inital commit for signup

added a basic app using the UserCreationForm to create new user at /accounts/signup/
change outside of the app are:
-added signup to INSTALLED_APPS in /photo21/settings.py
-added accounts/signup/ to path in /photo21/urls.py

should extend UserCreationForm to have field for email and maybe first/last names, except if we want the user to add that themselves later
This commit is contained in:
aeltheos 2021-10-07 16:50:35 +02:00
parent 5848b83e1e
commit 2db323f74d
7 changed files with 47 additions and 0 deletions

View file

@ -43,6 +43,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'photologue_custom',
'photologue',
'signup',
'sortedm2m',
'taggit',
]

View file

@ -30,6 +30,7 @@ urlpatterns = [
path('i18n/', include('django.conf.urls.i18n')),
path('admin/', admin.site.urls),
path('admin/doc/', include('django.contrib.admindocs.urls')),
path('accounts/signup/', include('signup.urls'))
]
if settings.DEBUG:

4
signup/apps.py Normal file
View file

@ -0,0 +1,4 @@
from django.apps import AppConfig
class Signup(AppConfig):
name = 'signup'

8
signup/settings.py Normal file
View file

@ -0,0 +1,8 @@
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
{
'DIRS': [os.path.join(BASE_DIR, 'photo21/signup/templates')],
'APP_DIRS': True,
},
]

View file

@ -0,0 +1,9 @@
{% extends "base.html" %}
{% block content %}
<h1>Création d'utilisateur</h1>
<form action = '' method="post">{% csrf_token %}
{{ form }}
<br>
<input type="submit" value="Envoyer">
</form>
{% endblock %}

5
signup/urls.py Normal file
View file

@ -0,0 +1,5 @@
from django.urls import path
from .views import signup
urlpatterns = [
path('', signup, name='signup'),
]

19
signup/views.py Normal file
View file

@ -0,0 +1,19 @@
from django import forms
from django.contrib.auth import login
from django.http.response import HttpResponse
from django.shortcuts import redirect, render
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
def signup(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
user = form.save()
login(request, user)
return redirect('/')
return render(request,'signup.html', {'form':form})
else:
form = UserCreationForm()
return render(request,'signup.html', {'form':form})