[Update] 修改校验用户有效性逻辑

pull/3554/head
BaiJiangJie 5 years ago
parent a88db3d9db
commit b90960e6e1

@ -1,31 +1,20 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
from django.utils.translation import ugettext as _
from django.contrib.auth import authenticate from django.contrib.auth import authenticate
from common.utils import (
get_ip_city, get_object_or_none, validate_ip
)
from users.models import User
from . import errors from . import errors
def check_user_valid(**kwargs): def check_user_valid(**kwargs):
password = kwargs.pop('password', None) password = kwargs.pop('password', None)
public_key = kwargs.pop('public_key', None) public_key = kwargs.pop('public_key', None)
email = kwargs.pop('email', None)
username = kwargs.pop('username', None) username = kwargs.pop('username', None)
request = kwargs.get('request') request = kwargs.get('request')
if username: user = authenticate(request, username=username,
user = get_object_or_none(User, username=username) password=password, public_key=public_key)
elif email: if not user:
user = get_object_or_none(User, email=email) return None, errors.reason_password_failed
else:
user = None
if user is None:
return None, errors.reason_user_not_exist
elif user.is_expired: elif user.is_expired:
return None, errors.reason_user_inactive return None, errors.reason_user_inactive
elif not user.is_active: elif not user.is_active:
@ -33,9 +22,4 @@ def check_user_valid(**kwargs):
elif user.password_has_expired: elif user.password_has_expired:
return None, errors.reason_password_expired return None, errors.reason_password_expired
if password or public_key:
user = authenticate(request, username=username,
password=password, public_key=public_key)
if user:
return user, '' return user, ''
return None, errors.reason_password_failed

Loading…
Cancel
Save