Exemplo n.º 1
0
 public function actionForget()
 {
     if (isset($_POST['phone']) & isset($_POST['psw']) & isset($_POST['code'])) {
         $cri = new CDbCriteria();
         $cri->condition = 'phone=:phone';
         $cri->params = array(':phone' => $_POST['phone']);
         $cri->order = 'id DESC';
         //排序条件
         $verify = Verify::model()->find($cri);
         if ($verify && $verify->code == $_POST['code']) {
             date_default_timezone_set('Asia/Shanghai');
             $recode = strtotime($verify->vtime);
             $now = time();
             //s数
             $min = ($now - $recode) / 60;
             if ($min <= 10) {
                 //验证成功
                 $query = new EntityFieldQuery();
                 $query->entityCondition('entity_type', 'user')->propertyCondition('name', $_POST['phone'], '=');
                 $result = $query->execute();
                 if (!isset($result['user'])) {
                     //该用户不存在
                     $basic = new basic();
                     $basic->error_code = 1;
                     $basic->error_msg = "用户不存在";
                     $jsonObj = CJSON::encode($basic);
                     echo $jsonObj;
                     die(0);
                 } else {
                     $uids = array_keys($result['user']);
                     $user = user_load($uids[0]);
                     $user->pass = sha1(sha1($_POST['psw']));
                     if (user_save($user)) {
                         $basic = new basic();
                         $basic->error_code = 0;
                         $basic->error_msg = "保存成功";
                         $jsonObj = CJSON::encode($basic);
                         echo $jsonObj;
                     } else {
                         $basic = new basic();
                         $basic->error_code = 2;
                         $basic->error_msg = "保存失败";
                         $jsonObj = CJSON::encode($basic);
                         echo $jsonObj;
                     }
                 }
             } else {
                 $basic = new basic();
                 $basic->error_code = 2;
                 $basic->error_msg = "验证码失效";
                 $jsonObj = CJSON::encode($basic);
                 echo $jsonObj;
             }
         } else {
             $basic = new basic();
             $basic->error_code = 3;
             $basic->error_msg = "验证码错误";
             $jsonObj = CJSON::encode($basic);
             echo $jsonObj;
         }
     }
 }