Mwi*_*Tim 3 php laravel laravel-4 cartalyst-sentry
我正在构建一个系统,当用户第一次使用Facebook登录时,他无法提供密码.所以我尝试使用Facebook的凭据登录他.
Sentry::authenticate($credentials, false);
Run Code Online (Sandbox Code Playgroud)
上面的命令总是要求输入密码.如何在不向用户提供密码的情况下登录用户?
Ant*_*iro 11
在Sentry中,您可以通过两种不同的方式登录:
1)在登录表单上输入密码时,告诉Sentry找到该用户并检查密码进行身份验证并同时登录他/她:
// Set login credentials
$credentials = array(
'email' => Input::get('email'),
'password' => Input::get('password'),
);
// Try to authenticate the user
$user = Sentry::authenticate($credentials, false);
Run Code Online (Sandbox Code Playgroud)
2)当用户通过其他方式(如OAuth)进行身份验证时,您只需要强制它在系统上登录:
// Find the user using the user id or e-mail
$user = Sentry::findUserById($userId);
// or
$user = Sentry::findUserByLogin($email);
// and
// Log the user in
Sentry::login($user, false);
Run Code Online (Sandbox Code Playgroud)
您选择了一个或另一个,您不必同时使用它们.
3)作为第三个例子,假设你有一个旧的用户数据库,你的密码使用MD5进行哈希处理:
// Find the user
$user = Sentry::findUserByLogin($email);
// Check the password
if ($user->password !== md5(Input::get('password'))
{
Redirect::back()->withMessage('Password is not correct.');
}
// And, if password is correct, force the login:
Sentry::login($user, false);
Run Code Online (Sandbox Code Playgroud)