注册码选填
This commit is contained in:
@@ -188,7 +188,7 @@ def register_submit(request):
|
||||
email_code = (payload.get("email_code") or "").strip()
|
||||
username = (payload.get("username") or "").strip()
|
||||
password = (payload.get("password") or "")
|
||||
if not code or not email or not email_code or not username or not password:
|
||||
if not email or not email_code or not username or not password:
|
||||
return HttpResponseBadRequest("Missing fields")
|
||||
v = request.session.get("email_verify") or {}
|
||||
if (v.get("email") or "") != email:
|
||||
@@ -201,20 +201,22 @@ def register_submit(request):
|
||||
return JsonResponse({"ok": False, "message": "验证码已过期"}, status=400)
|
||||
if (v.get("code") or "") != email_code:
|
||||
return JsonResponse({"ok": False, "message": "邮箱验证码错误"}, status=400)
|
||||
rc = get_registration_code(code)
|
||||
if not rc:
|
||||
return JsonResponse({"ok": False, "message": "注册码无效"}, status=400)
|
||||
try:
|
||||
exp = rc.get("expires_at")
|
||||
now = __import__("datetime").datetime.now(__import__("datetime").timezone.utc)
|
||||
if hasattr(exp, 'isoformat'):
|
||||
exp_dt = exp
|
||||
else:
|
||||
exp_dt = __import__("datetime").datetime.fromisoformat(str(exp))
|
||||
if exp_dt <= now:
|
||||
return JsonResponse({"ok": False, "message": "注册码已过期"}, status=400)
|
||||
except Exception:
|
||||
pass
|
||||
rc = None
|
||||
if code:
|
||||
rc = get_registration_code(code)
|
||||
if not rc:
|
||||
return JsonResponse({"ok": False, "message": "注册码无效"}, status=400)
|
||||
try:
|
||||
exp = rc.get("expires_at")
|
||||
now = __import__("datetime").datetime.now(__import__("datetime").timezone.utc)
|
||||
if hasattr(exp, 'isoformat'):
|
||||
exp_dt = exp
|
||||
else:
|
||||
exp_dt = __import__("datetime").datetime.fromisoformat(str(exp))
|
||||
if exp_dt <= now:
|
||||
return JsonResponse({"ok": False, "message": "注册码已过期"}, status=400)
|
||||
except Exception:
|
||||
pass
|
||||
existing = es_get_user_by_username(username)
|
||||
if existing:
|
||||
return JsonResponse({"ok": False, "message": "用户名已存在"}, status=409)
|
||||
@@ -226,8 +228,8 @@ def register_submit(request):
|
||||
"password": password,
|
||||
"permission": 1,
|
||||
"email": email,
|
||||
"key": rc.get("keys") or [],
|
||||
"manage_key": rc.get("manage_keys") or [],
|
||||
"key": (rc.get("keys") if rc else []) or [],
|
||||
"manage_key": (rc.get("manage_keys") if rc else []) or [],
|
||||
})
|
||||
if not ok:
|
||||
return JsonResponse({"ok": False, "message": "注册失败"}, status=500)
|
||||
|
||||
Reference in New Issue
Block a user