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

Reglages nom du site et emailfrom dans preferences

This commit is contained in:
Gabriel Detraz 2017-08-26 16:04:51 +02:00 committed by root
parent 0719e89a8b
commit 7aa69ab60f
11 changed files with 107 additions and 29 deletions

View file

@ -33,8 +33,6 @@ import re
from reversion import revisions as reversion
from datetime import timedelta
from re2o.settings import MAIN_EXTENSION
class Machine(models.Model):
""" Class définissant une machine, object parent user, objets fils interfaces"""

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-08-26 13:30
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('preferences', '0011_auto_20170825_2307'),
]
operations = [
migrations.AddField(
model_name='generaloption',
name='req_expire_hrs',
field=models.IntegerField(default=48),
),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-08-26 13:40
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('preferences', '0012_generaloption_req_expire_hrs'),
]
operations = [
migrations.AddField(
model_name='generaloption',
name='site_name',
field=models.CharField(default='Re2o', max_length=32),
),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-08-26 13:58
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('preferences', '0013_generaloption_site_name'),
]
operations = [
migrations.AddField(
model_name='generaloption',
name='email_from',
field=models.EmailField(default='www-data@serveur.net', max_length=254),
),
]

View file

@ -56,6 +56,9 @@ class GeneralOption(models.Model):
search_display_page = models.IntegerField(default=15)
pagination_number = models.IntegerField(default=25)
pagination_large_number = models.IntegerField(default=8)
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")
class Service(models.Model):
name = models.CharField(max_length=32)

View file

@ -97,6 +97,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<p>
</p>
<table class="table table-striped">
<tr>
<th>Nom du site web</th>
<td>{{ generaloptions.site_name }}</td>
<th>Adresse mail d'expedition automatique</th>
<td>{{ generaloptions.email_from }}</td>
</tr>
<tr>
<th>Affichage de résultats dans le champ de recherche</th>
<td>{{ generaloptions.search_display_page }}</td>
@ -106,6 +112,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<tr>
<th>Nombre d'items affichés en liste (taille élevée)</th>
<td>{{ generaloptions.pagination_large_number }}</td>
<th>Temps avant expiration du lien de reinitialisation de mot de passe (en heures)</th>
<td>{{ generaloptions.req_expire_hrs }}</td>
</tr>
</table>
<h4>Données de l'association</h4>

View file

@ -21,9 +21,10 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from machines.models import Interface, Machine
from .settings import SITE_NAME
from preferences.models import GeneralOption
def context_user(request):
general_options, created = GeneralOption.objects.get_or_create()
user = request.user
if user.is_authenticated():
interfaces = user.user_interfaces()
@ -50,5 +51,5 @@ def context_user(request):
'is_infra': is_infra,
'is_admin' : is_admin,
'interfaces': interfaces,
'site_name': SITE_NAME,
'site_name': general_options.site_name,
}

View file

@ -59,23 +59,8 @@ CSRF_COOKIE_HTTPONLY = True
X_FRAME_OPTIONS = 'DENY'
SESSION_COOKIE_AGE = 60 * 60 * 3
# Association information
SITE_NAME = "Re2o.rez"
# Main extension used in asso
MAIN_EXTENSION = ".rez"
LOGO_PATH = "static_files/logo.png"
# Number of hours a token remains valid after having been created. Numeric and string
# versions should have the same meaning.
REQ_EXPIRE_HRS = 48
REQ_EXPIRE_STR = '48 heures'
# Email `From` field
EMAIL_FROM = 'www-data@serveur.net'
EMAIL_HOST = 'smtp.example.org'
# Reglages pour la bdd ldap

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-08-26 13:30
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('topologie', '0022_auto_20161211_1622'),
]
operations = [
migrations.AlterField(
model_name='port',
name='radius',
field=models.CharField(choices=[('NO', 'NO'), ('STRICT', 'STRICT'), ('BLOQ', 'BLOQ'), ('COMMON', 'COMMON'), ('3', '3'), ('7', '7'), ('8', '8'), ('13', '13'), ('20', '20'), ('42', '42'), ('69', '69')], default='NO', max_length=32),
),
]

