Commit b0fca7f6 authored by Yoann Pietri's avatar Yoann Pietri Committed by root

Implémentation de l'auto inscription

parent a71e01e1
......@@ -117,6 +117,7 @@ class EditGeneralOptionForm(ModelForm):
self.fields['site_name'].label = 'Nom du site web'
self.fields['email_from'].label = "Adresse mail d\
'expedition automatique"
self.fields['GTU_sum_up'].label = "Résumé des CGU"
class EditAssoOptionForm(ModelForm):
......
......@@ -302,6 +302,16 @@ class GeneralOption(models.Model):
req_expire_hrs = models.IntegerField(default=48)
site_name = models.CharField(max_length=32, default="Re2o")
email_from = models.EmailField(default="www-data@serveur.net")
GTU_sum_up = models.TextField(
default="",
blank=True,
)
GTU = models.FileField(
upload_to = '',
default="",
null=True,
blank=True,
)
class Meta:
permissions = (
......
......@@ -137,7 +137,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<tr>
<th>Message global affiché sur le site</th>
<td>{{ generaloptions.general_message }}</td>
<th>Résumé des CGU</th>
<td>{{ generaloptions.GTU_sum_up }}</td>
<tr>
<tr>
<th>CGU</th>
<td>{{generaloptions.GTU}}</th>
</tr>
</table>
<h4>Données de l'association</h4>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'AssoOption' %}">
......
......@@ -33,7 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<h3>Edition des préférences</h3>
<form class="form" method="post">
<form class="form" method="post" enctype="multipart/form-data">
{% csrf_token %}
{% massive_bootstrap_form options 'utilisateur_asso' %}
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
......
......@@ -95,6 +95,7 @@ def edit_options(request, section):
return redirect(reverse('index'))
options = form_instance(
request.POST or None,
request.FILES or None,
instance=options_instance
)
if options.is_valid():
......
......@@ -45,11 +45,10 @@ def can_create(model):
def decorator(view):
def wrapper(request, *args, **kwargs):
can, msg = model.can_create(request.user, *args, **kwargs)
#options, _created = OptionalUser.objects.get_or_create()
if not can:
messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu")
return redirect(reverse('users:profil',
kwargs={'userid':str(request.user.id)}
))
return redirect(reverse('index'))
return view(request, *args, **kwargs)
return wrapper
return decorator
......
......@@ -150,7 +150,7 @@ STATICFILES_DIRS = (
),
)
MEDIA_ROOT = '/var/www/re2o/static'
MEDIA_ROOT = '/var/www/re2o/media'
STATIC_URL = '/static/'
......
......@@ -26,6 +26,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{# Load the tag library #}
{% load bootstrap3 %}
{% load acl %}
{% load self_adhesion %}
{% self_adhesion as var_sa %}
<!DOCTYPE html>
<html lang="fr">
<head prefix="og: http://ogp.me/ns#">
......@@ -102,17 +104,26 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</form>
</div>
<ul class="nav navbar-nav navbar-right">
<li>
{% if request.user.is_authenticated %}
<li>
<a href="{% url 'logout' %}">
<span class="glyphicon glyphicon-log-out"></span> Logout
</a>
</li>
{% else %}
{% if var_sa %}
<li>
<a href="{% url 'users:new-user' %}">
<span class="glyphicon glyphicon-user"></span> Créer un compte
</a>
</li>
{% endif %}
<li>
<a href="{% url 'login' %}">
<span class="glyphicon glyphicon-log-in"></span> Login
</a>
</li>
{% endif %}
</li>
</ul>
{% can_view_app preferences %}
<ul class="nav navbar-nav navbar-right">
......
......@@ -684,10 +684,13 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
an user or if the `options.all_can_create` is set.
"""
options, _created = OptionalUser.objects.get_or_create()
if options.all_can_create:
return True, None
if(not user_request.is_authenticated and not options.self_adhesion):
return False, None
else:
return user_request.has_perm('users.add_user'), u"Vous n'avez pas le\
if(options.all_can_create or options.self_adhesion):
return True, None
else:
return user_request.has_perm('users.add_user'), u"Vous n'avez pas le\
droit de créer un utilisateur"
def can_edit(self, user_request, *args, **kwargs):
......@@ -862,7 +865,7 @@ class Club(User):
"""
if user_request.has_perm('users.view_user'):
return True, None
if user_request.is_class_adherent:
if hasattr(user_request,'is_class_adherent') and user_request.is_class_adherent:
if user_request.adherent.club_administrator.all() or user_request.adherent.club_members.all():
return True, None
return False, u"Vous n'avez pas accès à la liste des utilisateurs."
......
......@@ -36,6 +36,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% massive_bootstrap_form userform 'room,school,administrators,members' %}
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
</form>
<br>
<p>En cliquant sur Créer ou modifier, l'utilisateur s'engage à respecter les <a href="/media/{{ GTU }}" download="CGU" >règles d'utilisation du réseau</a>.</p>
<h3>Résumé des règles d'utilisations</h3>
<p>{{ GTU_sum_up }}</p>
<br/>
<br/>
<br/>
......
......@@ -117,12 +117,14 @@ def password_change_action(u_form, user, request, req=False):
kwargs={'userid':str(user.id)}
))
@login_required
@can_create(Adherent)
def new_user(request):
""" Vue de création d'un nouvel utilisateur,
envoie un mail pour le mot de passe"""
user = AdherentForm(request.POST or None, user=request.user)
options, _created = GeneralOption.objects.get_or_create()
GTU_sum_up = options.GTU_sum_up
GTU = options.GTU
if user.is_valid():
user = user.save(commit=False)
with transaction.atomic(), reversion.create_revision():
......@@ -136,7 +138,7 @@ def new_user(request):
'users:profil',
kwargs={'userid':str(user.id)}
))
return form({'userform': user}, 'users/user.html', request)
return form({'userform': user,'GTU_sum_up':GTU_sum_up,'GTU':GTU}, 'users/user.html', request)
@login_required
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment