Merge branch 'models' into qwann/html/base
This commit is contained in:
commit
4f73d3cc1a
23 changed files with 356 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@
|
|||
__pycache__
|
||||
venv
|
||||
evenementiel/settings.py
|
||||
.*.swp
|
||||
|
|
|
@ -34,6 +34,7 @@ ALLOWED_HOSTS = []
|
|||
INSTALLED_APPS = [
|
||||
'equipment.apps.EquipmentConfig',
|
||||
'event.apps.EventConfig',
|
||||
'user.apps.UserConfig',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
|
|
|
@ -3,11 +3,13 @@ GestionEvenmentiel URL configuration
|
|||
"""
|
||||
from django.conf import settings
|
||||
from django.conf.urls import url, include
|
||||
from django.conf.urls import url
|
||||
from django.contrib import admin
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^admin/', admin.site.urls),
|
||||
url(r'^event/', include('event.urls')),
|
||||
url(r'^user/', include('user.urls')),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
|
|
0
user/__init__.py
Normal file
0
user/__init__.py
Normal file
3
user/admin.py
Normal file
3
user/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
5
user/apps.py
Normal file
5
user/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class UserConfig(AppConfig):
|
||||
name = 'user'
|
36
user/forms.py
Normal file
36
user/forms.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class CreateUserForm(UserCreationForm):
|
||||
key = forms.CharField(
|
||||
label="Clée de sécurité",
|
||||
widget=forms.PasswordInput,
|
||||
help_text="Cette clée est fournie par l'administrat-rice-eur "
|
||||
"du site. Pour en obtenir une veuillez la-le contacter."
|
||||
)
|
||||
error_m = {'wrong_key': "La clef fournie est eronnée."}
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ('username', 'first_name', 'last_name',
|
||||
'email', 'password1', 'password2',)
|
||||
|
||||
def save(self, commit=True):
|
||||
user = super(CreateUserForm, self).save(commit=False)
|
||||
user.email = self.cleaned_data["email"]
|
||||
user.first_name = self.cleaned_data["first_name"]
|
||||
user.last_name = self.cleaned_data["last_name"]
|
||||
if commit:
|
||||
user.save()
|
||||
return user
|
||||
|
||||
def clean_key(self):
|
||||
key = self.cleaned_data.get("key")
|
||||
if key != settings.CREATE_USER_KEY:
|
||||
raise forms.ValidationError(
|
||||
self.error_m['wrong_key'],
|
||||
code='wrong_key')
|
||||
return key
|
26
user/migrations/0001_initial.py
Normal file
26
user/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.6 on 2016-06-14 22:17
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Profil',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
35
user/migrations/0002_auto_20160616_1803.py
Normal file
35
user/migrations/0002_auto_20160616_1803.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.6 on 2016-06-16 16:03
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('user', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='profil',
|
||||
name='modif_pad',
|
||||
field=models.BooleanField(default=False, verbose_name='Modifier tous les pads'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='profil',
|
||||
name='read_kholle',
|
||||
field=models.BooleanField(default=False, verbose_name='Lecture de khôlles'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='profil',
|
||||
name='write_kholle',
|
||||
field=models.BooleanField(default=False, verbose_name='Écriture de khôlles'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='profil',
|
||||
name='write_pad',
|
||||
field=models.BooleanField(default=False, verbose_name='Écrire des pads'),
|
||||
),
|
||||
]
|
31
user/migrations/0003_auto_20160623_1603.py
Normal file
31
user/migrations/0003_auto_20160623_1603.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.6 on 2016-06-23 14:03
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('user', '0002_auto_20160616_1803'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='profil',
|
||||
name='modif_pad',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='profil',
|
||||
name='read_kholle',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='profil',
|
||||
name='write_kholle',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='profil',
|
||||
name='write_pad',
|
||||
),
|
||||
]
|
22
user/migrations/0004_auto_20160623_1808.py
Normal file
22
user/migrations/0004_auto_20160623_1808.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.6 on 2016-06-23 16:08
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('user', '0003_auto_20160623_1603'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='profil',
|
||||
name='user',
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name='Profil',
|
||||
),
|
||||
]
|
0
user/migrations/__init__.py
Normal file
0
user/migrations/__init__.py
Normal file
3
user/models.py
Normal file
3
user/models.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
|
7
user/templates/user/base_user.html
Normal file
7
user/templates/user/base_user.html
Normal file
|
@ -0,0 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block aside %}
|
||||
{% block user_aside_before %}{% endblock %}
|
||||
<p>Les comptes utilisateurs vous donnent accès à la gestion et d'évènements. Vous pouvez vous connecter par le CAS ENS ou via votre compte si vous n'avez pas d'identifiants CAS. Pour créer un tel compte il est nécessaire d'avoir une clée ; merci de contacter un-e administrat-rice-eur pour en obtenir une.</p>
|
||||
{% block user_aside_after %}{% endblock %}
|
||||
{% endblock %}
|
4
user/templates/user/change_pass.html
Normal file
4
user/templates/user/change_pass.html
Normal file
|
@ -0,0 +1,4 @@
|
|||
{% extends "user/user_form.html" %}
|
||||
|
||||
{% block action_name %}{% url 'user:password_change' %}{% endblock %}
|
||||
{% block user_error %}Une erreur s'est produite, veuillez réessayer.{% endblock %}
|
6
user/templates/user/email_password_reset.html
Normal file
6
user/templates/user/email_password_reset.html
Normal file
|
@ -0,0 +1,6 @@
|
|||
Bonjour,
|
||||
|
||||
Quelqu'un a demandé à réinitialiser le mot de passe pour le compte utilisateur de qwann.fr utilisant l'adresse mail : {{ email }}. Pour réinitialiser le mot de passe, veuillez suivre le lien suivant :
|
||||
{{ protocol}}://qwann.fr{% url 'user:password_reset_confirm' uidb64=uid token=token %}
|
||||
|
||||
Merci de ne pas répondre à ce mail.
|
28
user/templates/user/login.html
Normal file
28
user/templates/user/login.html
Normal file
|
@ -0,0 +1,28 @@
|
|||
{% extends "user/user_form.html" %}
|
||||
|
||||
{% block action_name %}{% url 'user:login' %}{% endblock %}
|
||||
{% block user_error %}L'identitfiant et le mot de passe ne correspondent pas !{% endblock %}
|
||||
|
||||
{% block extra_form_input %}
|
||||
<input type="hidden" name="next" value="{{ next }}" />
|
||||
{% endblock %}
|
||||
|
||||
{% block user_aside_after %}
|
||||
<hr/>
|
||||
<p>Vous n'avez pas de compte utilisateur et vous souhaiteriez en créer un ?</p>
|
||||
<form action="{% url 'user:create_user' %}" class="form-horizontal">
|
||||
<input type="submit" value="Créer un compte" class="btn btn-default btn-block btn-lg">
|
||||
</form>
|
||||
<hr/>
|
||||
<p>Vous avez déjà un compte utilisateur et vous avez oublié votre mot de passe ?</p>
|
||||
<form action="{% url 'user:password_reset' %}" class="form-horizontal">
|
||||
<input type="submit" value="Réinitialiser le mot de passe" class="btn btn-default btn-block btn-lg">
|
||||
</form>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function() {
|
||||
/* Met le focus sur le champ user
|
||||
* du formulaire de connexion */
|
||||
$('#id_username').focus();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
4
user/templates/user/password_reset.html
Normal file
4
user/templates/user/password_reset.html
Normal file
|
@ -0,0 +1,4 @@
|
|||
{% extends "user/user_form.html" %}
|
||||
|
||||
{% block action_name %}{% url 'user:password_reset' %}{% endblock %}
|
||||
{% block user_error %}L'identitfiant et le mot de passe ne correspondent pas !{% endblock %}
|
1
user/templates/user/subject_password_reset.txt
Normal file
1
user/templates/user/subject_password_reset.txt
Normal file
|
@ -0,0 +1 @@
|
|||
[Qwann.fr] Réinitialisation du mot de passe
|
35
user/templates/user/user_form.html
Normal file
35
user/templates/user/user_form.html
Normal file
|
@ -0,0 +1,35 @@
|
|||
{% extends "user/base_user.html" %}
|
||||
{% load bootstrap %}
|
||||
|
||||
{% block section_title %}{{ sec_title }}{% endblock %}
|
||||
{% block content %}
|
||||
{% if form.errors %}
|
||||
<p class="text-danger">{% block user_error %}{% endblock %}</p>
|
||||
{% endif %}
|
||||
<form class="form-horizontal" method="post" action="{%block action_name%}{%endblock%}">
|
||||
{% csrf_token %}
|
||||
<fieldset>
|
||||
{% for field in form %}
|
||||
{{ field | bootstrap }}
|
||||
{% endfor %}
|
||||
</fieldset>
|
||||
<div class="form-action">
|
||||
<button type="submit" class="btn btn-primary pull-right">
|
||||
{{ button }}
|
||||
</button>
|
||||
{% block extra_form_input %}{% endblock %}
|
||||
</div>
|
||||
</form>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function() {
|
||||
/* Met le focus sur le premier champ input
|
||||
* du formulaire chargé */
|
||||
$('form').eq(0).find('input').eq(1).focus();
|
||||
/* NB : c'est eq(1) parce qu'il y a le csrf_token ;) */
|
||||
/* NB : ATTENTION, le premier champ input n'est
|
||||
* pas toujours le premier champs, ce code n'est
|
||||
* pas toujours pertinent */
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
3
user/tests.py
Normal file
3
user/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
88
user/urls.py
Normal file
88
user/urls.py
Normal file
|
@ -0,0 +1,88 @@
|
|||
from django.conf.urls import url, include
|
||||
from django.contrib.auth import views as auth_views
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from event.views import Index #TODO : mettre le vrai home
|
||||
from user.views import CreateUser
|
||||
|
||||
app_name = 'user'
|
||||
urlpatterns = [
|
||||
# CREATE USER
|
||||
url('^create/$', CreateUser.as_view(), name='create_user'),
|
||||
# LOGIN
|
||||
url('^login/$',
|
||||
auth_views.login,
|
||||
{ 'template_name': 'user/login.html',
|
||||
'extra_context': {
|
||||
'sec_title' : 'Connexion',
|
||||
'button' : 'Se connecter',
|
||||
},
|
||||
},
|
||||
name='login',
|
||||
),
|
||||
# LOGOUT
|
||||
url('^logout/$',
|
||||
auth_views.logout,
|
||||
#TODO : mettre le vrai home
|
||||
{ 'next_page': reverse_lazy('event:index'),
|
||||
},
|
||||
name='logout',),
|
||||
# PASSWORD_CHANGE
|
||||
url('^password_change/$',
|
||||
auth_views.password_change,
|
||||
{ 'template_name': 'user/change_pass.html',
|
||||
#TODO : mettre le vrai home
|
||||
'post_change_redirect': reverse_lazy('event:index'),
|
||||
'extra_context': {
|
||||
'sec_title' : 'Changement de mot de passe',
|
||||
'button' : 'Modifier',
|
||||
},
|
||||
},
|
||||
name='password_change'),
|
||||
# url('^password_change/done/$', name='password_change_done'),
|
||||
# RESET PASSWORD
|
||||
url('^password_reset/$',
|
||||
auth_views.password_reset,
|
||||
{ 'template_name' : 'user/password_reset.html',
|
||||
'email_template_name': 'email_password_reset.html',
|
||||
'subject_template_name': 'subject_password_reset.txt',
|
||||
'post_reset_redirect': reverse_lazy('user:password_reset_done'),
|
||||
'extra_context': {
|
||||
'sec_title' : 'Demande de nouveau mot de passe',
|
||||
'button' : 'Envoyer'
|
||||
},
|
||||
},
|
||||
name='password_reset'),
|
||||
# PASS RESET DONE
|
||||
url('^password_reset/done/$',
|
||||
#TODO : mettre le vrai home
|
||||
Index.as_view(),
|
||||
name='password_reset_done'),
|
||||
# PASS RESET CONFIRM
|
||||
url('^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
|
||||
auth_views.password_reset_confirm,
|
||||
{
|
||||
'template_name': 'user/user_form.html',
|
||||
'post_reset_redirect' : reverse_lazy('user:password_reset_complete'),
|
||||
'extra_context': {
|
||||
'sec_title' : 'Changer de mot de passe',
|
||||
'button' : 'Changer'
|
||||
},
|
||||
},
|
||||
name='password_reset_confirm'),
|
||||
# PASS RESET COMPLETE
|
||||
url('^reset/done/$',
|
||||
#TODO : mettre le vrai home
|
||||
Index.as_view(),
|
||||
name='password_reset_complete'),
|
||||
]
|
||||
|
||||
# Inclu les vues suivantes :
|
||||
|
||||
# ^login/$ [name='login']
|
||||
# ^logout/$ [name='logout']
|
||||
# ^password_change/$ [name='password_change']
|
||||
# ^password_change/done/$ [name='password_change_done']
|
||||
# ^password_reset/$ [name='password_reset']
|
||||
# ^password_reset/done/$ [name='password_reset_done']
|
||||
# ^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$ [name='password_reset_confirm']
|
||||
# ^reset/done/$ [name='password_reset_complete']
|
15
user/views.py
Normal file
15
user/views.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
from user.forms import CreateUserForm
|
||||
from django.views.generic.edit import CreateView
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
|
||||
class CreateUser(SuccessMessageMixin, CreateView):
|
||||
template_name = 'user/user_form.html'
|
||||
form_class = CreateUserForm
|
||||
success_url = reverse_lazy('erkan:index')
|
||||
success_message = "Votre compte utilisateur a été correctement créé !"
|
||||
def get_context_data(self, **kwargs):
|
||||
ctx = super(CreateUser, self).get_context_data(**kwargs)
|
||||
ctx['button'] = 'Créer'
|
||||
ctx['sec_title'] = "Création d'utilisateur"
|
||||
return ctx
|
Loading…
Reference in a new issue