fix: use variable to len
This commit is contained in:
parent
d469466e66
commit
85f273b726
4
django/trancendence/accounts/settings.py
Normal file
4
django/trancendence/accounts/settings.py
Normal file
@ -0,0 +1,4 @@
|
||||
PASSWORD_MIN_SIZE = 3
|
||||
PASSWORD_MAX_SIZE = 128
|
||||
USERNAME_MIN_SIZE = 3
|
||||
USERNAME_MAX_SIZE = 40
|
@ -7,6 +7,7 @@ from django.contrib.auth.models import User
|
||||
from django.db.models.query import QuerySet
|
||||
|
||||
from .status_code import *
|
||||
from .settings import *
|
||||
|
||||
class Login(View):
|
||||
def get(self, request):
|
||||
@ -37,10 +38,10 @@ class Register(View):
|
||||
|
||||
def post(self, request):
|
||||
password = request.POST.get("password")
|
||||
if (password == None or len(password) < 3):
|
||||
if (password == None or not PASSWORD_MAX_SIZE >= len(password) >= PASSWORD_MIN_SIZE):
|
||||
return HttpResponse(INVALID_PASSWORD)
|
||||
username = request.POST.get("username")
|
||||
if (username == None or len(username) < 3):
|
||||
if (username == None or not USERNAME_MAX_SIZE >= len(username) >= USERNAME_MIN_SIZE):
|
||||
return HttpResponse(INVALID_USERNAME)
|
||||
|
||||
if User.objects.filter(username=username).exists():
|
||||
@ -98,7 +99,7 @@ class ChangePassword(View):
|
||||
return HttpResponse(INVALID_USERNAME_PASSWORD)
|
||||
|
||||
new_password = request.POST.get("new_password")
|
||||
if (new_password == None or len(new_password) < 3):
|
||||
if (new_password == None or not PASSWORD_MAX_SIZE >= len(new_password) >= PASSWORD_MIN_SIZE):
|
||||
return HttpResponse(INVALID_PASSWORD)
|
||||
|
||||
user.set_password(new_password)
|
||||
|
Loading…
Reference in New Issue
Block a user