简体   繁体   English

Laravel / Sentry login_attribute不变

[英]Laravel / Sentry login_attribute not changing

I am trying to implement the ability for a user to login either with their email or a username. 我正在尝试实现用户使用其电子邮件或用户名登录的功能。 At present I have the email login working with the code below, as that is the default set in the app/config/packages/cartalyst/sentry/config.php page. 目前,我有使用以下代码的电子邮件登录名,因为这是app/config/packages/cartalyst/sentry/config.php页面中的默认设置。

The code I have currently is: 我目前拥有的代码是:

$email = Input::get('email');
$password = Input::get('password');
$remember = Input::get('remember_me');

$field = filter_var(Input::get('email'), FILTER_VALIDATE_EMAIL) ? 'email' : 'username';       
Config::set('Cartalyst/Sentry::users.login_attribute', $field);

if(Sentry::authenticate(array($field => $email, 'password' => $password), $remember == 'yes'))
    $destination = Redirect::intended('/');

However it keeps throwing the LoginRequiredException provided by Sentry. 但是,它始终抛出Sentry提供的LoginRequiredException。

However if I change the login_attribute in the config.php page to username then the login for that works fine but the email side of things stop. 但是,如果我将config.php页面中的login_attribute更改为username,则该用户的登录正常,但电子邮件方面停止了。

If anyone can shed some light as to why this would be failing? 如果有人能阐明为什么会失败? I've added a line to extract the current value of login_attribute and that works and changes as anticipated but regardless the exception is still thrown. 我添加了一行以提取login_attribute的当前值,该行可以按预期工作和更改,但是无论是否仍然抛出异常。

The config item is used to set the login attribute at run time, not when actually processing a log in. You can see that being done in the Sentry service provider . config项用于在运行时设置登录属性,而不是在实际处理登录时设置。您可以在Sentry服务提供商中看到这一点。 Changing the config item will not affect the actual login attribute name being used, which is a static property on Sentry's user model . 更改配置项不会影响实际使用的登录属性名称,这是Sentry用户模型上的静态属性

You should be able to replace the Config::set() command with something like SentryUser::setLoginAttributeName($field) (modified for your exact situation) and achieve the results you desire. 您应该能够用诸如SentryUser::setLoginAttributeName($field)类的东西替换Config::set()命令(针对您的实际情况进行修改),并获得所需的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM