我有一个用户,需要通过一个动态口令验证他的帐户。为了进行身份验证,他填写了他的OTP,然后它就会验证手机号码。通过身份验证后,我想强制他登录。即,这样他就不需要手动登录了。所以,对于这个表单,我基本上有:
if($model->validate())
{
// Force Login
$this->redirect(array('/site/index'));
}仅使用他的一个凭据(即他的手机号码),我需要强制他登录。我该怎么做呢?
发布于 2013-02-08 18:03:30
有关该过程的说明,请参阅CWebUser文档
身份验证用户提供使用用户提供的information.
returnUrl.创建authentication.
CWebUser::login让用户登录,然后将用户浏览器重定向到IUserIdentity您应该已经有了一个实现IUserIdentity的标识类。通常这是一个从CUserIdentity派生的类,它在构造时接受用户名和密码。这里有很大的自由度:您可以决定不从CUserIdentity派生,而使用您自己的自定义身份类来以任何您希望的方式进行身份验证,或者您可以从CUserIdentity派生并覆盖authenticate方法来使用动态口令进行身份验证。
然后,该过程将与上面完全相同:
$identity = new MyIdentity(...); // you decide what params it takes
if ($identity->authenticate()) {
$user = Yii::app()->user;
$user->login($identity);
$this->redirect($user->returnUrl);
}https://stackoverflow.com/questions/14769234
复制相似问题