LoginController.php 1.4 KB

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