changed signup to accounts
finished fixing linting
This commit is contained in:
parent
4ab42bf3de
commit
d8853cee1c
11 changed files with 13 additions and 12 deletions
5
accounts/apps.py
Normal file
5
accounts/apps.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class Accounts(AppConfig):
|
||||
name = 'accounts'
|
||||
13
accounts/forms.py
Normal file
13
accounts/forms.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
from django import forms
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
class RegistrationForm(UserCreationForm):
|
||||
email = forms.EmailField(label="Email", widget=forms.TextInput(), required=True)
|
||||
first_name = forms.CharField(label="Prénom", widget=forms.TextInput(), required=True)
|
||||
last_name = forms.CharField(label="Nom", widget=forms.TextInput(), required=True)
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ["username", "password1", "password2", "email", "first_name", "last_name"]
|
||||
8
accounts/settings.py
Normal file
8
accounts/settings.py
Normal 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/accounts/templates')],
|
||||
'APP_DIRS': True,
|
||||
},
|
||||
]
|
||||
9
accounts/templates/signup.html
Normal file
9
accounts/templates/signup.html
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<h1>Création d'utilisateur</h1>
|
||||
<form action="" method="post">{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<br>
|
||||
<input type="submit" value="Envoyer">
|
||||
</form>
|
||||
{% endblock %}
|
||||
6
accounts/urls.py
Normal file
6
accounts/urls.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
from django.urls import path
|
||||
|
||||
from .views import signup
|
||||
urlpatterns = [
|
||||
path('', signup, name='accounts'),
|
||||
]
|
||||
20
accounts/views.py
Normal file
20
accounts/views.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
from django.contrib.auth import login
|
||||
from django.shortcuts import redirect, render
|
||||
|
||||
from .forms import RegistrationForm
|
||||
|
||||
|
||||
def signup(request):
|
||||
if request.method == 'POST':
|
||||
form = RegistrationForm(request.POST)
|
||||
if form.is_valid():
|
||||
user = form.save()
|
||||
user.first_name = form.cleaned_data.get('first_name')
|
||||
user.last_name = form.cleaned_data.get('last_name')
|
||||
user.email = form.cleaned_data.get('email')
|
||||
login(request, user)
|
||||
return redirect('/')
|
||||
return render(request, 'signup.html', {'form': form})
|
||||
else:
|
||||
form = RegistrationForm()
|
||||
return render(request, 'signup.html', {'form': form})
|
||||
Loading…
Add table
Add a link
Reference in a new issue