View file

@ -33,7 +33,7 @@ from django.db import transaction
import ldapdb.models
import ldapdb.models.fields
from re2o.settings import RIGHTS_LINK, REQ_EXPIRE_HRS, LDAP, GID_RANGES,UID_RANGES
from re2o.settings import RIGHTS_LINK, LDAP, GID_RANGES,UID_RANGES
import re, uuid
import datetime
@ -44,7 +44,7 @@ from django.core.validators import MinLengthValidator
from topologie.models import Room
from cotisations.models import Cotisation, Facture, Paiement, Vente
from machines.models import Interface, Machine
from preferences.models import OptionalUser
from preferences.models import GeneralOption, OptionalUser
now = timezone.now()
@ -622,8 +622,9 @@ class Request(models.Model):
def save(self):
if not self.expires_at:
options, created = GeneralOption.objects.get_or_create()
self.expires_at = timezone.now() \
+ datetime.timedelta(hours=REQ_EXPIRE_HRS)
+ datetime.timedelta(hours=options.req_expire_hrs)
if not self.token:
self.token = str(uuid.uuid4()).replace('-', '') # remove hyphens
super(Request, self).save()

View file

@ -47,7 +47,6 @@ from users.forms import MassArchiveForm, PassForm, ResetPasswordForm
from preferences.models import OptionalUser, AssoOption, GeneralOption
from re2o.login import hashNT
from re2o.settings import REQ_EXPIRE_STR, EMAIL_FROM, SITE_NAME
def form(ctx, template, request):
@ -75,20 +74,22 @@ def reset_passwd_mail(req, request):
""" Prend en argument un request, envoie un mail de réinitialisation de mot de pass """
t = loader.get_template('users/email_passwd_request')
options, created = AssoOption.objects.get_or_create()
general_options, created = GeneralOption.objects.get_or_create()
c = {
'name': str(req.user.name) + ' ' + str(req.user.surname),
'asso': options.name,
'asso_mail': options.contact,
'site_name': SITE_NAME,
'site_name': general_options.site_name,
'url': request.build_absolute_uri(
reverse('users:process', kwargs={'token': req.token})),
'expire_in': REQ_EXPIRE_STR,
'expire_in': str(general_options.req_expire_hrs) + ' heures',
}
send_mail('Changement de mot de passe du Rézo Metz / Password renewal for Rézo Metz', t.render(c),
EMAIL_FROM, [req.user.email], fail_silently=False)
general_options.email_from, [req.user.email], fail_silently=False)
return
def notif_ban(ban):
general_options, created = GeneralOption.objects.get_or_create()
""" Prend en argument un objet ban, envoie un mail de notification """
t = loader.get_template('users/email_ban_notif')
c = Context({
@ -97,13 +98,14 @@ def notif_ban(ban):
'date_end': ban.date_end,
})
send_mail('Deconnexion disciplinaire', t.render(c),
EMAIL_FROM, [ban.user.email], fail_silently=False)
general_options.email_from, [ban.user.email], fail_silently=False)
return
def notif_inscription(user):
""" Prend en argument un objet user, envoie un mail de bienvenue """
t = loader.get_template('users/email_welcome')
options, created = AssoOption.objects.get_or_create()
general_options, created = GeneralOption.objects.get_or_create()
c = Context({
'nom': str(user.name) + ' ' + str(user.surname),
'asso_name': options.name,
@ -111,7 +113,7 @@ def notif_inscription(user):
'pseudo':user.pseudo,
})
send_mail('Bienvenue au Rézo / Welcome to Rézo Metz', '',
EMAIL_FROM, [user.email], html_message=t.render(c))
general_options.email_from, [user.email], html_message=t.render(c))
return