0
I’m trying to do a custom login on Laravel 5.5, I can even authenticate the user, but when I direct to another page it loses the authenticated user reference and redirects to the login screen again.
My class Logincontroller:
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 any method or attribute I need to overwrite to resolve this?
Overwriting getAuthPassword did not resolve. Yes, config/auth.php is targeting the Pessoa model. So much so that when I give the loginByUser it is authenticating (if I give an Auth::User just after the loginbyuser line it is returning the user instance), but when I try to get the authenticated user on the next page, it returns nothing.
– Ademilson Santana da Silva
Make sure he’s opening the session. I had an affair that was using Annotations, and it wasn’t web middleware (which is responsible for Session), I had to add in my route notes, the middleware manually.
– Matheus Picioli