标签:yii 登陆
用户登陆的时候需要判定邮箱是否验证过!
在useridentify中
class UserIdentity extends CUserIdentity
{
/**
* Authenticates a user.
* The example implementation makes sure if the username and password
* are both ‘demo‘.
* In practical applications, this should be changed to authenticate
* against some persistent user identity storage (e.g. database).
* @return boolean whether authentication succeeds.
*/
public $_id;
const ERROR_STATUS_INVALID=11;
public function authenticate()
{
$user=SandUser::model()->findByAttributes(array(‘username‘=>$this->username));
if($user==null){
$this->errorCode=self::ERROR_USERNAME_INVALID;
}elseif($user->status == 0){
$this->errorCode=self::ERROR_STATUS_INVALID;
}elseif(!userSalt::vertifySalt($this->username, $this->password)){
$this->errorCode=self::ERROR_PASSWORD_INVALID;
}else {
$this->_id=$user->userid;
$this->errorCode=self::ERROR_NONE;
}
return $this->errorCode;
}
public function getId()
{
return $this->_id;
}
}定义一个新的变量,盛放status的状态,这里设置为11(为true的其他值也可)。
这个方法authenticate是在模型loginform中使用的,进入到loginform中:
public function authenticate($attribute,$params)
{
if(!$this->hasErrors())
{
$this->_identity=new UserIdentity($this->username,$this->password);
if($this->_identity->authenticate()== 1 && $this->_identity->authenticate() == 2){
$this->addError(‘password‘,‘错误的用户名或密码‘);}
elseif($this->_identity->authenticate() == 11){
Yii::app()->user->setFlash("error", "注册成功,邮件已经发送到邮箱,请进行邮箱验证" );
}
}
}改变了原有的判定方法。
在登陆的视图文件里面:
<?php if(Yii::app()->user->hasFlash(‘error‘)){ ?>
<div class="flash-error">
<?php echo Yii::app()->user->getFlash(‘error‘); ?>
</div>
<?php } ?>这样当用户的邮箱状态没有验证的话,会提示进行邮箱验证。
标签:yii 登陆
原文地址:http://dreamingo.blog.51cto.com/6111676/1546589