Files
huangjingfen/pro_v3.5.1/app/controller/supplier/Login.php
panchengyong c1e74d8e68 chore(php): 统一 ScottPan 文件头与注释域名替换
- 按 docs/renew-code-comment.md 将 PHP 文件头改为带边框的 Author 注释\n- 注释中的 crmeb.com 替换为 uj345.cn(代码字符串中的外链未改)\n- 新增 docs/renew-code-comment.md 说明

Made-with: Cursor
2026-03-29 11:22:58 +08:00

179 lines
5.1 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | Author: ScottPan Team
// +----------------------------------------------------------------------
namespace app\controller\supplier;
use app\Request;
use crmeb\utils\Captcha;
use crmeb\services\CacheService;
use app\services\supplier\LoginServices;
use think\annotation\Inject;
use think\exception\ValidateException;
use app\validate\api\user\RegisterValidates;
use think\facade\Config;
use think\facade\Cache;
/**
* 登录
* Class AuthController
* @package app\api\controller
*/
class Login
{
/**
* @var LoginServices
*/
#[Inject]
protected LoginServices $services;
/**
* @param Request $request
* @return mixed
* @author 等风来
* @email 136327134@qq.com
* @date 2022/10/11
*/
public function getAjCaptcha(Request $request)
{
[$account,] = $request->postMore([
'account',
], true);
$key = 'supplier_login_captcha_' . $account;
return app('json')->success(['is_captcha' => Cache::get($key) > 2]);
}
/**
* @return mixed
*/
public function ajcaptcha(Request $request)
{
$captchaType = $request->get('captchaType');
return app('json')->success(aj_captcha_create($captchaType));
}
/**
* 一次验证
* @return mixed
*/
public function ajcheck(Request $request)
{
[$token, $pointJson, $captchaType] = $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);
}
}
/**
* 获取后台登录页轮播图以及LOGO
* @return mixed
*/
public function info()
{
return app('json')->success($this->services->getLoginInfo());
}
/**
* 验证码
* @return \app\controller\admin\Login|\think\Response
*/
public function captcha()
{
return app()->make(Captcha::class)->create();
}
/**
* H5账号登陆
* @param Request $request
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function login(Request $request)
{
[$account, $password, $captchaType, $captchaVerification] = $request->postMore([
'account',
'pwd',
['captchaType', ''],
['captchaVerification', '']
], true);
validate(\app\validate\supplier\SystemSupplierValidate::class)->scene('login')->check(['account' => $account, 'pwd' => $password]);
$key = 'supplier_login_captcha_' . $account;
if (Cache::has($key) && Cache::get($key) > 2) {
if (!$captchaType || !$captchaVerification) {
return app('json')->fail('请拖动滑块验证');
}
//二次验证
try {
aj_captcha_check_two($captchaType, $captchaVerification);
} catch (\Throwable $e) {
return app('json')->fail($e->getError());
}
}
$res = $this->services->login($account, $password, 'supplier');
if ($res) {
Cache::delete($key);
}
return app('json')->success($res);
}
/**
* 退出登录
* @param Request $request
* @return mixed
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function logout(Request $request)
{
$key = trim(ltrim($request->header(Config::get('cookie.token_name')), 'Bearer'));
CacheService::redisHandler()->delete(md5($key));
return app('json')->success();
}
/**
* 密码修改
* @param Request $request
* @return mixed
*/
public function reset(Request $request)
{
[$account, $captcha, $password] = $request->postMore([['account', ''], ['captcha', ''], ['password', '']], true);
try {
validate(RegisterValidates::class)->scene('register')->check(['account' => $account, 'captcha' => $captcha, 'password' => $password]);
} catch (ValidateException $e) {
return app('json')->fail($e->getError());
}
$verifyCode = CacheService::get('code_' . $account);
if (!$verifyCode)
return app('json')->fail('请先获取验证码');
$verifyCode = substr($verifyCode, 0, 6);
if ($verifyCode != $captcha) {
return app('json')->fail('验证码错误');
}
if (strlen(trim($password)) < 6 || strlen(trim($password)) > 16)
return app('json')->fail('密码必须是在6到16位之间');
if ($password == '123456') return app('json')->fail('密码太过简单,请输入较为复杂的密码');
$resetStatus = $this->services->reset($account, $password);
if ($resetStatus) return app('json')->success('修改成功');
return app('json')->fail('修改失败');
}
}