ft_transcendence/django/trancendence/accounts/views.py

32 lines
967 B
Python
Raw Normal View History

2023-10-24 07:36:42 -04:00
from django.shortcuts import render
2023-10-24 07:56:16 -04:00
from django.views import View
2023-10-24 07:36:42 -04:00
# Create your views here.
2023-10-24 10:31:26 -04:00
from django.http import HttpResponse
from django.contrib.auth.models import User
2023-10-24 07:56:16 -04:00
class Login(View):
pass
2023-10-24 10:31:26 -04:00
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: password 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")
2023-10-24 07:56:16 -04:00
class Delete(View):
pass