28 lines
1.0 KiB
Python
28 lines
1.0 KiB
Python
from django.shortcuts import render
|
|
from django.views import View
|
|
from django.http import HttpResponse
|
|
from django.contrib.auth.models import User
|
|
from django.db.models.query import QuerySet
|
|
|
|
from ..status_code import *
|
|
from ..settings import *
|
|
|
|
class Register(View):
|
|
def get(self, request):
|
|
return render(request, "register.html")
|
|
|
|
def post(self, request):
|
|
password = request.POST.get("password")
|
|
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 not USERNAME_MAX_SIZE >= len(username) >= USERNAME_MIN_SIZE):
|
|
return HttpResponse(INVALID_USERNAME)
|
|
|
|
if User.objects.filter(username=username).exists():
|
|
return HttpResponse(USERNAME_ALREADY_USED)
|
|
|
|
user = User.objects.create_user(username, password=password)
|
|
user.save()
|
|
|
|
return HttpResponse(USER_ADDED) |