假设我有此代码进行Sentry
身份验证:
try {
$credentials = array(
'email' => Input::get('email'),
'password' => Input::get('password'),
);
$user = Sentry::authenticate($credentials, false);
}
catch (Cartalyst\Sentry\Users\LoginRequiredException $e) {
echo 'Login field is required.';
}
catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) {
echo 'Password field is required.';
}
catch (Cartalyst\Sentry\Users\WrongPasswordException $e) {
echo 'Wrong password, try again.';
}
catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
echo 'User was not found.';
}
catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) {
echo 'User is not activated.';
}
我想尝试删除所有try
和catch
(我有我的理由,它是多级身份验证,我正在尝试缩短我的代码)。所以我尝试了这个来检查身份验证是否失败:
$credentials = array(
'email' => Input::get('email'),
'password' => Input::get('password'),
);
$user = Sentry::authenticate($credentials, false);
if (is_null($user)) {
/* error logic here */
}
else{
/* login success! */
}
将is_null
不起作用,代码将无法继续。有什么建议或解决方案吗?
编辑
使用 Chrome 的控制台,var_dump($user)
没有显示任何内容。