MemberController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\admin\controller;
  3. use cmf\controller\HomeBaseController;
  4. use think\Db;
  5. class MemberController extends HomeBaseController{
  6. public function register(){
  7. return $this->fetch(":register");
  8. }
  9. public function doRegister(){
  10. $param = $this->request->param();
  11. $captcha = $this->request->param('captcha');
  12. if (empty($captcha)) {
  13. $this->error(lang('CAPTCHA_REQUIRED'));
  14. }
  15. //验证码
  16. if (!cmf_captcha_check($captcha)) {
  17. $this->error(lang('CAPTCHA_NOT_RIGHT'));
  18. }
  19. $name = $this->request->param("username");
  20. if (empty($name)) {
  21. $this->error(lang('USERNAME_OR_EMAIL_EMPTY'));
  22. }
  23. $pass = $this->request->param("password");
  24. if (empty($pass)) {
  25. $this->error(lang('PASSWORD_REQUIRED'));
  26. }
  27. if($param['password']!=$param['password1']){
  28. $this->error('密码不匹配');
  29. }
  30. $result = Db::name('user')->where('user_login',$name)->find();
  31. if (!empty($result)) {
  32. $this->error('用户名重复');
  33. }
  34. $data['user_pass'] = cmf_password($param['password']);
  35. $data['user_type'] = 1;
  36. $data['user_login'] = $param['username'];
  37. $data['create_time'] = time();
  38. $data['user_type'] = 3;
  39. $result = DB::name('user')->insertGetId($data);
  40. if ($result !== false) {
  41. Db::name('RoleUser')->insert(["role_id" => 2, "user_id" => $result]);
  42. $this->success("注册成功!", url("admin/public/login"));
  43. } else {
  44. $this->error("注册失败!");
  45. }
  46. }
  47. }
  48. ?>