Login.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 think\facade\App;
  13. use crmeb\utils\Captcha;
  14. use app\services\system\admin\SystemAdminServices;
  15. /**
  16. * 后台登陆
  17. * Class Login
  18. * @package app\adminapi\controller
  19. */
  20. class Login extends AuthController
  21. {
  22. /**
  23. * Login constructor.
  24. * @param App $app
  25. * @param SystemAdminServices $services
  26. */
  27. public function __construct(App $app, SystemAdminServices $services)
  28. {
  29. parent::__construct($app);
  30. $this->services = $services;
  31. }
  32. protected function initialize()
  33. {
  34. // TODO: Implement initialize() method.
  35. }
  36. /**
  37. * 验证码
  38. * @return $this|\think\Response
  39. */
  40. public function captcha()
  41. {
  42. return app()->make(Captcha::class)->create();
  43. }
  44. /**
  45. * @return mixed
  46. */
  47. public function ajcaptcha()
  48. {
  49. $captchaType = $this->request->get('captchaType');
  50. return app('json')->success(aj_captcha_create($captchaType));
  51. }
  52. /**
  53. * 一次验证
  54. * @return mixed
  55. */
  56. public function ajcheck()
  57. {
  58. [$token, $pointJson, $captchaType] = $this->request->postMore([
  59. ['token', ''],
  60. ['pointJson', ''],
  61. ['captchaType', ''],
  62. ], true);
  63. try {
  64. aj_captcha_check_one($captchaType, $token, $pointJson);
  65. return app('json')->success();
  66. } catch (\Throwable $e) {
  67. return app('json')->fail(400336);
  68. }
  69. }
  70. /**
  71. * 登陆
  72. * @return mixed
  73. * @throws \think\db\exception\DataNotFoundException
  74. * @throws \think\db\exception\DbException
  75. * @throws \think\db\exception\ModelNotFoundException
  76. */
  77. public function login()
  78. {
  79. [$account, $password, $imgcode, $key, $captchaVerification, $captchaType] = $this->request->postMore([
  80. 'account',
  81. 'pwd',
  82. ['imgcode', ''],
  83. ['key', ''],
  84. ['captchaVerification', ''],
  85. ['captchaType', '']
  86. ], true);
  87. if (!app()->make(Captcha::class)->check($imgcode)) {
  88. return app('json')->fail(400336);
  89. }
  90. try {
  91. aj_captcha_check_two($captchaType, $captchaVerification);
  92. } catch (\Throwable $e) {
  93. return app('json')->fail(400336);
  94. }
  95. $this->validate(['account' => $account, 'pwd' => $password], \app\adminapi\validate\setting\SystemAdminValidata::class, 'get');
  96. return app('json')->success($this->services->login($account, $password, 'admin', $key));
  97. }
  98. /**
  99. * 获取后台登录页轮播图以及LOGO
  100. * @return mixed
  101. */
  102. public function info()
  103. {
  104. return app('json')->success($this->services->getLoginInfo());
  105. }
  106. }