123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- /**
- * @Created by PhpStorm
- * @author: Kirin
- * @day: 2024/11/20
- * @time: 11:21
- */
- namespace app\controller\admin;
- use app\common\AdminBaseController;
- use app\services\system\admin\SystemAdminServices;
- use app\validate\admin\SystemAdminValidate;
- use qiniu\services\CacheService;
- use qiniu\services\SystemConfigService;
- use qiniu\utils\ApiErrorCode;
- use qiniu\utils\Captcha;
- use think\facade\Cache;
- use think\facade\Config;
- class Login extends AdminBaseController
- {
- /**
- * 验证码
- * @return $this|\think\Response
- */
- public function captcha()
- {
- return app()->make(Captcha::class)->create();
- }
- /**
- * 获取验证码
- * @return mixed
- */
- public function getAjCaptcha()
- {
- [$account,] = $this->request->postMore([
- 'account',
- ], true);
- $key = 'login_captcha_' . $account;
- return $this->success(['is_captcha' => Cache::get($key) > 2]);
- }
- /**
- * 获取后台登录页轮播图以及LOGO
- * @return mixed
- */
- public function info()
- {
- $data = SystemConfigService::more(['site_name','admin_login_slide', 'site_logo_square', 'site_logo', 'login_logo'],true);
- return $this->success([
- 'slide' => sys_config('admin_login_slide') ?? [],
- 'logo_square' => $data['site_logo_square'] ?? '',//透明
- 'logo_rectangle' => $data['site_logo'] ?? '',//方形
- 'login_logo' => $data['login_logo'] ?? '',//登陆
- 'site_name' => $data['site_name'],
- 'upload_file_size_max' => config('upload.filesize'),//文件上传大小kb
- ]);
- }
- /**
- * @return mixed
- */
- public function ajcaptcha()
- {
- $captchaType = $this->request->get('captchaType');
- return $this->success(aj_captcha_create($captchaType));
- }
- /**
- * 一次验证
- * @return mixed
- */
- public function ajcheck()
- {
- [$token, $pointJson, $captchaType] = $this->request->postMore([
- ['token', ''],
- ['pointJson', ''],
- ['captchaType', ''],
- ], true);
- try {
- aj_captcha_check_one($captchaType, $token, $pointJson);
- return $this->success();
- } catch (\Throwable $e) {
- return $this->error();
- }
- }
- /**
- * 登陆
- * @return mixed
- */
- public function login(SystemAdminServices $service)
- {
- [$account, $password, $captchaType, $captchaVerification] = $this->request->postMore([
- 'account',
- 'pwd',
- ['captchaType', ''],
- ['captchaVerification', ''],
- ], true);
- $key = 'login_captcha_' . $account;
- if (Cache::has($key) && Cache::get($key) > 2) {
- if (!$captchaType || !$captchaVerification) {
- return $this->error('请拖动滑块验证');
- }
- //二次验证
- try {
- aj_captcha_check_two($captchaType, $captchaVerification);
- } catch (\Throwable $e) {
- return $this->error($e->getError());
- }
- }
- validate(SystemAdminValidate::class)->scene('get')->check(['account' => $account, 'pwd' => $password]);
- $res = $service->login($account, $password, 'admin');
- if ($res) {
- Cache::delete($key);
- }
- return $this->success($res);
- }
- public function logout()
- {
- $key = trim(ltrim($this->request->header(Config::get('cookie.token_name')), 'Bearer'));
- CacheService::redisHandler()->delete(md5($key));
- return $this->success();
- }
- }
|