gpt4 book ai didi

php - Laravel 电子邮件确认登录

转载 作者:行者123 更新时间:2023-11-29 20:04:22 26 4
gpt4 key购买 nike

好吧,我正在尝试做的事情是,如果用户未通过电子邮件确认其帐户,则不要登录。我的登录代码如下所示:

    public function postLogin()
{
$credentials = [
'confirmed' => 0,
'email' => Input::get('email'),
'password' => Input::get('password')
];
$user = Sentinel::authenticate($credentials, false); // Login the user (if possible)

if ($user and $user->banned) {
Sentinel::logout();
$user = null;
}

if ($user) {
return $this->afterLoginActions();
} else {
$this->alertFlash(trans('app.access_denied'));
return Redirect::to('auth/login');
}
}

但我仍然可以登录,没有任何错误。有什么帮助吗?谢谢大家!

已编辑:正在工作,但现在如果我的详细信息不正确,我不会收到即时消息。代码:

    public function postLogin()
{
$credentials = [
'email' => Input::get('email'),
'password' => Input::get('password'),
'confirmed' => 1
];

$user = Sentinel::authenticate($credentials, false); // Login the user (if possible)
if ($user and $user->banned) {
Sentinel::logout();
$this->alertFlash(trans('app.banned'));
$user = null;
}
if ($user->confirmed==1) {
return $this->afterLoginActions();
}
else if ($user->confirmed==0) {
Sentinel::logout();
$this->alertFlash(trans('app.not_active'));
return Redirect::to('auth/login');
} else {
$this->alertFlash(trans('app.access_denied'));
return Redirect::to('auth/login');
}
}

最佳答案

如果该用户通过了电子邮件确认,您的表中是否有一列存储信息?如果您有的话,这就是我使用典型的 Laravel postLogin 方法所做的事情。

public function postLogin(Request $request)
{
$credentialas = (your credential here);
// only check credentials
if ($this->guard()->once($credentials)) {
$currentStatus = $this->guard()->user()->status;
if (intval($currentStatus) === (NOT_CONFIRMED)) {
$this->guard()->logout();
return $this->sendSuspendedResponse($request);
} else {
$this->guard()->login($this->guard()->user());
return $this->sendLoginResponse($request);
}
}
}

关于php - Laravel 电子邮件确认登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40407018/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com