backend: add: register
This commit is contained in:
parent
5fea6457da
commit
a3e2c2f631
8
django/trancendence/accounts/templates/register.html
Normal file
8
django/trancendence/accounts/templates/register.html
Normal 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>
|
@ -4,6 +4,6 @@ from . import views
|
||||
|
||||
urlpatterns = [
|
||||
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"),
|
||||
]
|
@ -2,11 +2,31 @@ 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 Create(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: 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):
|
||||
pass
|
@ -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!
|
||||
DEBUG = True
|
||||
|
||||
CSRF_TRUSTED_ORIGINS = ['https://code.chauvet.pro']
|
||||
|
||||
ALLOWED_HOSTS = ["*"]
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'accounts.apps.AccountsConfig',
|
||||
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
|
Loading…
Reference in New Issue
Block a user