ft_transcendence/django/trancendence/accounts/views.py

32 lines
967 B
Python

from django.shortcuts import render
from django.views import View
# Create your views here.
from django.http import HttpResponse
from django.contrib.auth.models import User
class Login(View):
pass
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 len(password) < 3):
return HttpResponse("error: password invalid")
username = request.POST.get("username")
if (username == None or len(username) < 3):
return HttpResponse("error: username invalid")
if User.objects.filter(username=username).exists():
return HttpResponse("error: username already used")
user = User.objects.create_user(username, password=password)
user.save()
return HttpResponse("ok: user added")
class Delete(View):
pass