Login.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller;
  12. use crmeb\services\CacheService;
  13. use think\facade\App;
  14. use crmeb\utils\Captcha;
  15. use app\services\system\admin\SystemAdminServices;
  16. /**
  17. * 后台登陆
  18. * Class Login
  19. * @package app\adminapi\controller
  20. */
  21. class Login extends AuthController
  22. {
  23. /**
  24. * Login constructor.
  25. * @param App $app
  26. * @param SystemAdminServices $services
  27. */
  28. public function __construct(App $app, SystemAdminServices $services)
  29. {
  30. parent::__construct($app);
  31. $this->services = $services;
  32. }
  33. protected function initialize()
  34. {
  35. // TODO: Implement initialize() method.
  36. }
  37. /**
  38. * 验证码
  39. * @return $this|\think\Response
  40. */
  41. public function captcha()
  42. {
  43. return app()->make(Captcha::class)->create();
  44. }
  45. /**
  46. * @return mixed
  47. */
  48. public function ajcaptcha()
  49. {
  50. $captchaType = $this->request->get('captchaType');
  51. return app('json')->success(aj_captcha_create($captchaType));
  52. }
  53. /**
  54. * 一次验证
  55. * @return mixed
  56. */
  57. public function ajcheck()
  58. {
  59. [$token, $pointJson, $captchaType] = $this->request->postMore([
  60. ['token', ''],
  61. ['pointJson', ''],
  62. ['captchaType', ''],
  63. ], true);
  64. try {
  65. aj_captcha_check_one($captchaType, $token, $pointJson);
  66. return app('json')->success();
  67. } catch (\Throwable $e) {
  68. return app('json')->fail(400336);
  69. }
  70. }
  71. /**
  72. * 登陆
  73. * @return mixed
  74. * @throws \think\db\exception\DataNotFoundException
  75. * @throws \think\db\exception\DbException
  76. * @throws \think\db\exception\ModelNotFoundException
  77. */
  78. public function login()
  79. {
  80. [$account, $password, $key, $captchaVerification, $captchaType] = $this->request->postMore([
  81. 'account',
  82. 'pwd',
  83. ['key', ''],
  84. ['captchaVerification', ''],
  85. ['captchaType', '']
  86. ], true);
  87. if ($captchaVerification != '') {
  88. try {
  89. aj_captcha_check_two($captchaType, $captchaVerification);
  90. } catch (\Throwable $e) {
  91. return app('json')->fail(400336);
  92. }
  93. }
  94. $this->validate(['account' => $account, 'pwd' => $password], \app\adminapi\validate\setting\SystemAdminValidata::class, 'get');
  95. $result = $this->services->login($account, $password, 'admin', $key);
  96. if (!$result) {
  97. $num = CacheService::get('login_captcha',1);
  98. if ($num > 1) {
  99. return app('json')->fail(400140, ['login_captcha' => 1]);
  100. }
  101. CacheService::set('login_captcha', $num + 1, 60);
  102. return app('json')->fail(400140, ['login_captcha' => 0]);
  103. }
  104. CacheService::delete('login_captcha');
  105. return app('json')->success($result);
  106. }
  107. /**
  108. * 获取后台登录页轮播图以及LOGO
  109. * @return mixed
  110. */
  111. public function info()
  112. {
  113. return app('json')->success($this->services->getLoginInfo());
  114. }
  115. }