Login.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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. * 登陆
  46. * @return mixed
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\DbException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. */
  51. public function login()
  52. {
  53. [$account, $password, $imgcode] = $this->request->postMore([
  54. 'account', 'pwd', ['imgcode', '']
  55. ], true);
  56. if (!app()->make(Captcha::class)->check($imgcode)) {
  57. return app('json')->fail('验证码错误,请重新输入');
  58. }
  59. $this->validate(['account' => $account, 'pwd' => $password], \app\adminapi\validate\setting\SystemAdminValidata::class, 'get');
  60. return app('json')->success($this->services->login($account, $password, 'admin'));
  61. }
  62. /**
  63. * 获取后台登录页轮播图以及LOGO
  64. * @return mixed
  65. */
  66. public function info()
  67. {
  68. return app('json')->success($this->services->getLoginInfo());
  69. }
  70. }