From 2db323f74de0e5d1dbd4fb0fd430ca26486b36ce Mon Sep 17 00:00:00 2001 From: aeltheos Date: Thu, 7 Oct 2021 16:50:35 +0200 Subject: [PATCH] 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 --- photo21/settings.py | 1 + photo21/urls.py | 1 + signup/apps.py | 4 ++++ signup/settings.py | 8 ++++++++ signup/templates/signup.html | 9 +++++++++ signup/urls.py | 5 +++++ signup/views.py | 19 +++++++++++++++++++ 7 files changed, 47 insertions(+) create mode 100644 signup/apps.py create mode 100644 signup/settings.py create mode 100644 signup/templates/signup.html create mode 100644 signup/urls.py create mode 100644 signup/views.py diff --git a/photo21/settings.py b/photo21/settings.py index 3cdb9d1..98510c0 100644 --- a/photo21/settings.py +++ b/photo21/settings.py @@ -43,6 +43,7 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'photologue_custom', 'photologue', + 'signup', 'sortedm2m', 'taggit', ] diff --git a/photo21/urls.py b/photo21/urls.py index aacd159..efae970 100644 --- a/photo21/urls.py +++ b/photo21/urls.py @@ -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: diff --git a/signup/apps.py b/signup/apps.py new file mode 100644 index 0000000..806582a --- /dev/null +++ b/signup/apps.py @@ -0,0 +1,4 @@ +from django.apps import AppConfig + +class Signup(AppConfig): + name = 'signup' \ No newline at end of file diff --git a/signup/settings.py b/signup/settings.py new file mode 100644 index 0000000..91a0e2c --- /dev/null +++ b/signup/settings.py @@ -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, + }, +] \ No newline at end of file diff --git a/signup/templates/signup.html b/signup/templates/signup.html new file mode 100644 index 0000000..82b06fc --- /dev/null +++ b/signup/templates/signup.html @@ -0,0 +1,9 @@ +{% extends "base.html" %} +{% block content %} +

Création d'utilisateur

+
{% csrf_token %} + {{ form }} +
+ +
+{% endblock %} \ No newline at end of file diff --git a/signup/urls.py b/signup/urls.py new file mode 100644 index 0000000..ed10141 --- /dev/null +++ b/signup/urls.py @@ -0,0 +1,5 @@ +from django.urls import path +from .views import signup +urlpatterns = [ + path('', signup, name='signup'), +] diff --git a/signup/views.py b/signup/views.py new file mode 100644 index 0000000..18fc0ce --- /dev/null +++ b/signup/views.py @@ -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}) \ No newline at end of file