YII登录过程简单总结
2013-12-04 20:42
381 查看
用户的登录、过程是一个比较费劲的事,还在Yii提供了组建支持,熟练的使用该组件,在开发中可以大大的减少时间。
在siteController中有如下actionLogin()
if ($isGuest){
$model=new LoginForm;
if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
if(isset($_POST['LoginForm']))
{
$model->attributes=$_POST['LoginForm'];
if($model->validate() && $model->login()){
ob_start();
$this->redirect(array("fortune/aucno"));
}
}
$this->render('login',array('model'=>$model));其中$model->login()调用的是model/LoginForm.php中的login方法,继续追踪改login()方法:
public function login()
{
if($this->_identity===null)
{
$this->_identity=new UserIdentity($this->username,$this->password);
$this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($this->_identity,$duration);
return true;
}
else
return false;
}
$this->_identity=new UserIdentity($this->username,$this->password);执行的是链接数据据库验证用户名密码
Yii::app()->user->login($this->_identity,$duration);//这条语句执行的是设置session或者cookie操作,具体可以查看yii参考文档
该方法可重写,代码如下很容易看懂:
$user=new User();
$username=trim($this->username);
$user=$user->find("username='".$username."'");
if(isset($user)){
$password=$user->password;
$userid=$user->id;
$this->id=$userid;
}
if(!isset($this->username) or !isset($user) or $user=""){
$this->errorCode='323';//self::ERROR_USERNAME_INVALID;
}
else if($password!=md5($this->password)){
$this->errorCode=self::ERROR_PASSWORD_INVALID;
}
else{
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
在siteController中有如下actionLogin()
if ($isGuest){
$model=new LoginForm;
if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
if(isset($_POST['LoginForm']))
{
$model->attributes=$_POST['LoginForm'];
if($model->validate() && $model->login()){
ob_start();
$this->redirect(array("fortune/aucno"));
}
}
$this->render('login',array('model'=>$model));其中$model->login()调用的是model/LoginForm.php中的login方法,继续追踪改login()方法:
public function login()
{
if($this->_identity===null)
{
$this->_identity=new UserIdentity($this->username,$this->password);
$this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($this->_identity,$duration);
return true;
}
else
return false;
}
$this->_identity=new UserIdentity($this->username,$this->password);执行的是链接数据据库验证用户名密码
Yii::app()->user->login($this->_identity,$duration);//这条语句执行的是设置session或者cookie操作,具体可以查看yii参考文档
该方法可重写,代码如下很容易看懂:
$user=new User();
$username=trim($this->username);
$user=$user->find("username='".$username."'");
if(isset($user)){
$password=$user->password;
$userid=$user->id;
$this->id=$userid;
}
if(!isset($this->username) or !isset($user) or $user=""){
$this->errorCode='323';//self::ERROR_USERNAME_INVALID;
}
else if($password!=md5($this->password)){
$this->errorCode=self::ERROR_PASSWORD_INVALID;
}
else{
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
相关文章推荐
- 一个简单的基于MVC模式的登录验证过程
- python脚本--简单实现堡垒机登录的过程
- Linux USB 驱动开发(五)—— USB驱动程序开发过程简单总结
- Oracle9i中的存储过程简单总结
- Yii 登录表单模型的简单操作
- webx学习总结(一)——使用webx框架实现简单的登录功能
- 简单的sql登录和注册存储过程
- MySql存储过程简单总结
- Lucene2.3 sort过程简单总结(返回Hits对象)
- linux 读过程简单总结
- yii+mySQL使用过程中问题总结
- Swing超基础学习总结——1、简单的登录窗口样式
- IOS shareSDK三方登录(集成过程)+(可能问题)总结
- 【SSO】--实现单点登录研究过程总结
- 一个简单的demo模拟登录过程页面跳转逻辑和双击退出应用
- Linux USB 驱动开发(五)—— USB驱动程序开发过程简单总结
- 总结Dynamips下使用SDM及配置QOS的简单过程
- 在SSH实现简单的注册和登录的错误总结
- Linux USB 驱动开发(五)—— USB驱动程序开发过程简单总结
- 模拟教务系统登录过程中的一些总结---至今还未成功模拟登录