Merge branch 'signup' into 'master'
Signup See merge request bde/photo21!1
This commit is contained in:
commit
61eadc9d60
9 changed files with 58 additions and 3 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"]
|
||||
9
accounts/templates/accounts/registration.html
Normal file
9
accounts/templates/accounts/registration.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='registration'),
|
||||
]
|
||||
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, 'accounts/registration.html', {'form': form})
|
||||
else:
|
||||
form = RegistrationForm()
|
||||
return render(request, 'accounts/registration.html', {'form': form})
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
from django.http import HttpResponseRedirect
|
||||
from django.conf import settings
|
||||
|
||||
import ipaddress
|
||||
import re
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ INSTALLED_APPS = [
|
|||
'django.contrib.staticfiles',
|
||||
'photologue_custom',
|
||||
'photologue',
|
||||
'accounts',
|
||||
'sortedm2m',
|
||||
'taggit',
|
||||
]
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ from django.contrib import admin
|
|||
from django.urls import include, path
|
||||
from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
from .views import IndexView
|
||||
|
||||
|
|
@ -30,6 +29,7 @@ urlpatterns = [
|
|||
path('i18n/', include('django.conf.urls.i18n')),
|
||||
path('admin/', admin.site.urls),
|
||||
path('admin/doc/', include('django.contrib.admindocs.urls')),
|
||||
path('accounts/registration/', include('accounts.urls'))
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
|
|
|
|||
4
tox.ini
4
tox.ini
|
|
@ -18,7 +18,7 @@ deps =
|
|||
-r{toxinidir}/requirements.txt
|
||||
coverage
|
||||
commands =
|
||||
coverage run --omit='photo21/wsgi.py' --source=photo21,photologue_custom ./manage.py test
|
||||
coverage run --omit='photo21/wsgi.py' --source=photo21,photologue_custom,accounts ./manage.py test
|
||||
coverage report -m
|
||||
|
||||
[testenv:linters]
|
||||
|
|
@ -32,7 +32,7 @@ deps =
|
|||
pep8-naming
|
||||
pyflakes
|
||||
commands =
|
||||
flake8 photo21 photologue_custom
|
||||
flake8 photo21 photologue_custom accounts
|
||||
|
||||
[flake8]
|
||||
ignore = W503, I100, I101
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue