LoginController.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * 登录
  4. * @author wesmiler
  5. */
  6. namespace app\api\controller;
  7. use app\index\service\Users;
  8. use app\index\validate\UsersValidate;
  9. class LoginController extends BaseController
  10. {
  11. /**
  12. * 账号注册
  13. * @throws \think\Exception
  14. * @throws \think\exception\PDOException
  15. */
  16. public function register(){
  17. $params = input();
  18. $validate = new UsersValidate();
  19. if (!$validate->scene('reg')->check($params)) {
  20. showJson(1002, $validate->getError());
  21. }
  22. if(!Users::saveData($params)){
  23. showJson(1002, 1011);
  24. }
  25. showJson(1001, 1012);
  26. }
  27. /**
  28. * 账号注册
  29. * @throws \think\Exception
  30. * @throws \think\exception\PDOException
  31. */
  32. public function login(){
  33. $params = input();
  34. $validate = new UsersValidate();
  35. if (!$validate->scene('login')->check($params)) {
  36. showJson(1002, $validate->getError());
  37. }
  38. $result = Users::login($params);
  39. if(!is_array($result)){
  40. showJson(1002, $result);
  41. }
  42. showJson(1001, 1013, $result);
  43. }
  44. }