|
|
@ -5,20 +5,19 @@ from rest_framework.response import Response |
|
|
|
from rest_framework.views import APIView |
|
|
|
from rest_framework.views import APIView |
|
|
|
|
|
|
|
|
|
|
|
from api.models import UserInfo, UserCertificationInfo, CertificationInfo, Apps |
|
|
|
from api.models import UserInfo, UserCertificationInfo, CertificationInfo, Apps |
|
|
|
|
|
|
|
from api.utils.auth.util import AuthInfo |
|
|
|
from api.utils.modelutils import get_min_default_domain_cname_obj, add_remote_info_from_request |
|
|
|
from api.utils.modelutils import get_min_default_domain_cname_obj, add_remote_info_from_request |
|
|
|
from api.utils.response import BaseResponse |
|
|
|
from api.utils.response import BaseResponse |
|
|
|
from api.utils.serializer import UserInfoSerializer, CertificationSerializer, UserCertificationSerializer |
|
|
|
from api.utils.serializer import UserInfoSerializer, CertificationSerializer, UserCertificationSerializer |
|
|
|
from api.utils.utils import get_captcha, valid_captcha, \ |
|
|
|
from api.utils.utils import get_random_username, check_username_exists, set_user_token, clean_user_token_and_cache |
|
|
|
get_sender_sms_token, is_valid_sender_code, get_sender_email_token, get_random_username, \ |
|
|
|
|
|
|
|
check_username_exists, set_user_token, clean_user_token_and_cache |
|
|
|
|
|
|
|
from common.base.baseutils import is_valid_phone, is_valid_email, get_real_ip_address |
|
|
|
from common.base.baseutils import is_valid_phone, is_valid_email, get_real_ip_address |
|
|
|
from common.core.auth import ExpiringTokenAuthentication |
|
|
|
from common.core.auth import ExpiringTokenAuthentication |
|
|
|
from common.core.sysconfig import Config |
|
|
|
from common.core.sysconfig import Config |
|
|
|
from common.core.throttle import VisitRegister1Throttle, VisitRegister2Throttle, GetAuthC1Throttle, GetAuthC2Throttle |
|
|
|
from common.core.throttle import VisitRegister1Throttle, VisitRegister2Throttle, GetAuthC1Throttle, GetAuthC2Throttle |
|
|
|
from common.libs.geetest.geetest_utils import first_register, second_validate |
|
|
|
|
|
|
|
from common.libs.mp.wechat import make_wx_login_qrcode, show_qrcode_url |
|
|
|
from common.libs.mp.wechat import make_wx_login_qrcode, show_qrcode_url |
|
|
|
from common.utils.caches import login_auth_failed, set_wx_ticket_login_info_cache, get_wx_ticket_login_info_cache, \ |
|
|
|
from common.utils.caches import login_auth_failed, set_wx_ticket_login_info_cache, get_wx_ticket_login_info_cache, \ |
|
|
|
new_user_download_times_gift |
|
|
|
new_user_download_times_gift |
|
|
|
|
|
|
|
from common.utils.sendmsg import get_sender_sms_token, is_valid_sender_code, get_sender_email_token |
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
|
@ -251,18 +250,11 @@ class LoginView(APIView): |
|
|
|
response = BaseResponse() |
|
|
|
response = BaseResponse() |
|
|
|
receive = request.data |
|
|
|
receive = request.data |
|
|
|
username = receive.get("username", None) |
|
|
|
username = receive.get("username", None) |
|
|
|
if Config.LOGIN.get("captcha"): |
|
|
|
auth_obj = AuthInfo(Config.LOGIN.get("captcha"), Config.LOGIN.get("geetest")) |
|
|
|
is_valid = valid_captcha(receive.get("captcha_key", None), receive.get("authcode", None), username) |
|
|
|
is_valid, msg = auth_obj.valid(receive) |
|
|
|
else: |
|
|
|
if not is_valid or username is None: |
|
|
|
is_valid = True |
|
|
|
|
|
|
|
if is_valid: |
|
|
|
|
|
|
|
if Config.LOGIN.get("geetest"): |
|
|
|
|
|
|
|
geetest = receive.get("geetest", None) |
|
|
|
|
|
|
|
if geetest and second_validate(geetest).get("result", "") == "success": |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
response.code = 1001 |
|
|
|
response.code = 1001 |
|
|
|
response.msg = "geetest 验证有误" |
|
|
|
response.msg = msg |
|
|
|
return Response(response.dict) |
|
|
|
return Response(response.dict) |
|
|
|
|
|
|
|
|
|
|
|
login_type = receive.get("login_type", None) |
|
|
|
login_type = receive.get("login_type", None) |
|
|
@ -350,31 +342,25 @@ class LoginView(APIView): |
|
|
|
response.code = 1006 |
|
|
|
response.code = 1006 |
|
|
|
logger.error(f"username:{username} failed too try , locked") |
|
|
|
logger.error(f"username:{username} failed too try , locked") |
|
|
|
response.msg = "用户登录失败次数过多,已被锁定,请1小时之后再次尝试" |
|
|
|
response.msg = "用户登录失败次数过多,已被锁定,请1小时之后再次尝试" |
|
|
|
else: |
|
|
|
|
|
|
|
response.code = 1001 |
|
|
|
|
|
|
|
response.msg = "验证码有误" |
|
|
|
|
|
|
|
add_remote_info_from_request(request, response.msg) |
|
|
|
add_remote_info_from_request(request, response.msg) |
|
|
|
return Response(response.dict) |
|
|
|
return Response(response.dict) |
|
|
|
|
|
|
|
|
|
|
|
def get(self, request): |
|
|
|
def get(self, request): |
|
|
|
response = BaseResponse() |
|
|
|
response = BaseResponse() |
|
|
|
response.data = {} |
|
|
|
response.data = {} |
|
|
|
if Config.LOGIN.get("captcha"): |
|
|
|
auth_obj = AuthInfo(Config.LOGIN.get("captcha"), Config.LOGIN.get("geetest")) |
|
|
|
response.data = get_captcha() |
|
|
|
response.data['auth_rules'] = auth_obj.make_rules_info() |
|
|
|
if Config.LOGIN.get("geetest"): |
|
|
|
|
|
|
|
response.data['geetest'] = True |
|
|
|
|
|
|
|
response.data['login_type'] = get_login_type() |
|
|
|
response.data['login_type'] = get_login_type() |
|
|
|
allow_f = Config.REGISTER.get("enable") |
|
|
|
allow_f = Config.REGISTER.get("enable") |
|
|
|
response.data['register_enable'] = allow_f |
|
|
|
response.data['register_enable'] = allow_f |
|
|
|
return Response(response.dict) |
|
|
|
return Response(response.dict) |
|
|
|
|
|
|
|
|
|
|
|
def put(self, request): |
|
|
|
def put(self, request): |
|
|
|
import hashlib |
|
|
|
|
|
|
|
response = BaseResponse() |
|
|
|
response = BaseResponse() |
|
|
|
user_id = request.data.get('user_id', None) |
|
|
|
user_id = request.data.get('user_id', None) |
|
|
|
if user_id: |
|
|
|
if user_id: |
|
|
|
sha = hashlib.sha1(str(user_id).encode("utf-8")) |
|
|
|
auth_obj = AuthInfo(Config.LOGIN.get("captcha"), Config.LOGIN.get("geetest")) |
|
|
|
response.data = first_register(sha.hexdigest(), request.META.get('REMOTE_ADDR')) |
|
|
|
response.data = auth_obj.make_geetest_info(user_id, request.META.get('REMOTE_ADDR')) |
|
|
|
else: |
|
|
|
else: |
|
|
|
response.code = 1002 |
|
|
|
response.code = 1002 |
|
|
|
response.msg = '参数错误' |
|
|
|
response.msg = '参数错误' |
|
|
@ -404,13 +390,11 @@ class RegistView(APIView): |
|
|
|
response.msg = "不允许该类型注册" |
|
|
|
response.msg = "不允许该类型注册" |
|
|
|
return Response(response.dict) |
|
|
|
return Response(response.dict) |
|
|
|
|
|
|
|
|
|
|
|
if Config.REGISTER.get("geetest"): |
|
|
|
auth_obj = AuthInfo(Config.REGISTER.get("captcha"), Config.REGISTER.get("geetest")) |
|
|
|
geetest = request.data.get("geetest", None) |
|
|
|
is_valid, msg = auth_obj.valid(request.data) |
|
|
|
if geetest and second_validate(geetest).get("result", "") == "success": |
|
|
|
if not is_valid: |
|
|
|
pass |
|
|
|
response.code = 1001 |
|
|
|
else: |
|
|
|
response.msg = msg |
|
|
|
response.code = 1018 |
|
|
|
|
|
|
|
response.msg = "geetest验证有误" |
|
|
|
|
|
|
|
return Response(response.dict) |
|
|
|
return Response(response.dict) |
|
|
|
|
|
|
|
|
|
|
|
is_valid, target = is_valid_sender_code(act, receive.get("auth_token", None), receive.get("auth_key", None)) |
|
|
|
is_valid, target = is_valid_sender_code(act, receive.get("auth_token", None), receive.get("auth_key", None)) |
|
|
@ -460,10 +444,8 @@ class RegistView(APIView): |
|
|
|
response.data = {} |
|
|
|
response.data = {} |
|
|
|
allow_f = Config.REGISTER.get("enable") |
|
|
|
allow_f = Config.REGISTER.get("enable") |
|
|
|
if allow_f: |
|
|
|
if allow_f: |
|
|
|
if Config.REGISTER.get("captcha"): |
|
|
|
auth_obj = AuthInfo(Config.REGISTER.get("captcha"), Config.REGISTER.get("geetest")) |
|
|
|
response.data = get_captcha() |
|
|
|
response.data['auth_rules'] = auth_obj.make_rules_info() |
|
|
|
if Config.REGISTER.get("geetest"): |
|
|
|
|
|
|
|
response.data['geetest'] = True |
|
|
|
|
|
|
|
response.data['register_type'] = get_register_type() |
|
|
|
response.data['register_type'] = get_register_type() |
|
|
|
response.data['enable'] = allow_f |
|
|
|
response.data['enable'] = allow_f |
|
|
|
return Response(response.dict) |
|
|
|
return Response(response.dict) |
|
|
@ -510,11 +492,12 @@ class UserInfoView(APIView): |
|
|
|
mobile = data.get("mobile", None) |
|
|
|
mobile = data.get("mobile", None) |
|
|
|
email = data.get("email", None) |
|
|
|
email = data.get("email", None) |
|
|
|
if mobile or email: |
|
|
|
if mobile or email: |
|
|
|
if Config.CHANGER.get('captcha'): |
|
|
|
|
|
|
|
is_valid = valid_captcha(data.get("captcha_key", None), data.get("authcode", None), request) |
|
|
|
auth_obj = AuthInfo(Config.CHANGER.get("captcha"), False) |
|
|
|
|
|
|
|
is_valid, msg = auth_obj.valid(data) |
|
|
|
if not is_valid: |
|
|
|
if not is_valid: |
|
|
|
res.code = 1008 |
|
|
|
res.code = 1001 |
|
|
|
res.msg = "图片验证码异常" |
|
|
|
res.msg = msg |
|
|
|
return Response(res.dict) |
|
|
|
return Response(res.dict) |
|
|
|
|
|
|
|
|
|
|
|
if old_password and sure_password: |
|
|
|
if old_password and sure_password: |
|
|
@ -624,22 +607,13 @@ class AuthorizationView(APIView): |
|
|
|
else: |
|
|
|
else: |
|
|
|
p_data = Config.REGISTER |
|
|
|
p_data = Config.REGISTER |
|
|
|
|
|
|
|
|
|
|
|
if p_data.get("captcha"): |
|
|
|
auth_obj = AuthInfo(p_data.get("captcha"), p_data.get("geetest")) |
|
|
|
is_valid = valid_captcha(ext.get("captcha_key", None), ext.get("authcode", None), target) |
|
|
|
auth_data = {'geetest': request.data.get("geetest", None)} |
|
|
|
if ext and is_valid: |
|
|
|
auth_data.update(ext) |
|
|
|
pass |
|
|
|
is_valid, msg = auth_obj.valid(auth_data) |
|
|
|
else: |
|
|
|
if not is_valid: |
|
|
|
res.code = 1018 |
|
|
|
res.code = 1001 |
|
|
|
res.msg = "图片验证码有误" |
|
|
|
res.msg = msg |
|
|
|
return Response(res.dict) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if p_data.get("geetest"): |
|
|
|
|
|
|
|
geetest = request.data.get("geetest", None) |
|
|
|
|
|
|
|
if geetest and second_validate(geetest).get("result", "") == "success": |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
res.code = 1018 |
|
|
|
|
|
|
|
res.msg = "geetest验证有误" |
|
|
|
|
|
|
|
return Response(res.dict) |
|
|
|
return Response(res.dict) |
|
|
|
if ext and ext.get('report'): |
|
|
|
if ext and ext.get('report'): |
|
|
|
app_obj = Apps.objects.filter(app_id=ext.get('report')).first() |
|
|
|
app_obj = Apps.objects.filter(app_id=ext.get('report')).first() |
|
|
@ -666,21 +640,14 @@ class ChangeAuthorizationView(APIView): |
|
|
|
target = request.data.get("target", None) |
|
|
|
target = request.data.get("target", None) |
|
|
|
ext = request.data.get("ext", None) |
|
|
|
ext = request.data.get("ext", None) |
|
|
|
f_type = request.data.get("ftype", None) |
|
|
|
f_type = request.data.get("ftype", None) |
|
|
|
if Config.REGISTER.get("captcha"): |
|
|
|
|
|
|
|
if ext and valid_captcha(ext.get("captcha_key", None), ext.get("authcode", None), target): |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
res.code = 1009 |
|
|
|
|
|
|
|
res.msg = "图片验证码有误" |
|
|
|
|
|
|
|
return Response(res.dict) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if Config.REGISTER.get("geetest"): |
|
|
|
auth_obj = AuthInfo(Config.REGISTER.get("captcha"), Config.REGISTER.get("geetest")) |
|
|
|
geetest = request.data.get("geetest", None) |
|
|
|
auth_data = {'geetest': request.data.get("geetest", None)} |
|
|
|
if geetest and second_validate(geetest).get("result", "") == "success": |
|
|
|
auth_data.update(ext) |
|
|
|
pass |
|
|
|
is_valid, msg = auth_obj.valid(auth_data) |
|
|
|
else: |
|
|
|
if not is_valid or target is None: |
|
|
|
res.code = 1018 |
|
|
|
res.code = 1001 |
|
|
|
res.msg = "geetest验证有误" |
|
|
|
res.msg = msg |
|
|
|
return Response(res.dict) |
|
|
|
return Response(res.dict) |
|
|
|
|
|
|
|
|
|
|
|
res = check_change_userinfo(target, act, 'change', request.user, f_type) |
|
|
|
res = check_change_userinfo(target, act, 'change', request.user, f_type) |
|
|
@ -754,15 +721,14 @@ class CertificationView(APIView): |
|
|
|
return Response(res.dict) |
|
|
|
return Response(res.dict) |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
try: |
|
|
|
if Config.CHANGER.get("captcha"): |
|
|
|
auth_obj = AuthInfo(Config.CHANGER.get("captcha"), False) |
|
|
|
if data and valid_captcha(data.get("captcha_key", None), data.get("authcode", None), |
|
|
|
is_valid, msg = auth_obj.valid(data) |
|
|
|
data.get("mobile")): |
|
|
|
if not is_valid or not data.get("mobile"): |
|
|
|
del data["captcha_key"] |
|
|
|
res.code = 1001 |
|
|
|
del data["authcode"] |
|
|
|
res.msg = msg |
|
|
|
else: |
|
|
|
|
|
|
|
res.code = 1009 |
|
|
|
|
|
|
|
res.msg = "图片验证码有误" |
|
|
|
|
|
|
|
return Response(res.dict) |
|
|
|
return Response(res.dict) |
|
|
|
|
|
|
|
del data["captcha_key"] |
|
|
|
|
|
|
|
del data["verify_code"] |
|
|
|
if Config.CHANGER.get('change_type').get('sms'): |
|
|
|
if Config.CHANGER.get('change_type').get('sms'): |
|
|
|
is_valid, target = is_valid_sender_code('sms', data.get("auth_token", None), data.get("auth_key", None)) |
|
|
|
is_valid, target = is_valid_sender_code('sms', data.get("auth_token", None), data.get("auth_key", None)) |
|
|
|
if is_valid and str(target) == str(data.get("mobile")): |
|
|
|
if is_valid and str(target) == str(data.get("mobile")): |
|
|
@ -809,10 +775,8 @@ class ChangeInfoView(APIView): |
|
|
|
response.data = {} |
|
|
|
response.data = {} |
|
|
|
allow_f = Config.CHANGER.get("enable") |
|
|
|
allow_f = Config.CHANGER.get("enable") |
|
|
|
if allow_f: |
|
|
|
if allow_f: |
|
|
|
if Config.CHANGER.get("captcha"): |
|
|
|
auth_obj = AuthInfo(Config.CHANGER.get("captcha"), Config.CHANGER.get("geetest")) |
|
|
|
response.data = get_captcha() |
|
|
|
response.data['auth_rules'] = auth_obj.make_rules_info() |
|
|
|
if Config.CHANGER.get("geetest"): |
|
|
|
|
|
|
|
response.data['geetest'] = True |
|
|
|
|
|
|
|
response.data['change_type'] = Config.CHANGER.get("change_type") |
|
|
|
response.data['change_type'] = Config.CHANGER.get("change_type") |
|
|
|
response.data['enable'] = allow_f |
|
|
|
response.data['enable'] = allow_f |
|
|
|
return Response(response.dict) |
|
|
|
return Response(response.dict) |
|
|
|