增加邮箱和手机号登录支持
This commit is contained in:
@@ -4,6 +4,7 @@ from datetime import datetime, timedelta
|
|||||||
from captcha.views import CaptchaStore, captcha_image
|
from captcha.views import CaptchaStore, captcha_image
|
||||||
from django.contrib import auth
|
from django.contrib import auth
|
||||||
from django.contrib.auth import login
|
from django.contrib.auth import login
|
||||||
|
from django.db.models import Q
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from drf_yasg import openapi
|
from drf_yasg import openapi
|
||||||
@@ -83,11 +84,18 @@ class LoginSerializer(TokenObtainPairSerializer):
|
|||||||
else:
|
else:
|
||||||
self.image_code and self.image_code.delete()
|
self.image_code and self.image_code.delete()
|
||||||
raise CustomValidationError("图片验证码错误")
|
raise CustomValidationError("图片验证码错误")
|
||||||
|
try:
|
||||||
user = Users.objects.get(username=attrs['username'])
|
user = Users.objects.get(
|
||||||
|
Q(username=attrs['username']) | Q(email=attrs['username']) | Q(mobile=attrs['username']))
|
||||||
|
except Users.DoesNotExist:
|
||||||
|
raise CustomValidationError("您登录的账号不存在")
|
||||||
|
except Users.MultipleObjectsReturned:
|
||||||
|
raise CustomValidationError("您登录的账号存在多个,请联系管理员检查登录账号唯一性")
|
||||||
if not user.is_active:
|
if not user.is_active:
|
||||||
raise CustomValidationError("账号已被锁定,联系管理员解锁")
|
raise CustomValidationError("账号已被锁定,联系管理员解锁")
|
||||||
try:
|
try:
|
||||||
|
# 必须重置用户名为username,否则使用邮箱手机号登录会提示密码错误
|
||||||
|
attrs['username'] = user.username
|
||||||
data = super().validate(attrs)
|
data = super().validate(attrs)
|
||||||
data["name"] = self.user.name
|
data["name"] = self.user.name
|
||||||
data["userId"] = self.user.id
|
data["userId"] = self.user.id
|
||||||
|
|||||||
1
web/public/version-build
Normal file
1
web/public/version-build
Normal file
@@ -0,0 +1 @@
|
|||||||
|
3.0.3.1719538291017
|
||||||
@@ -9,7 +9,7 @@ export default {
|
|||||||
two4: '友情链接',
|
two4: '友情链接',
|
||||||
},
|
},
|
||||||
account: {
|
account: {
|
||||||
accountPlaceholder1: '请输入登录账号',
|
accountPlaceholder1: '请输入登录账号/邮箱/手机号',
|
||||||
accountPlaceholder2: '请输入登录密码',
|
accountPlaceholder2: '请输入登录密码',
|
||||||
accountPlaceholder3: '请输入验证码',
|
accountPlaceholder3: '请输入验证码',
|
||||||
accountBtnText: '登 录',
|
accountBtnText: '登 录',
|
||||||
|
|||||||
Reference in New Issue
Block a user