Example #1
0
 public function actionRegister()
 {
     //$this->layout = 'unlogin';
     $email = isset($_POST['email']) ? $_POST['email'] : null;
     $password = isset($_POST['password']) ? $_POST['password'] : null;
     $phone = isset($_POST['phone']) ? $_POST['phone'] : null;
     $msg = null;
     $isEmail = preg_match("/^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+\$/", $email);
     if ($isEmail && $password) {
         $user = new User();
         $token = $user->makeToken();
         if ($user->insertOneUser($email, $password, $phone, $token)) {
             $id = Yii::app()->db()->getLastInsertId();
             $this->_sendEmail($id, $email, $token);
             $this->redirect('/site/login');
         }
     }
     $this->render('register', array('msg' => $msg));
 }
Example #2
0
 public static function createAdmin($attributes)
 {
     $user = new User();
     $user->attributes = $attributes;
     $user->role = self::ROLE_ADMIN;
     $user->password = crypt($user->password ? $user->password : mt_rand());
     $user->token = $user->makeToken();
     if ($user->save()) {
         $user->_sendAdminActivateEmail();
         return true;
     }
     return $user->getErrors();
 }