123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368 |
- <?php
- namespace Passport\Src;
- use Dever;
- use Passport\Lib\Base;
- # 所有手机发送短信操作,后续要独立成一个组件
- class Reg extends Base
- {
- /**
- * 获取图形验证码
- * @return mixed
- */
- public function getCode()
- {
- return $this->code();
- }
- /**
- * 获取手机随机验证码
- * @return mixed
- */
- public function getMCode()
- {
- $mobile = $this->checkMobileExists(1, -1);
- $msg = $this->getMcode_action($mobile);
- return $msg;
- }
- public 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 getMCodeReg()
- {
- $mobile = $this->checkMobileExists(1);
- $msg = $this->getMcode_action($mobile);
- 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
- */
- public function checkMobileExist()
- {
- $param['option_mobile'] = $this->checkMobile();
- $user = Dever::db('passport/user')->one($param);
- if (!$user) {
- Dever::alert('该手机号未注册');
- }
- return 'ok';
- }
- /**
- * 检测图形验证码
- * @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');
- if (!$code) {
- Dever::alert('请输入验证码');
- }
- $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, $table = 'passport/user')
- {
- $param['option_mobile'] = $this->checkMobile();
- if ($state && $state == 1) {
- } else {
- $this->checkMCode($param['option_mobile']);
- }
- if ($login !== -1) {
- $user = Dever::db($table)->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('请填写正确的邮箱');
- }
- $check = Dever::config('base', 'project')->passportCheckEmail;
- if ($check && !strstr($email, $check[0])) {
- Dever::alert($check[1]);
- }
- return $email;
- }
- /**
- * 验证邮箱是否注册
- * @return mixed
- */
- public function checkEmailExists($state = false, $login = false, $table = 'passport/user')
- {
- $param['option_email'] = $this->checkEmail();
- if ($state && $state == 1) {
- } else {
- $this->checkCode($param['option_email']);
- }
- if ($login != -1) {
- $user = Dever::db($table)->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;
- $code = Dever::config('base', 'project')->nocode ? Dever::config('base', 'project')->nocode : state;
- $baccount = ucfirst($account);
- $method = 'check' . $baccount . 'Exists';
- $param[$account] = $this->$method($code);
- if ($param[$account]) {
- $param['username'] = Dever::input('username');
- $param['password'] = Dever::input('password');
- $param['sex'] = Dever::input('sex');
- $param['wechat'] = Dever::input('wechat');
- $param['profession'] = Dever::input('profession');
- $param['truename'] = Dever::input('truename');
- $param['area_id'] = Dever::input('area_id');
- $param['area'] = Dever::input('area');
- $param['source_type'] = Dever::input('source_type', 'h5');//即将废弃
- $param['system_source'] = Dever::input('system_source', 1);
-
- $cpassword = Dever::input('cpassword');
- if (!$param['username']) {
- Dever::alert('昵称不能为空');
- }
- if (!$param['password']) {
- Dever::alert('密码不能为空');
- }
- if ($cpassword != $param['password']) {
- Dever::alert('确认密码不正确');
- }
- if ($param['sex']) {
- $config_sex = Dever::config('base', 'project')->sex;
- if (isset($config_sex[$param['sex']])) {
- $param['sex'] = $config_sex[$param['sex']];
- } else {
- if ($sex == '男') {
- $param['sex'] = 1;
- } elseif ($sex == '女') {
- $param['sex'] = 2;
- } elseif ($sex == '未知') {
- $param['sex'] = 3;
- }
- }
- }
- if ($account == 'mobile' && $param['username'] == $param[$account]) {
- $param['username'] = Dever::hide($param['username']);
- }
- $id = Dever::db('passport/user')->insert($param);
- if ($id > 0) {
- $this->save($id);
- $this->refer();
- } else {
- Dever::alert('注册失败');
- }
- }
- }
- public function forget_email()
- {
- #发送邮件
- $email = Dever::input('email');
- if ($email) {
- if (!preg_match(Dever::rule('email'), $email)) {
- Dever::alert('请输入正确的邮箱');
- }
- $method = 'checkEmailExists';
- $this->$method(1, 1);
- $code = $this->code(false, false);
- $email = base64_encode($email);
- //return Dever::load('passport/lib/email')->forget($email, $code);
- Dever::daemon('lib/email.forget?email=' . $email . '&code=' . $code, 'passport');
- $refer = $this->refer(true);
- return $refer . '||邮件已经发送成功!请到您的邮箱里查看。';
- } else {
- Dever::alert('请输入邮箱');
- }
- }
- public function forget()
- {
- $signature = Dever::input('signature');
- if (!$signature) {
- Dever::alert('您的验证信息已失效,请重新发送验证邮件');
- }
- $signature = Dever::decode($signature);
- $temp = explode('|||', $signature);
- $code = $temp[1];
- $state = $this->code($code);
- if (!$state) {
- Dever::alert('您的验证信息已失效,请重新发送验证邮件');
- }
- $account = Dever::config('base', 'project')->account;
- $code = Dever::config('base', 'project')->nocode ? Dever::config('base', 'project')->nocode : state;
- $baccount = ucfirst($account);
- $method = 'check' . $baccount . 'Exists';
- $param['option_' . $account] = $this->$method($code, true);
- $user = Dever::load('passport/user-one', $param);
- if (!$user) {
- Dever::alert('该账号还未注册,请先注册');
- } else {
- $param['set_password'] = Dever::input('password');
- $cpassword = Dever::input('cpassword');
- if (sha1($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) {
- $refer = $this->refer(true);
- return $refer . '||您已经成功修改密码';
- } else {
- Dever::alert('修改失败');
- }
- }
- }
- public function url()
- {
- return Dever::url('reg?' . $this->createRefer(), 'main');
- }
- }
|