131 lines
3.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\adminapi\controller;
use crmeb\services\CacheService;
use think\facade\App;
use crmeb\utils\Captcha;
use app\services\system\admin\SystemAdminServices;
/**
* 后台登陆
* Class Login
* @package app\adminapi\controller
*/
class Login extends AuthController
{
/**
* Login constructor.
* @param App $app
* @param SystemAdminServices $services
*/
public function __construct(App $app, SystemAdminServices $services)
{
parent::__construct($app);// 调用父类构造函数
$this->services = $services;// 实例化系统管理员服务类
}
protected function initialize()
{
// TODO: Implement initialize() method.
}
/**
* 验证码
* @return $this|\think\Response
*/
public function captcha()
{
return app()->make(Captcha::class)->create();// 生成验证码
}
/**
* @return mixed
*/
public function ajcaptcha()
{
$captchaType = $this->request->get('captchaType');// 验证码类型
return app('json')->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 app('json')->success();
} catch (\Throwable $e) {
return app('json')->fail(400336);
}
}
/**
* 登陆
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function login()
{
[$account, $password, $key, $captchaVerification, $captchaType] = $this->request->postMore([
'account',
'pwd',
['key', ''],
['captchaVerification', ''],
['captchaType', '']
], true);
if ($captchaVerification != '') {
try {
aj_captcha_check_two($captchaType, $captchaVerification);
} catch (\Throwable $e) {
return app('json')->fail(400336);
}
}
if (strlen(trim($password)) < 6 || strlen(trim($password)) > 32) {
return app('json')->fail(400762);
}
$this->validate(['account' => $account, 'pwd' => $password], \app\adminapi\validate\setting\SystemAdminValidata::class, 'get');
$result = $this->services->login($account, $password, 'admin', $key);
if (!$result) {
$num = CacheService::get('login_captcha', 1);
if ($num > 1) {
return app('json')->fail(400140, ['login_captcha' => 1]);
}
CacheService::set('login_captcha', $num + 1, 60);
return app('json')->fail(400140, ['login_captcha' => 0]);
}
CacheService::delete('login_captcha');
return app('json')->success($result);
}
/**
* 获取后台登录页轮播图以及LOGO
* @return mixed
*/
public function info()
{
return app('json')->success($this->services->getLoginInfo());
}
}