backend: add: register

This commit is contained in:
starnakin 2023-10-24 16:31:26 +02:00
parent 5fea6457da
commit a3e2c2f631
4 changed files with 35 additions and 3 deletions

View File

@ -0,0 +1,8 @@
<html>
<form method='post'>
{% csrf_token %}
<input type="text" name="username" placeholder="username">
<input type="text" name="password" placeholder="password">
<input type='submit'>
</form>
</html>

View File

@ -4,6 +4,6 @@ from . import views
urlpatterns = [ urlpatterns = [
path("login", views.Login.as_view(), name="login"), path("login", views.Login.as_view(), name="login"),
path("create", views.Create.as_view(), name="create"), path("register", views.Register.as_view(), name="register"),
path("delete", views.Delete.as_view(), name="delete"), path("delete", views.Delete.as_view(), name="delete"),
] ]

View File

@ -2,11 +2,31 @@ from django.shortcuts import render
from django.views import View from django.views import View
# Create your views here. # Create your views here.
from django.http import HttpResponse
from django.contrib.auth.models import User
class Login(View): class Login(View):
pass pass
class Create(View): class Register(View):
pass 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")
class Delete(View): class Delete(View):
pass pass

View File

@ -25,12 +25,16 @@ SECRET_KEY = 'django-insecure-18!@88-wm-!skec9^n-85n(f$my^#mh3!#@f=_e@=*arh_yyjj
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = True
CSRF_TRUSTED_ORIGINS = ['https://code.chauvet.pro']
ALLOWED_HOSTS = ["*"] ALLOWED_HOSTS = ["*"]
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
'accounts.apps.AccountsConfig',
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',