feat: 新增登录接口

This commit is contained in:
2024-12-31 18:05:36 +08:00
parent 22f63b9a91
commit 50ba08f2b3
8 changed files with 219 additions and 2 deletions

View File

@@ -0,0 +1,47 @@
<?php
declare (strict_types = 1);
namespace app\admin\controller\v1;
use app\admin\model\v1\UserModel;
use app\admin\validate\v1\LoginValidate;
use think\facade\Cache;
class Login
{
/**
* 登录验证接口
*/
public function index()
{
// 获取参数
$post = request()->post([
'username',
'password',
]);
// 验证参数
$validate = new LoginValidate();
if (!$validate->check($post)) {
return error($validate->getError());
}
// 验证用户
$user = UserModel::usernameOrMobile($post['username'])->find();
if (!$user) {
return error('用户不存在!');
}
// 验证密码
if ($user['password'] != password_with_salt($post['password'], $user['salt'])) {
return error('密码错误!');
}
// 验证用户状态
if ($user['status'] == -1) {
return error('用户已禁用,请联系管理员!');
}
dump(session("ss"));
return $user;
}
}