예제 #1
0
파일: passwd.php 프로젝트: lughong/shop
 public function sendcode($email = '')
 {
     $email = isset($_POST['email']) ? htmlspecialchars(trim($_POST['email'])) : '';
     if (!$email) {
         echo '{"result":"-1","msg":"邮箱不能为空"}';
         throw new Exception('exit');
     }
     $rs = Legal::isEmail($email);
     if ($rs) {
         self::_sendCode($email);
     } else {
         echo '{"result":"-2","msg":"邮箱格式不对"}';
         throw new Exception('exit');
     }
 }
예제 #2
0
파일: reg.php 프로젝트: lughong/test
 public function reging()
 {
     //用户名输入是否为空
     $username = isset($_POST['username']) ? htmlspecialchars(trim($_POST['username'])) : '';
     if (!$username) {
         $msg['error'] = '-3';
         $msg['msg'] = "用户名不能为空";
         echo json_encode($msg);
         throw new Exception('exit');
     }
     $username_len = strlen($username);
     if ($username_len < 3 || $username_len > 16) {
         $msg['error'] = '-3';
         $msg['msg'] = "请输入3-16个字符的用户名";
         echo json_encode($msg);
         throw new Exception('exit');
     }
     //检查该用户名是否已经注册了
     $username_rs = User::isUsernameExists($username);
     if ($username_rs) {
         $msg['error'] = '-3';
         $msg['msg'] = "注册失败,用户名已被注册";
         echo json_encode($msg);
         throw new Exception('exit');
     }
     //邮箱输入是否为空
     $email = isset($_POST['email']) ? htmlspecialchars(trim($_POST['email'])) : '';
     if (!$email) {
         $msg['error'] = '-3';
         $msg['msg'] = "邮箱不能为空";
         echo json_encode($msg);
         throw new Exception('exit');
     }
     //检查邮箱是否已被注册
     $email_rs = User::isEmailExists($email);
     if ($email_rs) {
         $msg['error'] = '-3';
         $msg['msg'] = "注册失败,邮箱已被注册";
         echo json_encode($msg);
         throw new Exception('exit');
     }
     //验证邮箱格式
     if (!Legal::isEmail($email)) {
         $msg['error'] = '-3';
         $msg['msg'] = "邮箱格式错误";
         echo json_encode($msg);
         throw new Exception('exit');
     }
     $password = isset($_POST['password']) ? htmlspecialchars(trim($_POST['password'])) : '';
     $repassword = isset($_POST['repassword']) ? htmlspecialchars(trim($_POST['repassword'])) : '';
     if (!$password) {
         $msg['error'] = '-3';
         $msg['msg'] = "密码填写不能为空";
         echo json_encode($msg);
         throw new Exception('exit');
     }
     $password_len = strlen($password);
     if ($password_len < 6 || $password_len > 18) {
         $msg['error'] = '-3';
         $msg['msg'] = "请输入6-18个字符的密码";
         echo json_encode($msg);
         throw new Exception('exit');
     }
     if ($password !== $repassword) {
         $msg['error'] = '-3';
         $msg['msg'] = "两次密码填写不一致";
         echo json_encode($msg);
         throw new Exception('exit');
     }
     //检查验证码
     $captcha = isset($_POST['captcha']) ? htmlspecialchars(trim($_POST['captcha'])) : '';
     if (!$captcha) {
         $msg['error'] = '-3';
         $msg['msg'] = "请输入验证码";
         echo json_encode($msg);
         throw new Exception('exit');
     }
     if ($_SESSION['captcha'] !== $captcha) {
         $msg['error'] = '-3';
         $msg['msg'] = "输入的验证码不正确";
         echo json_encode($msg);
         throw new Exception('exit');
     }
     $insert_rs = User::addUser($username, $password, $email);
     if ($insert_rs) {
         User::login($insert_rs);
         $url = url("myweb", "home::index");
         $msg['error'] = $insert_rs;
         $msg['msg'] = "注册成功";
         $msg['url'] = $url;
         echo json_encode($msg);
         throw new Exception('exit');
     } else {
         $msg['error'] = '-3';
         $msg['msg'] = "注册失败";
         echo json_encode($msg);
         throw new Exception('exit');
     }
 }