Register.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Sports\Controller;
  3. use BaseController\Controller;
  4. use App\Sports\Controller\Validation;
  5. /**
  6. * Class Register
  7. * @package App\Sports\Controller
  8. * User: tank
  9. * Date: 2019/3/19
  10. */
  11. class Register extends Controller{
  12. /**
  13. * 新增账号
  14. */
  15. public function userAdd(){
  16. $data = $_REQUEST;
  17. try {
  18. if (empty($data['account'])) throw new \Exception(Render([], '4013', lang('Tips','Sports')->get('no_account')));
  19. if (empty($data['password'])) throw new \Exception(Render([], '4014', lang('Tips','Sports')->get('no_password')));
  20. if (empty($data['repassword'])) throw new \Exception(Render([], '4015', lang('Tips','Sports')->get('no_repassword')));
  21. if (empty($data['problemID'])) throw new \Exception(Render([], '4011', lang('Tips','Sports')->get('no_problem')));
  22. if (empty($data['answer'])) throw new \Exception(Render([], '4012', lang('Tips','Sports')->get('no_answer')));
  23. if (empty($data['wmpassword'])) throw new \Exception(Render([], '4016', lang('Tips','Sports')->get('no_wmpassword')));
  24. if ($data['agree'] < 1) throw new \Exception(Render([], '4018', lang('Tips','Sports')->get('no_agree')));
  25. if ($data['password'] != $data['repassword']) throw new \Exception(Render([], '4017', lang('Tips','Sports')->get('no_pwd_equally')));
  26. if (strcmp($data['password'],$data['wmpassword']) == 0) throw new \Exception(Render([], '4024', lang('Tips','Sports')->get('agreement_wmpassword_password')));
  27. if (Validation::isAccount($data['account']) != 1) throw new \Exception(Render([], '4020', lang('Tips','Sports')->get('illegal_account')));
  28. if (Validation::isAccount($data['password']) != 1) throw new \Exception(Render([], '4021', lang('Tips','Sports')->get('illegal_password')));
  29. if (Validation::isAccount($data['answer']) != 1) throw new \Exception(Render([], '4022', lang('Tips','Sports')->get('illegal_answer')));
  30. if (Validation::isAccount($data['wmpassword']) != 1) throw new \Exception(Render([], '4023', lang('Tips','Sports')->get('illegal_wmpassword')));
  31. $res = lm('Account', 'Sports')->where('username',$data['account'])->select('id')->first();
  32. if(!empty($res->id)) throw new \Exception(Render([], '4004', lang('Tips','Sports')->get('no_null_account')));
  33. $obj = [
  34. 'username'=>$data['account'],
  35. 'userpwd'=>$data['password'],
  36. 'qukuanpwd'=>$data['wmpassword'],
  37. 'pwdpoint_problemid'=>$data['problemID'],
  38. 'pwdpoint_answer'=>$data['answer']
  39. ];
  40. $inser = lm('Account', 'Sports')->insert($obj);
  41. if(empty($inser)) throw new \Exception(Render([], '4005', lang('Tips','Sports')->get('fail')));
  42. Render([], '200', lang('Tips','Sports')->get('success'));
  43. } catch (\Exception $e) {
  44. echo $e->getMessage();
  45. }
  46. }
  47. }