修复登录时邮箱大小写敏感
This commit is contained in:
@@ -18,6 +18,7 @@ from datetime import datetime
|
||||
import logging
|
||||
|
||||
import peewee
|
||||
from peewee import fn
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
|
||||
from api.db import UserTenantRole
|
||||
@@ -93,8 +94,15 @@ class UserService(CommonService):
|
||||
Returns:
|
||||
User object if authentication successful, None otherwise.
|
||||
"""
|
||||
user = cls.model.select().where((cls.model.email == email),
|
||||
(cls.model.status == StatusEnum.VALID.value)).first()
|
||||
normalized_email = (email or "").strip().lower()
|
||||
user = (
|
||||
cls.model.select()
|
||||
.where(
|
||||
fn.Lower(cls.model.email) == normalized_email,
|
||||
cls.model.status == StatusEnum.VALID.value
|
||||
)
|
||||
.first()
|
||||
)
|
||||
if user and check_password_hash(str(user.password), password):
|
||||
return user
|
||||
else:
|
||||
@@ -106,6 +114,16 @@ class UserService(CommonService):
|
||||
users = cls.model.select().where((cls.model.email == email))
|
||||
return list(users)
|
||||
|
||||
@classmethod
|
||||
@DB.connection_context()
|
||||
def query_user_by_email_insensitive(cls, email):
|
||||
normalized_email = (email or "").strip().lower()
|
||||
users = (
|
||||
cls.model.select()
|
||||
.where(fn.Lower(cls.model.email) == normalized_email)
|
||||
)
|
||||
return list(users)
|
||||
|
||||
@classmethod
|
||||
@DB.connection_context()
|
||||
def save(cls, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user