Custom Login Laravel [duplicate]

0

I'm trying to log in to Laravel 5.5, I can authenticate the user, but when I go to another page it loses the reference of the authenticated user and redirects to the login screen again.

My LoginController class:

    public function attempt(Request $request)
{

    $this->validate($request, [
        'cpf'   => 'required',
        'login' => 'required',
        'senha' => 'required',
    ]);

    $dados = $request->all();
    $pessoa = Pessoa::where('login', $dados['login'])
        ->where('cpf', $dados['cpf'])
        ->first();

    if ($pessoa == null) {

        return redirect()->back()
            ->with('fail', 'Credenciais não encontradas para o login e CPF informados')
            ->withInput();

    }

    if (md5($dados['senha']) != $pessoa->senha) {

        return redirect()->back()
            ->with('fail', 'Senha incorreta para o login ' . $dados['login'])
            ->withInput();

    }

    if (!$pessoa->ativo) {
        return redirect()->back()
            ->with('fail', 'O login não está ativo')
            ->withInput();          
    }

    \Auth::loginUsingId($pessoa->id);

    return redirect()->route('dashboard.index');



}

And my Model Person:

  
class Pessoa extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $primaryKey = 'id';


    protected $fillable = [
        'nome', 'cpf', 'senha', 'ativo', 'login',
    ];

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

Is there a method or attribute that I need to override to resolve this?

    
asked by anonymous 03.08.2018 / 15:03

2 answers

0
Auth::login($user, true);

Should resolve

    
10.08.2018 / 15:08
0

You have some methods that you can override, in your model that replaces the User default, you have to put a date mutator, similar to this:

getPasswordAttribute() { return $this->seu_campo_de_senha; }

I'll leave 2 my posts with this problem. The second was middleware error, so you can get it, which is more up to date. In it I override several methods that the laravel provider backs up by default.

And remember in the config / auth.php file to change the reference of the User model, for your model in question.

Older

Newest, more complete and more overwritten

Reference

    
03.08.2018 / 15:23