Esempio n. 1
0
 /**
  *Displays the register page
  */
 public function actionRegister()
 {
     $model = new RegisterForm();
     // if it is ajax validation request
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'register-form') {
         Yii::app()->end();
     }
     if (isset($_POST['RegisterForm'])) {
         $user = new User();
         $user->attributes = $_POST['RegisterForm'];
         // validate user input and redirect to the previous page if valid
         // Yii::app()->user  means  MyshowWebUser
         if ($user->register()) {
             $this->redirect(Yii::app()->user->returnUrl);
         }
         $model->addError('email', 'email已经被注册过了,请重新注册');
     }
     $this->pageTitle = '注册';
     $this->breadcrumbs = array($this->pageTitle);
     // display the login form
     $this->render('register', array('model' => $model));
 }
Esempio n. 2
0
 /**
  * Registration page
  *
  **/
 public function actionRegister()
 {
     $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array('{{app_name}}' => Cii::getConfig('name', Yii::app()->name), '{{label}}' => Yii::t('ciims.controllers.Site', 'Sign Up'))));
     $this->layout = '//layouts/main';
     $model = new RegisterForm();
     $user = new Users();
     $error = '';
     if (isset($_POST) && !empty($_POST)) {
         $model->attributes = $_POST['RegisterForm'];
         if ($model->validate()) {
             if (!function_exists('password_hash')) {
                 require_once YiiBase::getPathOfAlias('ext.bcrypt.bcrypt') . '.php';
             }
             // Bcrypt the initial password instead of just using the basic hashing mechanism
             $hash = Users::model()->encryptHash(Cii::get($_POST['RegisterForm'], 'email'), Cii::get($_POST['RegisterForm'], 'password'), Yii::app()->params['encryptionKey']);
             $cost = Cii::getBcryptCost();
             $password = password_hash($hash, PASSWORD_BCRYPT, array('cost' => $cost));
             $user->attributes = array('email' => Cii::get($_POST['RegisterForm'], 'email'), 'password' => $password, 'firstName' => NULL, 'lastName' => NULL, 'displayName' => Cii::get($_POST['RegisterForm'], 'displayName'), 'user_role' => 1, 'status' => Users::INACTIVE);
             try {
                 if ($user->save()) {
                     $hash = mb_strimwidth(hash("sha256", md5(time() . md5(hash("sha512", time())))), 0, 16);
                     $meta = new UserMetadata();
                     $meta->user_id = $user->id;
                     $meta->key = 'activationKey';
                     $meta->value = $hash;
                     $meta->save();
                     // Send the registration email
                     $this->sendEmail($user, Yii::t('ciims.email', 'Activate Your Account'), '//email/register', array('user' => $user, 'hash' => $hash), true, true);
                     $this->redirect($this->createUrl('/register-success'));
                     return;
                 }
             } catch (CDbException $e) {
                 $model->addError(null, Yii::t('ciims.controllers.Site', 'The email address has already been associated to an account. Do you want to login instead?'));
             }
         }
     }
     $this->render('register', array('model' => $model, 'error' => $error, 'user' => $user));
 }