예제 #1
0
 function get()
 {
     $phone = $this->post["phone"];
     if (validate("phone", $phone)) {
         $result = $this->load("guest")->findPhone($phone);
         if ($result) {
             //send sms
             $sms = create_sms_code(6);
             $this->session["sms"] = $sms;
             $send_result = send_sms_code($phone, "验证码" . $sms);
             // ok == 1
             if ($send_result == 1) {
                 $this->session['sms'] = $sms;
                 $this->session['phone'] = $phone;
                 return json_encode(array('error_code' => 0));
             } else {
                 return json_encode(array('error_code' => 4));
             }
         } else {
             return json_encode(array("error_code" => 2));
         }
     } else {
         return json_encode(array("error_code" => 3));
     }
 }
예제 #2
0
 function get()
 {
     $session_sms = isset($this->session['sms']) ? $this->session['sms'] : 0;
     if (!empty($session_sms)) {
         $sms = $this->post["sms"];
         if ($this->session['sms'] == $sms) {
             $phone = $this->session['phone'];
             $new_pass = randomPass(6);
             $s_pass = secret($new_pass);
             $ret = $this->load("guest")->updatePassByPhone($phone, $s_pass);
             if ($ret) {
                 $result = send_sms_code($phone, "新密码:" . $new_pass . ",请妥善保存");
                 return json_encode(array("error_code" => 0));
             } else {
                 //update fail
                 return json_encode(array("error_code" => 13));
             }
         } else {
             return json_encode(array("error_code" => 7));
         }
     } else {
         return json_encode(array("error_code" => 6));
     }
 }
예제 #3
0
 /**
  * 找回密码
  * @param way     找回方式
  * @param account 打印店账号
  * @param phone   手机号
  * @param email   邮箱
  */
 function findPwd()
 {
     $account = I('account', false, C('REGEX_ACCOUNT'));
     if (!$account) {
         $this->error('账号无效!');
     }
     switch (I('way')) {
         case 'phone':
             $phone = I('post.phone', false, C('REGEX_PHONE'));
             if (!$phone) {
                 $this->error('手机号无效!');
             }
             $printer_phone = M('Printer')->getFieldByAccount($account, 'phone');
             if (!empty($printer_phone)) {
                 if ($phone != $printer_phone) {
                     $this->error('账号与手机号不匹配!');
                 }
             } else {
                 $this->error('账号未注册或未绑定手机!');
             }
             $result = send_sms_code($phone, 'findPwd');
             //发送短信
             if ($result == true) {
                 session('find_pwd_account', $account);
                 session('find_pwd_phone', $phone);
                 $this->success('发送成功');
             } elseif ($result === 0) {
                 $this->error('发送次数过多');
             } else {
                 $this->error('发送失败');
             }
             break;
         case 'email':
             $email = I('post.email', false, C('REGEX_EMAIL'));
             if (!$email) {
                 $this->error('邮箱地址无效!');
             }
             $printer = M('Printer')->Field('id,email,name')->getByAccount($account);
             if (!empty($printer['email'])) {
                 if ($email != $printer['email']) {
                     $this->error('账号与邮箱不匹配!');
                 }
             } else {
                 $this->error('账号未注册或未绑定邮箱!');
             }
             $data['use_id'] = $printer['id'];
             $data['type'] = 2;
             //密码找回类型为2
             $Code = M('code');
             $Code->where($data)->delete();
             $data['code'] = random(32);
             $data['content'] = $account;
             $cid = $Code->add($data);
             if ($cid) {
                 $url = U('Printer/checkEmailCode', 'id=' . $cid . '&code=' . $data['code'], '', true);
                 if (send_mail($printer, L('MAIL_FINDPWD', array('link' => $url)), C('MAIL_VERIFY'))) {
                     $this->success('验证邮件已发送到' . $email . '请及时到邮箱查收');
                 } else {
                     $this->error('验证邮件发送失败!');
                 }
             } else {
                 $this->error('信息生成失败!');
             }
             break;
         default:
             $this->error('类型未知!');
     }
 }
예제 #4
0
 /**
  * 找回密码
  * @param way    找回方式
  * @param number 学号
  * @param phone  手机号
  * @param email  邮箱
  */
 public function findPwd()
 {
     $number = I('number', false, C('REGEX_NUMBER'));
     if (!$number) {
         $this->error('学号无效!');
     }
     switch (I('way')) {
         case 'phone':
             $phone = I('post.phone', false, C('REGEX_PHONE'));
             if (!$phone) {
                 $this->error('手机号无效!');
             }
             $user = M('User')->Field('id,phone')->getByStudentNumber($number);
             if (!empty($user['phone'])) {
                 import('Common.Encrypt', COMMON_PATH, '.php');
                 decrypt_phone($user['phone'], $number, $user['id']);
                 if ($phone != $user['phone']) {
                     $this->error('学号与手机号不匹配!');
                 }
             } else {
                 $this->error('学号未注册或未绑定手机!');
             }
             $result = send_sms_code($phone, 'findPwd');
             //发送短信
             if (true == $result) {
                 session('find_pwd_number', $number);
                 session('find_pwd_phone', $phone);
                 $this->success('发送成功');
             } elseif (0 === $result) {
                 $this->error('发送次数过多');
             } else {
                 $this->error('发送失败');
             }
             break;
         case 'email':
             $email = I('post.email', false, C('REGEX_EMAIL'));
             if (!$email) {
                 $this->error('邮箱地址无效!');
             }
             $user = M('User')->Field('name,id,email')->getByStudentNumber($number);
             if (!empty($user['email'])) {
                 import('Common.Encrypt', COMMON_PATH, '.php');
                 decrypt_email($user['email']);
                 if ($email != $user['email']) {
                     $this->error('学号与邮箱不匹配!');
                 }
             } else {
                 $this->error('学号未登录过或未绑定邮箱!');
             }
             $data['use_id'] = $user['id'];
             $data['type'] = 2;
             //密码找回类型为2
             $Code = M('code');
             $Code->where($data)->delete();
             $data['code'] = random(32);
             $data['content'] = $number;
             $cid = $Code->add($data);
             if ($cid) {
                 $url = U('User/checkEmailCode', 'id=' . $cid . '&code=' . $data['code'], '', true);
                 if (send_mail($user, L('MAIL_FINDPWD', array('link' => $url)), C('MAIL_VERIFY'))) {
                     $this->success('验证邮件已发送到' . $email . '请及时到邮箱查收!注意垃圾箱哦o(^▽^)o', '/', 5);
                 } else {
                     $this->error('验证邮件发送失败!');
                 }
             } else {
                 $this->error('信息生成失败!');
             }
             break;
         default:
             $this->error('类型未知!');
     }
 }