Commit e76a788c authored by chirac's avatar chirac
Browse files

GEstion des comptes mails

parent 5116eaf3
......@@ -12,7 +12,7 @@ https://docs.djangoproject.com/en/1.8/ref/settings/
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
from .settings_local import SECRET_KEY, DATABASES, DEBUG, ALLOWED_HOSTS, ASSO_NAME, ASSO_ADDRESS_LINE1, ASSO_ADDRESS_LINE2, ASSO_SIRET, ASSO_EMAIL, ASSO_PHONE, LOGO_PATH, services_urls, REQ_EXPIRE_HRS, REQ_EXPIRE_STR, EMAIL_FROM, SITE_NAME, UID_RANGES, LDAP
from .settings_local import SECRET_KEY, DATABASES, DEBUG, ALLOWED_HOSTS, ASSO_NAME, ASSO_ADDRESS_LINE1, ASSO_ADDRESS_LINE2, ASSO_SIRET, ASSO_EMAIL, ASSO_PHONE, LOGO_PATH, services_urls, REQ_EXPIRE_HRS, REQ_EXPIRE_STR, EMAIL_FROM, SITE_NAME, UID_RANGES, MAIL_QUOTA, LDAP
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
......
......@@ -15,6 +15,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='mailalias',
name='alias',
field=models.CharField(max_length=32, unique=True, help_text="N'indiquer que le préfixe de l'alias (@ares.fr)", validators=[users.models.mailalias_check]),
field=models.CharField(max_length=32, unique=True, help_text="N'indiquer que le préfixe de l'alias (@ares.fr)", validators=[users.models.mail_check]),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import users.models
class Migration(migrations.Migration):
dependencies = [
('users', '0007_auto_20160826_0024'),
]
operations = [
migrations.AddField(
model_name='user',
name='mail_account',
field=models.EmailField(max_length=254, unique=True, null=True),
),
migrations.AddField(
model_name='user',
name='mail_quota',
field=models.IntegerField(default=100),
),
migrations.AlterField(
model_name='mailalias',
name='alias',
field=models.CharField(max_length=32, validators=[users.models.mail_check], help_text="N'indiquer que le préfixe de l'alias (devant @ares.fr)", unique=True),
),
migrations.AlterField(
model_name='user',
name='pseudo',
field=models.CharField(max_length=32, validators=[users.models.linux_user_validator], help_text='Doit contenir uniquement des lettres, chiffres, ou tirets. ', unique=True),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0008_auto_20160827_1349'),
]
operations = [
migrations.AddField(
model_name='user',
name='mail_account_state',
field=models.BooleanField(help_text='Cocher pour activer', default=False),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import users.models
class Migration(migrations.Migration):
dependencies = [
('users', '0009_user_mail_account_state'),
]
operations = [
migrations.AlterField(
model_name='user',
name='mail_account',
field=models.CharField(help_text="N'indiquer que le préfixe de l'adresse (devant @ares.fr)", validators=[users.models.mail_check], max_length=32, blank=True, unique=True, null=True),
),
]
......@@ -8,7 +8,7 @@ from django.dispatch import receiver
import ldapdb.models
import ldapdb.models.fields
from re2o.settings import RIGHTS_LINK, REQ_EXPIRE_HRS, UID_RANGES, LDAP
from re2o.settings import RIGHTS_LINK, REQ_EXPIRE_HRS, UID_RANGES, MAIL_QUOTA, LDAP
import re, uuid
import datetime
......@@ -23,11 +23,11 @@ def linux_user_validator(login):
raise forms.ValidationError("Ce login (%s) n'est pas valide et contient des caractères interdits" % login)
return
def mailalias_check(alias):
""" Validation de l'alias mail pour respecter les contraintes"""
ALIAS_PATTERN = re.compile("^[a-z_][a-z0-9_-]*[$]?$")
if not ALIAS_PATTERN.match(alias):
raise forms.ValidationError("Cet alias n'est pas valide")
def mail_check(alias):
""" Validation des mail pour respecter les contraintes"""
PATTERN = re.compile("^[a-z0-9._-]*[$]?$")
if not PATTERN.match(alias):
raise forms.ValidationError("Cet alias ou adresse n'est pas valide")
return
def get_admin_right():
......@@ -100,6 +100,9 @@ class User(AbstractBaseUser):
state = models.IntegerField(choices=STATES, default=STATE_ACTIVE)
registered = models.DateTimeField(auto_now_add=True)
uid_number = models.IntegerField(default=auto_uid, unique=True, null=True)
mail_account_state = models.BooleanField(default=False, help_text="Cocher pour activer")
mail_account = models.CharField(max_length=32, unique=True, help_text="N'indiquer que le préfixe de l'adresse (devant @ares.fr)", validators=[mail_check], null=True, blank=True)
mail_quota = models.IntegerField(default=MAIL_QUOTA)
USERNAME_FIELD = 'pseudo'
REQUIRED_FIELDS = ['name', 'surname', 'email']
......@@ -274,7 +277,7 @@ class ListShell(models.Model):
class MailAlias(models.Model):
user = models.ForeignKey('User', on_delete=models.PROTECT)
alias = models.CharField(max_length=32, unique=True, help_text="N'indiquer que le préfixe de l'alias (devant @ares.fr)", validators=[mailalias_check])
alias = models.CharField(max_length=32, unique=True, help_text="N'indiquer que le préfixe de l'alias (devant @ares.fr)", validators=[mail_check])
redirection = models.EmailField()
def __str__(self):
......@@ -377,6 +380,28 @@ class EditInfoForm(BaseInfoForm):
'shell',
]
class BaseMailAccountForm(ModelForm):
def __init__(self, *args, **kwargs):
super(BaseMailAccountForm, self).__init__(*args, **kwargs)
self.fields['mail_account'].label = 'Compte mail'
self.fields['mail_account_state'].label = 'Etat du compte mail'
class Meta:
model = User
fields = [
'mail_account_state',
'mail_account',
]
class MailAccountForm(BaseMailAccountForm):
class Meta(BaseMailAccountForm.Meta):
fields = [
'mail_account_state',
'mail_account',
'mail_quota',
]
class UserForm(BaseInfoForm):
class Meta(BaseInfoForm.Meta):
fields = '__all__'
......
......@@ -7,6 +7,7 @@
<h2>Adhérent</h2>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:edit-info' user.id %}"><i class="glyphicon glyphicon-edit"></i> Editer</a>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:password' user.id %}"><i class="glyphicon glyphicon-lock"></i> Changer le mot de passe</a>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:mail-account' user.id %}"><i class="glyphicon glyphicon-envelope"></i> Gérer le compte mail</a>
{% if is_bureau %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:state' user.id %}"><i class="glyphicon glyphicon-flash"></i> Changer le statut</a>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:add-right' user.id %}"><i class="glyphicon glyphicon-ok"></i> Ajouter un droit</a>{% endif %}
<a class="btn btn-info btn-sm" role="button" href="{% url 'users:history' 'user' user.id %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a>
......@@ -25,15 +26,18 @@
<th>E-mail</th>
<td>{{ user.email }}</td>
</tr>
<tr>
<th>Commentaire</th>
<td>{{ user.comment }}</td>
<th>Date d'inscription</th>
<td>{{ user.registered }}</td>
</tr>
<tr>
<th>Uid</th>
<td>{{ user.uid_number }}</td>
<th>Shell</th>
<td>{{ user.shell }}</td>
</tr>
<tr>
<th>Statut</th>
{% if user.state == 0 %}
......@@ -49,6 +53,17 @@
{% else %}
<td>Aucun</td>
{% endif %}
</tr>
<tr>
<th>Compte mail</th>
{% if user.mail_account_state == True %}
<td><font color="green">Actif</font></td>
{% else %}
<td><font color="red">Désactivé</font></td>
{% endif %}
<th>Compte mail</th>
<td>{{ user.mail_account }}{% if user.mail_account %}@ares.fr{% endif %}</td>
</tr>
</table>
<h2>Alias Mail</h2>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:add-mailalias' user.id %}"><i class="glyphicon glyphicon-edit"></i> Ajouter un alias</a>
......
......@@ -5,6 +5,7 @@ from . import views
urlpatterns = [
url(r'^new_user/$', views.new_user, name='new-user'),
url(r'^edit_info/(?P<userid>[0-9]+)$', views.edit_info, name='edit-info'),
url(r'^mail_account/(?P<userid>[0-9]+)$', views.mail_account, name='mail-account'),
url(r'^state/(?P<userid>[0-9]+)$', views.state, name='state'),
url(r'^password/(?P<userid>[0-9]+)$', views.password, name='password'),
url(r'^add_right/(?P<userid>[0-9]+)$', views.add_right, name='add-right'),
......
......@@ -16,8 +16,8 @@ from django.db import transaction
from reversion import revisions as reversion
from users.models import User, Right, ListRight, Request, MailAlias
from users.models import DelRightForm, DelListRightForm, NewListRightForm, MailAliasForm
from users.models import EditInfoForm, BaseInfoForm, StateForm, RightForm, ListRightForm
from users.models import DelRightForm, DelListRightForm, NewListRightForm, MailAliasForm, MailAccountForm
from users.models import EditInfoForm, BaseInfoForm, StateForm, RightForm, ListRightForm, BaseMailAccountForm
from users.forms import PassForm, ResetPasswordForm
from re2o.login import hashNT
......@@ -106,6 +106,30 @@ def edit_info(request, userid):
return redirect("/users/profil/" + userid)
return form({'userform': user}, 'users/user.html', request)
@login_required
def mail_account(request, userid):
try:
user = User.objects.get(pk=userid)
except User.DoesNotExist:
messages.error(request, "Utilisateur inexistant")
return redirect("/users/")
if not request.user.has_perms(('bureau',)) and user != request.user:
messages.error(request, "Vous ne pouvez pas modifier un autre user que vous sans droit bureau")
return redirect("/users/profil/" + str(request.user.id))
if not request.user.has_perms(('bureau',)):
user = BaseMailAccountForm(request.POST or None, instance=user)
else:
user = MailAccountForm(request.POST or None, instance=user)
if user.is_valid():
with transaction.atomic(), reversion.create_revision():
user.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in user.changed_data))
messages.success(request, "L'user a bien été modifié")
return redirect("/users/profil/" + userid)
return form({'userform': user}, 'users/user.html', request)
@login_required
@permission_required('bureau')
def state(request, userid):
......
Supports Markdown
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