程序判断逻辑贴出来看下!!
解决方案 »
- 已经搞了两天了,仍然没解决,无奈向大伙儿求救imagick扩展,谢谢了
- 高手进 sql注入失败!
- 错误代码:2003 can't connect to MySQL server on '*.*.*.*'(10061)
- 优化查询
- shmop_open()如何申请空间?
- 新手图书馆系统,问个问题
- 新手求助--URL传递的值怎么获取啊?
- php命令行调用,后台运行的问题???
- 哪里有PHP计数器(基于文本文件,并且同一访客的多次访问只被计数一次)
- 2个初学者问题,关于mysql_connect和mysql_pconnect()。
- zend studio 打不开
- wamp启动gzip压缩后 重启为什么一直显示黄色的
<?phpclass LoginController extends Controller{ /*
* 登陆模板*/
public function actionIndex(){ $login_model = new LoginForm();
if(isset($_POST['LoginForm'])){ $login_model->attributes = $_POST['LoginForm'] ; if($login_model->validate() && $login_model->login()){ $this->redirect(Yii::app()->homeUrl);
}
} $this->render('index',array('login_model'=>$login_model));
}
/*
* 验证码
* */
public function actions(){
return array(
'captcha'=>array(
'class'=>'CCaptchaAction',
'height'=>40,
'width'=>80,
'minLength'=>4,
'maxLength'=>4,
),
);
} /*
* 登出*/
public function actionLogout(){
Yii::app()->user->logout();
$this->redirect($this->createUrl('index/index'));
}}数据模型:
<?php/**
* LoginForm class.
* LoginForm is the data structure for keeping
* user login form data. It is used by the 'login' action of 'SiteController'.
*/
class LoginForm extends CFormModel
{
public $username;
public $password;
public $email;
public $vcode; private $_identity; /**
* Declares the validation rules.
* The rules state that username and password are required,
* and password needs to be authenticated.
*/
public function rules()
{
return array(
// username and password are required
array('password', 'required','message'=>'密码不能为空'),
array('email', 'required','message'=>'电邮不能为空'),
array('vcode', 'required','message'=>'验证码不能为空'),
//array('vcode','captcha','message'=>'请输入正确的验证码'),
// password needs to be authenticated
array('password', 'authenticate'), );
} /**
* Declares attribute labels.
*/
public function attributeLabels()
{
return array(
'email'=>'email:',
'password'=>'密 码:',
'vcode'=>'验证码:',
);
} /**
* Authenticates the password.
* This is the 'authenticate' validator as declared in rules().
*/
public function authenticate($attribute,$params)
{ if(!$this->hasErrors())
{ $this->_identity=new UserIdentity($this->email,$this->password);
if(!$this->_identity->authenticate())
$this->addError('password','电邮或密码不正确!');
}
} /**
* Logs in the user using the given username and password in the model.
* @return boolean whether login is successful
*/
public function login(){
if($this->_identity===null)
{ $this->_identity=new UserIdentity($this->email,$this->password);
$this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration = 0;
Yii::app()->user->login($this->_identity,$duration);
return true;
}
else
return false;
}
}