8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-29 08:02:24 +00:00

Correction de bugs et ajout d'un message

This commit is contained in:
Yoann Pétri 2018-07-17 18:31:27 +02:00 committed by root
parent badc111491
commit faf6e4fc93
2 changed files with 12 additions and 6 deletions

View file

@ -48,6 +48,7 @@ from __future__ import unicode_literals
import re import re
import uuid import uuid
import datetime import datetime
from pytz import timezone
from django.db import models from django.db import models
from django.db.models import Q from django.db.models import Q
@ -414,7 +415,8 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
def has_access(self): def has_access(self):
""" Renvoie si un utilisateur a accès à internet """ """ Renvoie si un utilisateur a accès à internet """
if(OptionalUser.get_cached_value('mail_verification') and not self.verified and self.verification_deadline is not None and datetime.datetime.now() > self.verification_deadline): now = datetime.datetime.now(datetime.timezone.utc)
if(OptionalUser.get_cached_value('mail_verification') and not self.verified and self.verification_deadline is not None and now > self.verification_deadline):
verified = False verified = False
else: else:
verified = True verified = True
@ -589,7 +591,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
) )
return return
def send_verification_mail(self, request): def send_verification_mail(self, request):
""" Prend en argument un request, envoie un mail de """ Prend en argument un request, envoie un mail de
vérification""" vérification"""
req = Request() req = Request()
@ -610,7 +612,7 @@ def send_verification_mail(self, request):
) + ' heures', ) + ' heures',
} }
send_mail( send_mail(
'Changement du compte de %(name)s / Account verification for ' 'Vérification du compte de %(name)s / Account verification for '
'%(name)s' % {'name': AssoOption.get_cached_value('name')}, '%(name)s' % {'name': AssoOption.get_cached_value('name')},
template.render(context), template.render(context),
GeneralOption.get_cached_value('email_from'), GeneralOption.get_cached_value('email_from'),
@ -653,7 +655,7 @@ def send_verification_mail(self, request):
def verification_message(self): def verification_message(self):
if(OptionalUser.get_cached_value('mail_verification') and not self.verified): if(OptionalUser.get_cached_value('mail_verification') and not self.verified):
if(self.verification_deadline is not None): if(self.verification_deadline is not None):
message = 'Votre adresse mail n\'est pas vérifiée. Si vous ne vérifiez pas votre adresse mail, toute connexion sera intérrompu le ' + self.verification_deadline message = 'Votre adresse mail n\'est pas vérifiée. Si vous ne vérifiez pas votre adresse mail, toute connexion sera intérrompu le ' + str(self.verification_deadline)
else: else:
message = 'Votre adresse mail n\'est pas vérifiée.' message = 'Votre adresse mail n\'est pas vérifiée.'
return message return message

View file

@ -34,6 +34,7 @@ des whitelist, des services users et des écoles
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
import datetime
from django.urls import reverse from django.urls import reverse
from django.shortcuts import get_object_or_404, render, redirect from django.shortcuts import get_object_or_404, render, redirect
@ -113,7 +114,8 @@ def new_user(request):
if user.is_valid(): if user.is_valid():
password = user.cleaned_data['password2'] password = user.cleaned_data['password2']
user = user.save(commit=False) user = user.save(commit=False)
if(OptionalUser.get_cached_value('mail_verification'): user.save()
if(OptionalUser.get_cached_value('mail_verification')):
user.send_verification_mail(request) user.send_verification_mail(request)
messages.warning(request, "Un mail pour vérifier l'adresse a été envoyé") messages.warning(request, "Un mail pour vérifier l'adresse a été envoyé")
if(OptionalUser.get_cached_value('verification_time')>0): if(OptionalUser.get_cached_value('verification_time')>0):
@ -961,11 +963,13 @@ def process(request, token):
user = req.user user = req.user
user.verified = True user.verified = True
user.save() user.save()
messages.success(request, "Le compte a bien été vérifié")
return process_passwd(request, req) return process_passwd(request, req)
elif req.type == Request.EMAIL: elif req.type == Request.EMAIL:
user = req.user user = req.user
user.verified= True user.verified= True
user.save() user.save()
messages.success(request, "Le compte a bien été vérifié")
return redirect(reverse('login')) return redirect(reverse('login'))
else: else:
messages.error(request, "Entrée incorrecte, contactez un admin") messages.error(request, "Entrée incorrecte, contactez un admin")