Php laravel和sentry包中的身份验证失败
我正在尝试在我的新应用程序中使用Sentry 2来处理所有用户和组。Php laravel和sentry包中的身份验证失败,php,laravel,laravel-4,cartalyst-sentry,Php,Laravel,Laravel 4,Cartalyst Sentry,我正在尝试在我的新应用程序中使用Sentry 2来处理所有用户和组。 在使用sentry对用户进行身份验证后,当尝试重定向到另一个页面时,身份验证丢失 在测试代码中,检查函数Sentry::check()的输出为true public function Login(){ $credentials = array( 'username' => 'Mouad',
在使用sentry对用户进行身份验证后,当尝试重定向到另一个页面时,身份验证丢失
在测试代码中,检查函数
Sentry::check()
的输出为true
public function Login(){
$credentials = array(
'username' => 'Mouad',
'password' => 'test',
);
// Authenticate the user
$user = Sentry::authenticate($credentials, false);
var_dump(Sentry::check());
}
会话输出
array (size=3)
'_token' => string 'slAqB8IYYrSPPSC1k1A2i8aTpkpVklPad3fiqoFA' (length=40)
'flash' =>
array (size=2)
'old' =>
array (size=0)
empty
'new' =>
array (size=0)
empty
'cartalyst_sentry' =>
array (size=2)
0 => null
1 => string '$2y$08$nWq4rHlacrNykXhQykipJ.0c8mr6VK4o364UvatPtJZ1kM1W8KH7K' (length=60)
当我尝试在身份验证后重定向页面时,“cartalyst\u sentry”会话条目已更改,检查函数sentry::check()
的输出为false
public function Login(){
$credentials = array(
'username' => 'Mouad',
'password' => 'test',
);
// Authenticate the user
$user = Sentry::authenticate($credentials, false);
return Redirect::to('admin');
}
public function Admin(){
$data = Session::all();
var_dump($data);
var_dump(Sentry::check());
}
路由配置很简单
Route::get('/', 'MainController@Index');
Route::get('create', 'MainController@Create');
Route::get('login', 'MainController@Login');
Route::get('admin', 'MainController@Admin');
Route::get('logout', 'MainController@Logout');
会话配置是默认的,并且存储文件夹是可写的您可以尝试以下方法: 登录控制器:
public function store() {
if (Input::get('remember') == "") {
$remember = false;
} else {
$remember = true;
}
$user = [
'email' => Input::get('email'),
'password' => Input::get('password')
];
$login = User::login($user, $remember);
}
用户模型($login
是对模态用户的调用):
public static function login(array $credentials, $remember) {
try {
$user = Sentry::findUserByCredentials($credentials);
// PROCESS TO THE LOGIN AND REDIRECT TO THE DASHBOARD PAGE
$user->is_logged_in = 1;
$user->save();
Sentry::login($user, $remember);
return \Redirect::route('admin.dashboard.index');
} catch (\Cartalyst\Sentry\Users\LoginRequiredException $e) {
return \Redirect::back()->withErrors(['auth_message' => 'U moet alle velden in vullen']);
} catch (\Cartalyst\Sentry\Users\PasswordRequiredException $e) {
return \Redirect::back()->withErrors(['auth_message' => 'U moet het wachtwoordveld invullen']);
} catch (\Cartalyst\Sentry\Users\WrongPasswordException $e) {
return \Redirect::back()->withErrors(['auth_message' => 'Het opgegeven email/wachtwoord is onjuist']);
} catch (\Cartalyst\Sentry\Users\UserNotFoundException $e) {
return \Redirect::back()->withErrors(['auth_message' => 'Het opgegeven email/wachtwoord is onjuist']);
} catch (\Cartalyst\Sentry\Users\UserNotActivatedException $e) {
return \Redirect::back()->withErrors(['auth_message' => 'Dit account is nog niet geactiveerd']);
} catch (\Cartalyst\Sentry\Throttling\UserSuspendedException $e) {
return \Redirect::back()->withErrors(['auth_message' => 'Dit account heeft een timeout']);
} catch (\Cartakyst\Sentry\Throttling\UserBannedExveption $e) {
return \Redirect::back()->withErrors(['auth_message' => 'Dit account is van onze site verbannen']);
}
}