Laravel 5 - Auth :: attempt: Error when using another table

1

Good afternoon guys, I've been searching the Internet and unfortunately I could not solve my problem.

I need to authenticate users using the Laravel 5.2 framework however my method needs to be different, ie instead of using php artisan make: auth I need to do manual authentication of users, in the Auth :: attempt case.

My problem is that the function is returning FALSE. The credentials entered are correct, but I have not yet been able to.

Settings:

routes.php

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::get('login', 'LoginController@login');

App \ User.php

<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    protected $table = 'usuarios';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'nome', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password'
    ];

    public function setPasswordAttribute($tmp)
    {
        return $this->attributes['password'] = trim(\Hash::make($tmp));
    }
}

App \ Controllers \ LoginController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class LoginController extends Controller
{
    public function login()
    {
        if (\Auth::attempt(['email' => '[email protected]', 'password' => '123'])) {
            return 'TRUE';
        } else {
            return 'FALSE';
        }
    }
}
    
asked by anonymous 24.07.2016 / 23:08

1 answer

-1

I see that the request of the information has not been made, nor a guard for these purposes.

See the template below and see what you can do.

 public function postlogin(loginAlunoRequest $inf_valores) {
    // atribuindo valores digitados para uma validação
    $validacao = ['RA' => $inf_valores->get('RA'), 'password' => $inf_valores->get('password'),];

    if (Auth::guard('guardLoginAluno')->attempt($validacao)) {  // Validando as informações.
        $Situacao = auth()->guard('guardLoginAluno')->user()->Situacao; // Atribuindo o valor do campo situação para uma vareavel
        if ($Situacao == "ATIVO") { // validando se o aluno esta ativo
            return redirect('/aluno'); // direcionando o usuario para pagina solicitada
        } else { // condição caso o aluno esteje inativo
            return redirect('/loginaluno') // direcionando para pagina de login 
                            ->withErrors(['Inativo' => 'Aluno Inativo!']) // messagem de erros aluno inativo
                            ->withInput(); // levando as informações de digitada de volta para o form login
        }
    } else {
        return redirect('/loginaluno') // caso a senha ou ra esteja incorretos
                        ->withErrors(['ERRO-LOGIN' => 'RA ou Senha Inválidos!']) // messagem de dados invalidos
                        ->withInput(); // levando as informações de digitada de volta para o form login
    } 
    
21.12.2016 / 18:52