[英]Laravel Auth/Guard not signing in using valid credentials
這是我先前關於表單請求的問題的后續操作,現已解決。 不幸的是,該應用程序將無法使用正確的憑據登錄。 我以前遇到過這個問題,解決方案與會話有關—但是,這里的情況並非如此,因為會話設置正確且是關鍵。
提供正確的憑據時, $auth->attempt()
返回false。
架構:
Schema::create('users', function (Blueprint $t) {
$t->increments('id')->unsigned();
$t->timestamps();
$t->rememberToken();
$t->boolean('system')->default(false);
$t->boolean('activated')->default(true);
$t->string('username')->unique();
$t->string('email')->unique()->nullable();
$t->string('passphrase', 64);
$t->string('first_name', 20)->nullable();
$t->string('last_name', 20)->nullable();
$t->text('meta')->nullable();
});
種子:
$adminUser = App\User::create([
'system' => true,
'username' => 'SysAdmin',
'passphrase' => bcrypt('the-password'),
]);
$adminUser->attachRole($administratorRole);
用戶模型:
namespace App;
use Bican\Roles\Contracts\HasRoleAndPermission as HasRoleAndPermissionContract;
use Bican\Roles\Traits\HasRoleAndPermission;
use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Database\Eloquent\Model;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract, HasRoleAndPermissionContract
{
use Authenticatable, CanResetPassword, HasRoleAndPermission;
protected $table = 'users';
protected $fillable = ['system', 'username', 'email', 'passphrase', 'first_name', 'last_name'];
protected $hidden = ['passphrase', 'remember_token'];
}
AuthController :: attemptSignIn()方法:
用戶可以使用其用戶名或電子郵件地址登錄。
public function attemptSignIn(SignInRequest $request = null, $type = 'regular')
{
switch ($type) {
case 'regular':
$identifierFieldName = 'account_identifier';
$field = filter_var($this->request->input($identifierFieldName), FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
$this->request->merge([$field => $this->request->input($identifierFieldName)]);
$specifics = $this->request->only($field, 'passphrase');
if ($this->auth->attempt($specifics)) {
return redirect($this->redirectPath);
} else {
return redirect($this->signInPath)
->with('authError', "The credentials you've provided are incorrect.")
->with('authErrorType', 'danger')
->withInput($this->request->only($identifierFieldName));
}
break;
case 'oota':
break;
}
}
$specifics
設置的信息是正確的,並且與數據庫中的記錄匹配。
也許我缺少一些簡單的東西?
如前所述這里 , password
是硬編碼到Laravel的認證協議。 這樣,我只需要更改發送給attempt
的數組:
$specifics['password'] = $specifics['passphrase'];
unset($specifics['passphrase']);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.