Example #1
0
 /**
  * Creates a new users.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $form = new SignupForm();
     // collect user input data
     if (isset($_POST['SignupForm'])) {
         $form->attributes = $_POST['SignupForm'];
         //var_dump($_POST);
         //var_dump($form);
         // validate user input and redirect to previous page if valid
         if ($form->validate()) {
             // TODO: validate passwords
             $user = new User();
             //$user->attributes = $_POST['SignupForm'];
             $user->username = $_POST['SignupForm']['username'];
             $user->email = $_POST['SignupForm']['email'];
             $user->password_hash = md5($_POST['SignupForm']['password']);
             $user->display_name = $_POST['SignupForm']['display_name'];
             $user->admin = 0;
             $user->posts_count = 0;
             $user->activated = 0;
             $user->login_key = md5($user->password_hash + $user->email);
             $user->login_key_expires_at = date('Y-m-d H:i:s', strtotime('+1 day'));
             //if(isset($_POST['Users'])) {
             /*$users->attributes = array(
             			
             			
             		); ;*/
             //var_dump($users);
             //if($user->validate()) {
             if ($user->save(false)) {
                 $identity = new UserIdentity($user->username, $_POST['SignupForm']['password']);
                 /*$identity->authenticate();
                 		switch($identity->errorCode)
                 		{
                 			case UserIdentity::ERROR_NONE:
                 				$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
                 				Yii::app()->user->login($identity,$duration);
                 				break;
                 			case UserIdentity::ERROR_USERNAME_INVALID:
                 				$this->addError('username','Username is incorrect.');
                 				break;
                 			default: // UserIdentity::ERROR_PASSWORD_INVALID
                 				$this->addError('password','Password is incorrect.');
                 				break;
                 		}*/
                 Yii::app()->user->login($identity);
                 $this->redirect(array('view', 'id' => $user->id));
             } else {
                 var_dump($user->getErrors());
             }
             /*} else {
             			var_dump($user->getErrors());
             		}*/
             //}
             //var_dump($user);
             //$this->redirect(Yii::app()->user->returnUrl);
         }
     }
     // display the login form
     $this->render('create', array('form' => $form));
     /*$users=new User;
     		if(isset($_POST['Users']))
     		{
     			$users->attributes=$_POST['Users'];
     			if($users->save())
     				$this->redirect(array('show','id'=>$users->id));
     		}
     		$this->render('create',array('users'=>$users));*/
 }