[英]Laravel / Sentry login_attribute not changing
我正在嘗試實現用戶使用其電子郵件或用戶名登錄的功能。 目前,我有使用以下代碼的電子郵件登錄名,因為這是app/config/packages/cartalyst/sentry/config.php
頁面中的默認設置。
我目前擁有的代碼是:
$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('/');
但是,它始終拋出Sentry提供的LoginRequiredException。
但是,如果我將config.php
頁面中的login_attribute
更改為username,則該用戶的登錄正常,但電子郵件方面停止了。
如果有人能闡明為什么會失敗? 我添加了一行以提取login_attribute
的當前值,該行可以按預期工作和更改,但是無論是否仍然拋出異常。
config項用於在運行時設置登錄屬性,而不是在實際處理登錄時設置。您可以在Sentry服務提供商中看到這一點。 更改配置項不會影響實際使用的登錄屬性名稱,這是Sentry用戶模型上的靜態屬性 。
您應該能夠用諸如SentryUser::setLoginAttributeName($field)
類的東西替換Config::set()
命令(針對您的實際情況進行修改),並獲得所需的結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.