8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 11:23:10 +00:00

Implémentation de l'auto inscription

This commit is contained in:
Yoann Pétri 2018-01-14 23:47:44 +01:00 committed by root
parent a72d70e527
commit 6445a26223
11 changed files with 50 additions and 13 deletions

View file

@ -117,6 +117,7 @@ class EditGeneralOptionForm(ModelForm):
self.fields['site_name'].label = 'Nom du site web' self.fields['site_name'].label = 'Nom du site web'
self.fields['email_from'].label = "Adresse mail d\ self.fields['email_from'].label = "Adresse mail d\
'expedition automatique" 'expedition automatique"
self.fields['GTU_sum_up'].label = "Résumé des CGU"
class EditAssoOptionForm(ModelForm): class EditAssoOptionForm(ModelForm):

View file

@ -302,6 +302,16 @@ class GeneralOption(models.Model):
req_expire_hrs = models.IntegerField(default=48) req_expire_hrs = models.IntegerField(default=48)
site_name = models.CharField(max_length=32, default="Re2o") site_name = models.CharField(max_length=32, default="Re2o")
email_from = models.EmailField(default="www-data@serveur.net") 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: class Meta:
permissions = ( permissions = (

View file

@ -137,7 +137,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<tr> <tr>
<th>Message global affiché sur le site</th> <th>Message global affiché sur le site</th>
<td>{{ generaloptions.general_message }}</td> <td>{{ generaloptions.general_message }}</td>
<th>Résumé des CGU</th>
<td>{{ generaloptions.GTU_sum_up }}</td>
<tr> <tr>
<tr>
<th>CGU</th>
<td>{{generaloptions.GTU}}</th>
</tr>
</table> </table>
<h4>Données de l'association</h4> <h4>Données de l'association</h4>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'AssoOption' %}"> <a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'AssoOption' %}">

View file

@ -33,7 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<h3>Edition des préférences</h3> <h3>Edition des préférences</h3>
<form class="form" method="post"> <form class="form" method="post" enctype="multipart/form-data">
{% csrf_token %} {% csrf_token %}
{% massive_bootstrap_form options 'utilisateur_asso' %} {% massive_bootstrap_form options 'utilisateur_asso' %}
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %} {% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}

View file

@ -95,6 +95,7 @@ def edit_options(request, section):
return redirect(reverse('index')) return redirect(reverse('index'))
options = form_instance( options = form_instance(
request.POST or None, request.POST or None,
request.FILES or None,
instance=options_instance instance=options_instance
) )
if options.is_valid(): if options.is_valid():

View file

@ -45,11 +45,10 @@ def can_create(model):
def decorator(view): def decorator(view):
def wrapper(request, *args, **kwargs): def wrapper(request, *args, **kwargs):
can, msg = model.can_create(request.user, *args, **kwargs) can, msg = model.can_create(request.user, *args, **kwargs)
#options, _created = OptionalUser.objects.get_or_create()
if not can: if not can:
messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu") messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu")
return redirect(reverse('users:profil', return redirect(reverse('index'))
kwargs={'userid':str(request.user.id)}
))
return view(request, *args, **kwargs) return view(request, *args, **kwargs)
return wrapper return wrapper
return decorator return decorator

View file

@ -150,7 +150,7 @@ STATICFILES_DIRS = (
), ),
) )
MEDIA_ROOT = '/var/www/re2o/static' MEDIA_ROOT = '/var/www/re2o/media'
STATIC_URL = '/static/' STATIC_URL = '/static/'

View file

@ -26,6 +26,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{# Load the tag library #} {# Load the tag library #}
{% load bootstrap3 %} {% load bootstrap3 %}
{% load acl %} {% load acl %}
{% load self_adhesion %}
{% self_adhesion as var_sa %}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="fr"> <html lang="fr">
<head prefix="og: http://ogp.me/ns#"> <head prefix="og: http://ogp.me/ns#">
@ -102,17 +104,26 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</form> </form>
</div> </div>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li>
{% if request.user.is_authenticated %} {% if request.user.is_authenticated %}
<li>
<a href="{% url 'logout' %}"> <a href="{% url 'logout' %}">
<span class="glyphicon glyphicon-log-out"></span> Logout <span class="glyphicon glyphicon-log-out"></span> Logout
</a> </a>
</li>
{% else %} {% 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' %}"> <a href="{% url 'login' %}">
<span class="glyphicon glyphicon-log-in"></span> Login <span class="glyphicon glyphicon-log-in"></span> Login
</a> </a>
</li>
{% endif %} {% endif %}
</li>
</ul> </ul>
{% can_view_app preferences %} {% can_view_app preferences %}
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">

View file

@ -684,10 +684,13 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
an user or if the `options.all_can_create` is set. an user or if the `options.all_can_create` is set.
""" """
options, _created = OptionalUser.objects.get_or_create() options, _created = OptionalUser.objects.get_or_create()
if options.all_can_create: if(not user_request.is_authenticated and not options.self_adhesion):
return True, None return False, None
else: 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" droit de créer un utilisateur"
def can_edit(self, user_request, *args, **kwargs): def can_edit(self, user_request, *args, **kwargs):
@ -862,7 +865,7 @@ class Club(User):
""" """
if user_request.has_perm('users.view_user'): if user_request.has_perm('users.view_user'):
return True, None 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(): if user_request.adherent.club_administrator.all() or user_request.adherent.club_members.all():
return True, None return True, None
return False, u"Vous n'avez pas accès à la liste des utilisateurs." return False, u"Vous n'avez pas accès à la liste des utilisateurs."

View file

@ -36,6 +36,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% massive_bootstrap_form userform 'room,school,administrators,members' %} {% massive_bootstrap_form userform 'room,school,administrators,members' %}
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %} {% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
</form> </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/> <br/>
<br/> <br/>

View file

@ -117,12 +117,14 @@ def password_change_action(u_form, user, request, req=False):
kwargs={'userid':str(user.id)} kwargs={'userid':str(user.id)}
)) ))
@login_required
@can_create(Adherent) @can_create(Adherent)
def new_user(request): def new_user(request):
""" Vue de création d'un nouvel utilisateur, """ Vue de création d'un nouvel utilisateur,
envoie un mail pour le mot de passe""" envoie un mail pour le mot de passe"""
user = AdherentForm(request.POST or None, user=request.user) 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(): if user.is_valid():
user = user.save(commit=False) user = user.save(commit=False)
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -136,7 +138,7 @@ def new_user(request):
'users:profil', 'users:profil',
kwargs={'userid':str(user.id)} 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 @login_required