mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-23 23:43:47 +00:00
Mise en place du mail et la view pour valider
This commit is contained in:
parent
7983b6214a
commit
dd672b5cdb
2 changed files with 43 additions and 1 deletions
|
@ -232,7 +232,6 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
|||
blank=True,
|
||||
null = True
|
||||
)
|
||||
verification_uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
|
||||
USERNAME_FIELD = 'pseudo'
|
||||
REQUIRED_FIELDS = ['surname', 'email']
|
||||
|
@ -590,6 +589,36 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
|||
)
|
||||
return
|
||||
|
||||
def send_verification_mail(self, request):
|
||||
""" Prend en argument un request, envoie un mail de
|
||||
vérification"""
|
||||
req = Request()
|
||||
req.type = Request.EMAIL
|
||||
req.user = self
|
||||
req.save()
|
||||
template = loader.get_template('users/email_verification_request')
|
||||
context = {
|
||||
'name': req.user.get_full_name(),
|
||||
'asso': AssoOption.get_cached_value('name'),
|
||||
'asso_mail': AssoOption.get_cached_value('contact'),
|
||||
'site_name': GeneralOption.get_cached_value('site_name'),
|
||||
'url': request.build_absolute_uri(
|
||||
reverse('users:process', kwargs={'token': req.token})
|
||||
),
|
||||
'expire_in': str(
|
||||
GeneralOption.get_cached_value('req_expire_hrs')
|
||||
) + ' heures',
|
||||
}
|
||||
send_mail(
|
||||
'Changement du compte de %(name)s / Account verification for '
|
||||
'%(name)s' % {'name': AssoOption.get_cached_value('name')},
|
||||
template.render(context),
|
||||
GeneralOption.get_cached_value('email_from'),
|
||||
[req.user.email],
|
||||
fail_silently=False
|
||||
)
|
||||
return
|
||||
|
||||
def reset_passwd_mail(self, request):
|
||||
""" Prend en argument un request, envoie un mail de
|
||||
réinitialisation de mot de pass """
|
||||
|
|
|
@ -113,6 +113,11 @@ def new_user(request):
|
|||
if user.is_valid():
|
||||
password = user.cleaned_data['password2']
|
||||
user = user.save(commit=False)
|
||||
if(OptionalUser.get_cached_value('mail_verification'):
|
||||
user.send_verification_mail(request)
|
||||
messages.warning(request, "Un mail pour vérifier l'adresse a été envoyé")
|
||||
if(OptionalUser.get_cached_value('verification_time')>0):
|
||||
user.verification_deadline = datetime.datetime.now() + datetime.timedelta(hours=OptionalUser.get_cached_value('verification_time'))
|
||||
user.save()
|
||||
if(password != ""):
|
||||
user.set_password(password)
|
||||
|
@ -953,7 +958,15 @@ def process(request, token):
|
|||
req = get_object_or_404(valid_reqs, token=token)
|
||||
|
||||
if req.type == Request.PASSWD:
|
||||
user = req.user
|
||||
user.mail_verification = True
|
||||
user.save()
|
||||
return process_passwd(request, req)
|
||||
elif req.type == Request.EMAIL:
|
||||
user = req.user
|
||||
user.mail_verification = True
|
||||
user.save()
|
||||
return redirect(reverse('login'))
|
||||
else:
|
||||
messages.error(request, "Entrée incorrecte, contactez un admin")
|
||||
redirect(reverse('index'))
|
||||
|
|
Loading…
Reference in a new issue