123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <?php
- namespace Passport\Src;
- use Dever;
- use Passport\Src\Lib\Base;
- class Reg extends Base
- {
- /**
- * 获取图形验证码
- * @return mixed
- */
- public function getCode()
- {
- return $this->code();
- }
- /**
- * 获取手机随机验证码
- * @return mixed
- */
- public function getMCode()
- {
- $mobile = $this->checkMobileExists(1);
- $code = $this->mcode($mobile);
- //Dever::alert('验证码已发送至您的手机,请注意查收,十分钟之内有效');
- return '验证码已发送至您的手机,请注意查收,十分钟之内有效:' . $code;
- }
- /**
- * 检测图形验证码
- * @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)
- {
- $param['option_mobile'] = $this->checkMobile();
- if ($state && $state == 1) {
- } else {
- $this->checkMCode($param['option_mobile']);
- }
- $user = Dever::load('passport/user-one', $param);
- if ($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)
- {
- $param['option_email'] = $this->checkEmail();
- if ($state && $state == 1) {
- } else {
- $this->checkCode($param['option_email']);
- }
- $user = Dever::load('passport/user-one', $param);
- if ($user) {
- Dever::alert('该邮箱已经注册');
- }
- return $param['option_email'];
- }
- public function action()
- {
- $account = Dever::config('base', 'passport')->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');
- $cpassword = Dever::input('cpassword');
- if (!$param['add_username']) {
- Dever::alert('昵称不能为空');
- }
- if (!$param['add_password']) {
- Dever::alert('密码不能为空');
- }
- if ($cpassword != $param['add_password']) {
- Dever::alert('确认密码不正确');
- }
- $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', 'passport')->account;
- $baccount = ucfirst($account);
- $method = 'check' . $baccount . 'Exists';
- $param['option_' . $account] = $this->$method();
- $this->checkCode($param['option_' . $account]);
- $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) {
- return $this->save($id);
- $this->refer();
- } else {
- Dever::alert('修改失败');
- }
- }
- }
- public function url()
- {
- return Dever::url('reg?' . $this->createRefer(), 'main');
- }
- }
|