2015-05-20 17:28:30 6202次浏览 2条回答 0 悬赏 10 金钱

控制器:
//登录

public function actionLogin()
{
    
    $this->layout="//layouts/column3";
    $model=new LoginForm;

    // if it is ajax validation request
    if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
    {
        echo CActiveForm::validate($model);
        Yii::app()->end();
    }

    // collect user input data
    if(isset($_POST['LoginForm']))
    {   

        $model->attributes=$_POST['LoginForm'];
        $model->password = md5($_POST['LoginForm']['password']);
        // validate user input and redirect to the previous page if valid
        if($model->validate() && $model->login()) {
            //var_dump(yii::app()->user->getState('userName'));exit();
            if((yii::app()->user->getState('isAdmin'))==true) {
                $this->redirect(array('meeting/index'));
            }
            $this->redirect(Yii::app()->user->returnUrl);
        }
    }
    // display the login form
    $this->render('login',array('model'=>$model));
}

//注册

public function actionCreate()
{

    $this->layout = '//layouts/column3';
    $model=new Person;

    
    // Uncomment the following line if AJAX validation is needed
    // $this->performAjaxValidation($model);

    if(isset($_POST['Person']))
    {
        $model->attributes=$_POST['Person'];
        $model->password = md5($_POST['Person']['password']);
        $model->repeat_password = md5($_POST['Person']['repeat_password']);
        $model->state = 1;
        if($model->save())
            $this->redirect(array('login'));
    }

    $this->render('register',array(
        'model'=>$model,
    ));
}

最佳答案

您需要登录后才可以回答。登录 | 立即注册
asd5230653
主管

asd5230653

注册时间:2015-05-15
最后登录:2015-07-22
在线时长:4小时32分
  • 粉丝5
  • 金钱395
  • 威望10
  • 积分535

热门问题