mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-08 14:56:03 +00:00
fix: 登录失败时无提示
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import quart
|
||||
import sqlalchemy
|
||||
import argon2
|
||||
|
||||
from .. import group
|
||||
from .....persistence.entities import user
|
||||
@@ -32,7 +33,10 @@ class UserRouterGroup(group.RouterGroup):
|
||||
async def _() -> str:
|
||||
json_data = await quart.request.json
|
||||
|
||||
token = await self.ap.user_service.authenticate(json_data['user'], json_data['password'])
|
||||
try:
|
||||
token = await self.ap.user_service.authenticate(json_data['user'], json_data['password'])
|
||||
except argon2.exceptions.VerifyMismatchError:
|
||||
return self.fail(1, '用户名或密码错误')
|
||||
|
||||
return self.success(data={
|
||||
'token': token
|
||||
|
||||
@@ -51,8 +51,7 @@ class UserService:
|
||||
|
||||
ph = argon2.PasswordHasher()
|
||||
|
||||
if not ph.verify(user_obj.password, password):
|
||||
raise ValueError('密码错误')
|
||||
ph.verify(user_obj.password, password)
|
||||
|
||||
return await self.generate_jwt_token(user_email)
|
||||
|
||||
|
||||
@@ -47,17 +47,21 @@ const login = () => {
|
||||
user: user.value,
|
||||
password: password.value
|
||||
}).then(res => {
|
||||
if (res.data.data.token) {
|
||||
if (res.data.code == 0) {
|
||||
emit('success', '登录成功')
|
||||
localStorage.setItem('user-token', res.data.data.token)
|
||||
setTimeout(() => {
|
||||
location.reload()
|
||||
}, 1000)
|
||||
} else {
|
||||
emit('error', '登录失败')
|
||||
emit('error', res.data.msg)
|
||||
}
|
||||
}).catch(err => {
|
||||
emit('error', err.response.data.message)
|
||||
if (err.response.data.msg) {
|
||||
emit('error', err.response.data.msg)
|
||||
} else {
|
||||
emit('error', '登录失败')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user