示例#1
0
 public function actionReg()
 {
     $email = trim(Yii::app()->request->getParam('email'));
     $nick = trim(Yii::app()->request->getParam('nickname'));
     $password = trim(Yii::app()->request->getParam('passwd'));
     $password2 = trim(Yii::app()->request->getParam('passwd2'));
     $refer = trim(Yii::app()->request->getParam('refer', '/'));
     if (!preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$/i', $email)) {
         $this->json_return(false, '请输入一个格式正确的Email地址');
     }
     if (!$password || $password != $password2) {
         $this->json_return(false, '2次输入的密码不一致');
     }
     if (!$nick) {
         $this->json_return(false, '请填写昵称');
     }
     if (mb_strlen($nick, 'UTF-8') > 9) {
         $this->json_return(false, '昵称长度请限制在9个字之内');
     }
     if (Player::model()->find('email=:email', array(':email' => $email))) {
         $this->json_return(false, '这个Email已经被注册了,您是否已经注册过了呢?');
     }
     if (Player::model()->find('nickname=:nick', array(':nick' => $nick))) {
         $this->json_return(false, '这个昵称已经被注册了,换一个吧');
     }
     $player = new Player();
     $player->email = $email;
     $player->nickname = $nick;
     $player->password = MyUserIdentity::hashpwd($password);
     $player->login_times = 0;
     $player->b_win = 0;
     $player->b_lose = 0;
     $player->w_win = 0;
     $player->w_lose = 0;
     $player->draw = 0;
     $player->reg_time = date('Y-m-d H:i:s');
     $player->reg_ip = MyController::getUserHostAddress();
     $player->last_login_time = date('Y-m-d H:i:s');
     $player->last_login_ip = MyController::getUserHostAddress();
     $player->score = Yii::app()->params['init_score'];
     if ($player->save()) {
         $identity = new MyUserIdentity($email, $password);
         if ($identity->authenticate()) {
             Yii::app()->user->login($identity, 3600);
             $this->json_return(true, '恭喜您注册成功!', $refer);
         }
     }
     $this->json_return(false, '注册失败啦,请与管理员联系。');
 }
示例#2
0
 public function actionProfile()
 {
     $this->needlogin();
     if (Yii::app()->request->getParam('submit')) {
         $email = trim(Yii::app()->request->getParam('email'));
         $nickname = trim(Yii::app()->request->getParam('nickname'));
         $password = trim(Yii::app()->request->getParam('password'));
         $repassword = trim(Yii::app()->request->getParam('repassword'));
         $intro = trim(Yii::app()->request->getParam('intro'));
         //一些验证
         if (!preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$/i', $email)) {
             $this->json_return(false, '请输入一个格式正确的Email地址');
         }
         if (mb_strlen($nickname, 'UTF-8') > 9) {
             $this->json_return(false, '昵称长度请限制在9个字之内');
         }
         if (!$nickname) {
             $this->json_return(false, '请填写昵称');
         }
         if ($email != $this->_userinfo()->email && Player::model()->find('email=:email', array(':email' => $email))) {
             $this->json_return(false, '这个Email已经被注册了');
         }
         if ($nickname != $this->_userinfo()->nickname && Player::model()->find('nickname=:nick', array(':nick' => $nickname))) {
             $this->json_return(false, '这个昵称已经被注册了,换一个吧');
         }
         if ($password && $password != $repassword) {
             $this->json_return(false, '2次输入的密码不一致');
         }
         $this->userinfo->email = $email;
         $this->userinfo->nickname = $nickname;
         if ($password) {
             $this->userinfo->password = MyUserIdentity::hashpwd($password);
         }
         $this->userinfo->intro = $intro;
         $this->userinfo->save();
         $this->json_return(true, '修改成功!');
     }
     $this->pageTitle = '我的资料-' . Yii::app()->params['title'];
     $this->currmenu = 'profile';
     $this->js = array('profile');
     $this->render('profile');
 }