Login.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\controller\common;
  3. use app\extra\basic\Base;
  4. use LinFly\Annotation\Route\Controller;
  5. use LinFly\Annotation\Route\Route;
  6. use support\Request;
  7. use support\Response;
  8. use Tinywan\Captcha\Captcha;
  9. #[Controller(prefix: "/api/login")]
  10. class Login extends Base
  11. {
  12. /**
  13. * 登陆
  14. * @param Request $request
  15. * @return Response
  16. */
  17. #[Route(path: "user",methods: "post")]
  18. public function setLogin(Request $request): Response
  19. {
  20. try {
  21. $param = $this->_valid([
  22. "username.require" => trans("empty.user"),
  23. "password.require" => trans("empty.passwd"),
  24. "code.require" => trans("empty.code"),
  25. "key.require" => trans("empty.data"),
  26. ],"post");
  27. if (!is_array($param)) return error($param);
  28. if (Captcha::check($param['code'],$param['key']) === false) return errorTrans("error.captcha");
  29. } catch (\Throwable $throwable) {
  30. return error($throwable->getMessage());
  31. }
  32. }
  33. /**
  34. * 手机号码登陆
  35. * @param Request $request
  36. * @return Response
  37. */
  38. #[Route(path: "mobile",methods: "post")]
  39. public function setLogin2Mobile(Request $request): Response
  40. {
  41. try {
  42. $param = $this->_valid([
  43. "mobile.require" => trans("empty.mobile"),
  44. "code.require" => trans("empty.code"),
  45. ],"post");
  46. if (!is_array($param)) return error($param);
  47. } catch (\Throwable $throwable) {
  48. return error($throwable->getMessage());
  49. }
  50. }
  51. }