feat: 新增登录接口
This commit is contained in:
47
app/admin/controller/v1/Login.php
Normal file
47
app/admin/controller/v1/Login.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user