Reg.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. namespace Passport\Src;
  3. use Dever;
  4. use Passport\Src\Lib\Base;
  5. class Reg extends Base
  6. {
  7. /**
  8. * 获取图形验证码
  9. * @return mixed
  10. */
  11. public function getCode()
  12. {
  13. return $this->code();
  14. }
  15. /**
  16. * 获取手机随机验证码
  17. * @return mixed
  18. */
  19. public function getMCode()
  20. {
  21. $mobile = $this->checkMobileExists(1);
  22. $code = $this->mcode($mobile);
  23. //Dever::alert('验证码已发送至您的手机,请注意查收,十分钟之内有效');
  24. return '验证码已发送至您的手机,请注意查收,十分钟之内有效:' . $code;
  25. }
  26. /**
  27. * 检测图形验证码
  28. * @return mixed
  29. */
  30. private function checkCode()
  31. {
  32. $code = Dever::input('code');
  33. $code = $this->code($code);
  34. if (!$code) {
  35. Dever::alert('请您填写正确的验证码');
  36. }
  37. }
  38. /**
  39. * 检测手机验证码
  40. * @return mixed
  41. */
  42. private function checkMCode($mobile)
  43. {
  44. $code = Dever::input('mcode');
  45. $code = $this->mcode($mobile, $code);
  46. if (!$code) {
  47. Dever::alert('请您填写正确的验证码');
  48. }
  49. }
  50. /**
  51. * 验证手机号
  52. * @return mixed
  53. */
  54. private function checkMobile()
  55. {
  56. $rule = Dever::rule('mobile');
  57. $mobile = Dever::input('mobile');
  58. if (!$mobile) {
  59. Dever::alert('手机号不能为空');
  60. }
  61. if (!preg_match($rule, $mobile)) {
  62. Dever::alert('请填写正确的手机号');
  63. }
  64. return $mobile;
  65. }
  66. /**
  67. * 验证手机号是否注册
  68. * @return mixed
  69. */
  70. public function checkMobileExists($state = false)
  71. {
  72. $param['option_mobile'] = $this->checkMobile();
  73. if ($state && $state == 1) {
  74. } else {
  75. $this->checkMCode($param['option_mobile']);
  76. }
  77. $user = Dever::load('passport/user-one', $param);
  78. if ($user) {
  79. Dever::alert('该手机号已经注册');
  80. }
  81. return $param['option_mobile'];
  82. }
  83. /**
  84. * 验证邮箱
  85. * @return mixed
  86. */
  87. private function checkEmail()
  88. {
  89. $rule = Dever::rule('email');
  90. $email = Dever::input('email');
  91. if (!$email) {
  92. Dever::alert('邮箱不能为空');
  93. }
  94. if (!preg_match($rule, $email)) {
  95. Dever::alert('请填写正确的邮箱');
  96. }
  97. return $email;
  98. }
  99. /**
  100. * 验证邮箱是否注册
  101. * @return mixed
  102. */
  103. public function checkEmailExists($state = false)
  104. {
  105. $param['option_email'] = $this->checkEmail();
  106. if ($state && $state == 1) {
  107. } else {
  108. $this->checkCode($param['option_email']);
  109. }
  110. $user = Dever::load('passport/user-one', $param);
  111. if ($user) {
  112. Dever::alert('该邮箱已经注册');
  113. }
  114. return $param['option_email'];
  115. }
  116. public function action()
  117. {
  118. $account = Dever::config('base', 'passport')->account;
  119. $baccount = ucfirst($account);
  120. $method = 'check' . $baccount . 'Exists';
  121. $param['option_' . $account] = $this->$method();
  122. if ($param['option_' . $account]) {
  123. $param['add_' . $account] = $param['option_' . $account];
  124. $param['add_username'] = Dever::input('username');
  125. $param['add_password'] = Dever::input('password');
  126. $cpassword = Dever::input('cpassword');
  127. if (!$param['add_username']) {
  128. Dever::alert('昵称不能为空');
  129. }
  130. if (!$param['add_password']) {
  131. Dever::alert('密码不能为空');
  132. }
  133. if ($cpassword != $param['add_password']) {
  134. Dever::alert('确认密码不正确');
  135. }
  136. $id = Dever::load('passport/user-insert', $param);
  137. if ($id > 0) {
  138. $this->save($id);
  139. $this->refer();
  140. } else {
  141. Dever::alert('注册失败');
  142. }
  143. }
  144. }
  145. public function forget()
  146. {
  147. $account = Dever::config('base', 'passport')->account;
  148. $baccount = ucfirst($account);
  149. $method = 'check' . $baccount . 'Exists';
  150. $param['option_' . $account] = $this->$method();
  151. $this->checkCode($param['option_' . $account]);
  152. $user = Dever::load('passport/user-one', $param);
  153. if (!$user) {
  154. Dever::alert('该账号还未注册,请先注册');
  155. } else {
  156. $param['set_password'] = Dever::input('password');
  157. $cpassword = Dever::input('cpassword');
  158. if (md5($param['set_password']) == $user['password']) {
  159. Dever::alert('您的新密码和旧密码相同');
  160. }
  161. if (!$param['set_password']) {
  162. Dever::alert('新密码不能为空');
  163. }
  164. if ($param['set_password'] != $cpassword) {
  165. Dever::alert('确认密码不正确');
  166. }
  167. $id = $param['where_id'] = $user['id'];
  168. Dever::load('passport/user-update', $param);
  169. if ($id > 0) {
  170. return $this->save($id);
  171. $this->refer();
  172. } else {
  173. Dever::alert('修改失败');
  174. }
  175. }
  176. }
  177. public function url()
  178. {
  179. return Dever::url('reg?' . $this->createRefer(), 'main');
  180. }
  181. }