core: accounts: separate views i multiple files
This commit is contained in:
28
django/trancendence/accounts/views/register.py
Normal file
28
django/trancendence/accounts/views/register.py
Normal file
@ -0,0 +1,28 @@
|
||||
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)
|
Reference in New Issue
Block a user