Login.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 crmeb\basic\BaseController;
  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. * 登陆
  47. * @return mixed
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\DbException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. */
  52. public function login()
  53. {
  54. [$account, $password, $imgcode] = $this->request->postMore([
  55. 'account', 'pwd', ['imgcode', '']
  56. ], true);
  57. if (!app()->make(Captcha::class)->check($imgcode)) {
  58. return app('json')->fail('验证码错误,请重新输入');
  59. }
  60. $this->validate(['account' => $account, 'pwd' => $password], \app\adminapi\validate\setting\SystemAdminValidata::class, 'get');
  61. return app('json')->success($this->services->login($account, $password, 'admin'));
  62. }
  63. /**
  64. * 获取后台登录页轮播图以及LOGO
  65. * @return mixed
  66. */
  67. public function info()
  68. {
  69. return app('json')->success($this->services->getLoginInfo());
  70. }
  71. }