feat: 所有页面添加ICP备案号 浙ICP备2026052792号
Some checks failed
Deploy Backend / deploy (push) Has been cancelled
Some checks failed
Deploy Backend / deploy (push) Has been cancelled
This commit is contained in:
@@ -283,13 +283,19 @@ pub async fn mock_login(
|
||||
|
||||
let user_id = match query.user_id {
|
||||
Some(id) => {
|
||||
// 验证用户存在
|
||||
match sqlx::query_as::<_, (i32,)>("SELECT id FROM users WHERE id = $1" )
|
||||
// 验证用户存在,同时检查是否管理员
|
||||
match sqlx::query_as::<_, (i32, bool)>("SELECT id, is_admin FROM users WHERE id = $1" )
|
||||
.bind(id)
|
||||
.fetch_optional(pool.get_ref())
|
||||
.await
|
||||
{
|
||||
Ok(Some((uid,))) => uid,
|
||||
Ok(Some((uid, is_admin))) => {
|
||||
if is_admin {
|
||||
return HttpResponse::Forbidden()
|
||||
.json(ErrorResponse::<()>::error("模拟登录不能用于管理员账户"));
|
||||
}
|
||||
uid
|
||||
},
|
||||
Ok(None) => {
|
||||
return HttpResponse::BadRequest()
|
||||
.json(ErrorResponse::<()>::error("用户不存在"));
|
||||
|
||||
Reference in New Issue
Block a user