Laravel 5确认了如何检查用户 [英] How to check user is confirmed with Laravel 5
问题描述
我正在尝试使用开箱即用的Laravel身份验证.身份验证不是问题,但我想检查用户是否已确认他的电子邮件地址.
I'm trying to use the Laravel auth out of the box. The authentication is not the problem but I want to check if the user has confirmed his email address.
我如何让Laravel
检查表值confirmed
是否具有值1.
How I let have Laravel
check if the table value confirmed
has the value 1.
在config/auth.php中,我已经设置了'driver' => 'database'
,因此,如果我了解正确的文档,则可以进行手动身份验证,然后我可以检查用户是否已确认其帐户.
In config/auth.php I have set 'driver' => 'database'
so if I understand the docs right I can then do manual authentication and I guess I can then check if the user has confirmed his account.
Laravel在哪里对匹配的用户名和密码进行检查?
Where does Laravel perform the check for a matching username and password?
推荐答案
If you're using Laravel Auth out of the box, you want to go take a look at the AuthController that has been setup for you.
您将看到它使用了特征 AuthenticatesAndRegistersUsers 将行为添加到控制器.
You'll see that this uses a trait AuthenticatesAndRegistersUsers to add behavior to the controller.
在该特征内,您将找到 postLogin
.
Inside that trait you'll find the method postLogin
.
通过将自己的postLogin
添加到AuthController
,您将要覆盖此方法.您可以复制并粘贴入门方法.
You will want to override this method, by adding your own postLogin
to the AuthController
. You can copy and paste the method for starters.
现在来看一下有关身份验证的Laravel文档.向下滚动到有关使用条件对用户进行身份验证"的地方.
Now go take a look at the Laravel docs on authentication. Scroll down to where it talks about "Authenticating A User With Conditions."
if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1]))
{
// The user is active, not suspended, and exists.
}
如示例所示,在您的postLogin
方法中更改attempt()
代码以包括条件.在您的情况下,您可能希望传递'confirmed' => 1
条件而不是活动条件,具体取决于您在users表中调用的字段.
Change the attempt()
code in your postLogin
method to include the condition, as shown in the example. In your case you would probably want to pass in a condition of 'confirmed' => 1
instead of active, depending on what you call the field in your users table.
那应该带你走!
这篇关于Laravel 5确认了如何检查用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!