Skip to content

Commit

Permalink
fix: 登录失败时无提示
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Nov 20, 2024
1 parent 753066c commit 6e9c213
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 5 additions & 1 deletion pkg/api/http/controller/groups/user.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import quart
import sqlalchemy
import argon2

from .. import group
from .....persistence.entities import user
Expand Down Expand Up @@ -32,7 +33,10 @@ async def _() -> str:
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
Expand Down
3 changes: 1 addition & 2 deletions pkg/api/http/service/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ async def authenticate(self, user_email: str, password: str) -> str | None:

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)

Expand Down
10 changes: 7 additions & 3 deletions web/src/components/LoginDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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', '登录失败')
}
})
}
Expand Down

0 comments on commit 6e9c213

Please sign in to comment.