Skip to content

Commit

Permalink
fix a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nineaiyu committed Jun 17, 2020
1 parent 863c4d2 commit a06822e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
12 changes: 11 additions & 1 deletion fir_ser/api/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# project: 5月
# author: liuyu
# date: 2020/5/7
import os
import os, re
from fir_ser.settings import SUPER_SIGN_ROOT, SERVER_DOMAIN, CAPTCHA_LENGTH, MEDIA_ROOT
from api.models import APPSuperSignUsedInfo, APPToDeveloper, \
UDIDsyncDeveloper
Expand Down Expand Up @@ -112,3 +112,13 @@ def upload_oss_default_head_img(user_obj, storage_obj):
if storage_obj:
storage_obj = Storage(user_obj, storage_obj)
return storage_obj.upload_file(head_img_full_path)


def is_valid_domain(value):
pattern = re.compile(
r'^(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|'
r'([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|'
r'([a-zA-Z0-9][-_.a-zA-Z0-9]{0,61}[a-zA-Z0-9]))\.'
r'([a-zA-Z]{2,13}|[a-zA-Z0-9-]{2,30}.[a-zA-Z]{2,3})$'
)
return True if pattern.match(value) else False
29 changes: 20 additions & 9 deletions fir_ser/api/views/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from rest_framework.views import APIView
import binascii
import os, datetime
from api.utils.utils import get_captcha, valid_captcha
from api.utils.utils import get_captcha, valid_captcha, is_valid_domain
from api.utils.TokenManager import DownloadToken, generateNumericTokenOfLength
from api.utils.auth import ExpiringTokenAuthentication
from api.utils.response import BaseResponse
Expand Down Expand Up @@ -132,19 +132,30 @@ def put(self, request):
# 修改个人资料
domain_name = data.get("domain_name", None)
if domain_name:
domain_name_list = domain_name.strip(' ').strip("http://").strip("https://").split("/")
if len(domain_name_list) > 1:
domain_name_list = domain_name.strip(' ').replace("http://", "").replace("https://", "").split("/")
if len(domain_name_list) > 0:
domain_name = domain_name_list[0]
if len(domain_name) > 3:
if len(domain_name) > 3 and is_valid_domain(domain_name_list[0]):
if domain_name == SERVER_DOMAIN.get("REDIRECT_UDID_DOMAIN").split("//")[1]:
serializer = UserInfoSerializer(request.user)
res.data = serializer.data
res.code = 1004
res.msg = "域名设置失败,请更换其他域名"
return Response(res.dict)
admin_storage = UserInfo.objects.filter(is_superuser=True).order_by('pk').first()
if admin_storage and admin_storage.uid == request.user.uid:
request.user.domain_name = domain_name
set_default_app_wx_easy(request.user)
else:
serializer = UserInfoSerializer(request.user)
res.data = serializer.data
res.code = 1004
res.msg = "域名设置失败,请更换其他域名"
return Response(res.dict)
else:
request.user.domain_name = domain_name
set_default_app_wx_easy(request.user)
else:
serializer = UserInfoSerializer(request.user)
res.data = serializer.data
res.code = 1004
res.msg = "域名校验失败"
return Response(res.dict)

if domain_name == '':
request.user.domain_name = None
Expand Down

0 comments on commit a06822e

Please sign in to comment.