code(); } /** * 获取手机随机验证码:未登录 * @return mixed */ public function getMCode() { $mobile = $this->checkMobileExists(1); $msg = $this->getMcode_action($mobile); return $msg; } private function getMcode_action($mobile) { $code = $this->mcode($mobile); $msg = '验证码已发送至您的手机,请注意查收,十分钟之内有效'; $debug = Dever::config('base', 'project')->mobileCode['debug']; if ($debug) { $msg .= ':' . $code; } return $msg; } /** * 获取手机随机验证码:已经登录状态 * @return mixed */ public function getMCodeLogin() { $mobile = $this->checkMobileExists(1, true); $type = Dever::input('type', 'code'); if ($type == 'code') { $msg = $this->getMcode_action($mobile); } else { $content = Dever::input('content'); $msg = $this->send($mobile, $content); } return $msg; } /** * 检测图形验证码 * @return mixed */ private function checkCode() { $code = Dever::input('code'); $code = $this->code($code); if (!$code) { Dever::alert('验证码输入错误'); } } /** * 检测手机验证码 * @return mixed */ private function checkMCode($mobile) { $code = Dever::input('mcode'); $code = $this->mcode($mobile, $code); if (!$code) { Dever::alert('验证码输入错误'); } } /** * 验证手机号 * @return mixed */ private function checkMobile() { $rule = Dever::rule('mobile'); $mobile = Dever::input('mobile'); if (!$mobile) { Dever::alert('手机号不能为空'); } if (!preg_match($rule, $mobile)) { Dever::alert('请填写正确的手机号'); } return $mobile; } /** * 验证手机号是否注册 * @return mixed */ public function checkMobileExists($state = false, $login = false) { $param['option_mobile'] = $this->checkMobile(); if ($state && $state == 1) { } else { $this->checkMCode($param['option_mobile']); } $user = Dever::load('passport/user-one', $param); if ($login == false && $user) { Dever::alert('该手机号已经注册'); } elseif ($login == true && !$user) { Dever::alert('该手机号未注册'); } return $param['option_mobile']; } /** * 验证邮箱 * @return mixed */ private function checkEmail() { $rule = Dever::rule('email'); $email = Dever::input('email'); if (!$email) { Dever::alert('邮箱不能为空'); } if (!preg_match($rule, $email)) { Dever::alert('请填写正确的邮箱'); } return $email; } /** * 验证邮箱是否注册 * @return mixed */ public function checkEmailExists($state = false, $login = false) { $param['option_email'] = $this->checkEmail(); if ($state && $state == 1) { } else { $this->checkCode($param['option_email']); } $user = Dever::load('passport/user-one', $param); if ($login == false && $user) { Dever::alert('该邮箱已经注册'); } elseif ($login == true && !$user) { Dever::alert('该邮箱未注册'); } return $param['option_email']; } public function action() { $account = Dever::config('base', 'project')->account; $baccount = ucfirst($account); $method = 'check' . $baccount . 'Exists'; $param['option_' . $account] = $this->$method(); if ($param['option_' . $account]) { $param['add_' . $account] = $param['option_' . $account]; $param['add_username'] = Dever::input('username'); $param['add_password'] = Dever::input('password'); $param['add_sex'] = Dever::input('sex'); $cpassword = Dever::input('cpassword'); if (!$param['add_username']) { Dever::alert('昵称不能为空'); } if (!$param['add_password']) { Dever::alert('密码不能为空'); } if ($cpassword != $param['add_password']) { Dever::alert('确认密码不正确'); } if ($param['add_sex']) { $config_sex = Dever::config('base', 'project')->sex; if (isset($config_sex[$param['add_sex']])) { $param['add_sex'] = $config_sex[$param['add_sex']]; } else { if ($sex == '男') { $param['add_sex'] = 1; } elseif ($sex == '女') { $param['add_sex'] = 2; } elseif ($sex == '未知') { $param['add_sex'] = 3; } } } if ($param['add_username'] == $param['add_' . $account]) { $param['add_username'] = substr_replace($param['add_username'],'****',3,4); } $id = Dever::load('passport/user-insert', $param); if ($id > 0) { $this->save($id); $this->refer(); } else { Dever::alert('注册失败'); } } } public function forget() { $account = Dever::config('base', 'project')->account; $baccount = ucfirst($account); $method = 'check' . $baccount . 'Exists'; $param['option_' . $account] = $this->$method(0, true); $user = Dever::load('passport/user-one', $param); if (!$user) { Dever::alert('该账号还未注册,请先注册'); } else { $param['set_password'] = Dever::input('password'); $cpassword = Dever::input('cpassword'); if (md5($param['set_password']) == $user['password']) { Dever::alert('您的新密码和旧密码相同'); } if (!$param['set_password']) { Dever::alert('新密码不能为空'); } if ($param['set_password'] != $cpassword) { Dever::alert('确认密码不正确'); } $id = $param['where_id'] = $user['id']; Dever::load('passport/user-update', $param); if ($id > 0) { $this->refer(); } else { Dever::alert('修改失败'); } } } public function url() { return Dever::url('reg?' . $this->createRefer(), 'main'); } }