mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-25 22:22:26 +00:00
Fix handling of confirmation email for front facing elements
This commit is contained in:
parent
b91efa3d29
commit
5e2e609474
4 changed files with 49 additions and 49 deletions
|
@ -368,6 +368,8 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
||||||
label=_("Force the move?"), initial=False, required=False
|
label=_("Force the move?"), initial=False, required=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
should_send_confirmation_email = False
|
||||||
|
|
||||||
def clean_email(self):
|
def clean_email(self):
|
||||||
if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get(
|
if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get(
|
||||||
"email"
|
"email"
|
||||||
|
@ -398,18 +400,19 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
"""On met à jour l'état de l'utilisateur en fonction de son mail"""
|
"""On met à jour l'état de l'utilisateur en fonction de son mail"""
|
||||||
user = super(AdherentForm, self).save(commit=False)
|
user = super(AdherentForm, self).save(commit=commit)
|
||||||
|
|
||||||
if user.email != self.initial["email"]:
|
if user.email != self.initial["email"]:
|
||||||
# Send a confirmation email
|
# Send a confirmation email
|
||||||
if user.state in [User.STATE_ACTIVE, User.STATE_DISABLED, User.STATE_NOT_YET_ACTIVE, User.STATE_EMAIL_NOT_YET_CONFIRMED]:
|
if user.state in [User.STATE_ACTIVE, User.STATE_DISABLED, User.STATE_NOT_YET_ACTIVE, User.STATE_EMAIL_NOT_YET_CONFIRMED]:
|
||||||
user.state = User.STATE_EMAIL_NOT_YET_CONFIRMED
|
user.state = User.STATE_EMAIL_NOT_YET_CONFIRMED
|
||||||
user.confirm_email_address_mail()
|
self.should_send_confirmation_email = True
|
||||||
|
|
||||||
# Always keep the oldest change date
|
# Always keep the oldest change date
|
||||||
if user.email_change_date is None:
|
if user.email_change_date is None:
|
||||||
user.email_change_date = timezone.now()
|
user.email_change_date = timezone.now()
|
||||||
|
|
||||||
|
user.save()
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -226,7 +226,7 @@ class User(
|
||||||
shortcuts_enabled = models.BooleanField(
|
shortcuts_enabled = models.BooleanField(
|
||||||
verbose_name=_("enable shortcuts on Re2o website"), default=True
|
verbose_name=_("enable shortcuts on Re2o website"), default=True
|
||||||
)
|
)
|
||||||
email_change_date = None
|
email_change_date = models.DateTimeField(default=None, null=True)
|
||||||
|
|
||||||
USERNAME_FIELD = "pseudo"
|
USERNAME_FIELD = "pseudo"
|
||||||
REQUIRED_FIELDS = ["surname", "email"]
|
REQUIRED_FIELDS = ["surname", "email"]
|
||||||
|
@ -795,6 +795,7 @@ class User(
|
||||||
req.type = Request.EMAIL
|
req.type = Request.EMAIL
|
||||||
req.user = self
|
req.user = self
|
||||||
req.save()
|
req.save()
|
||||||
|
|
||||||
template = loader.get_template("users/email_confirmation_request")
|
template = loader.get_template("users/email_confirmation_request")
|
||||||
context = {
|
context = {
|
||||||
"name": req.user.get_full_name(),
|
"name": req.user.get_full_name(),
|
||||||
|
|
|
@ -39,35 +39,23 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="dashboard_container">
|
|
||||||
{% if users.state == Users.STATE_NOT_YET_ACTIVE %}
|
{% if users.state == users.STATE_EMAIL_NOT_YET_CONFIRMED %}
|
||||||
<h2>{% blocktrans with name=users.name surname=users.surname %}Welcome {{ name }} {{ surname }}{% endblocktrans %}</h2>
|
<div class="alert alert-warning">
|
||||||
{% else %}
|
{% blocktrans %}Please confirm your email address.{% endblocktrans %}
|
||||||
<h2>{% blocktrans with name=users.name surname=users.surname %}Profile of {{ name }} {{ surname }}{% endblocktrans %}</h2>
|
<br/>
|
||||||
{% endif %}
|
<a href="{% url 'users:resend-confirmation-email' users.id %}">
|
||||||
|
{% blocktrans %}Didn't receive the email?{% endblocktrans %}
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
{% elif users.state == users.STATE_DISABLED %}
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
{% blocktrans %}Your account has been disabled{% endblocktrans %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
<div class="dashboard_container">
|
<div class="dashboard_container">
|
||||||
{% if users.state == Users.STATE_NOT_YET_ACTIVE %}
|
|
||||||
<div class="row">
|
|
||||||
<div class="alert alert-warning">
|
|
||||||
{% blocktrans %}Please confirm your email address{% endblocktrans %}
|
|
||||||
<br/>
|
|
||||||
<a href="{% url 'users:resend-confirmation-email' users.id %}">
|
|
||||||
{% blocktrans %}Resend the email{% endblocktrans %}
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% elif users.state == Users.STATE_DISABLED %}
|
|
||||||
<div class="row">
|
|
||||||
<div class="alert alert-danger">
|
|
||||||
{% blocktrans %}Your account has been disabled{% endblocktrans %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-6 {% if solde_activated %}col-md-4{% else %}col_md-6{% endif %}">
|
<div class="col-sm-6 {% if solde_activated %}col-md-4{% else %}col_md-6{% endif %}">
|
||||||
{% if users.is_ban%}
|
{% if users.is_ban%}
|
||||||
|
@ -210,7 +198,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<dt>{% trans "Email address" %}</dt>
|
<dt>{% trans "Email address" %}</dt>
|
||||||
<dd><a href="mailto:{{ users.email }}">{{ users.email }}</a>{% if users.email_change_date is not None %}<i class="text-danger">{% trans "Pending confirmation..." %}</i>{% endif %}</dd>
|
<dd><a href="mailto:{{ users.email }}">{{ users.email }}</a>{% if users.email_change_date is not None %}<br/><i class="text-warning">{% trans "Pending confirmation..." %}</i>{% endif %}</dd>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
|
|
|
@ -223,8 +223,13 @@ def edit_info(request, user, userid):
|
||||||
)
|
)
|
||||||
if user_form.is_valid():
|
if user_form.is_valid():
|
||||||
if user_form.changed_data:
|
if user_form.changed_data:
|
||||||
user_form.save()
|
user = user_form.save()
|
||||||
messages.success(request, _("The user was edited."))
|
messages.success(request, _("The user was edited."))
|
||||||
|
|
||||||
|
if user_form.should_send_confirmation_email:
|
||||||
|
user.confirm_email_address_mail(request)
|
||||||
|
messages.warning(request, _("Sent a new confirmation email"))
|
||||||
|
|
||||||
return redirect(reverse("users:profil", kwargs={"userid": str(userid)}))
|
return redirect(reverse("users:profil", kwargs={"userid": str(userid)}))
|
||||||
return form(
|
return form(
|
||||||
{"userform": user_form, "action_name": _("Edit")},
|
{"userform": user_form, "action_name": _("Edit")},
|
||||||
|
@ -994,12 +999,15 @@ def reset_password(request):
|
||||||
|
|
||||||
|
|
||||||
def process(request, token):
|
def process(request, token):
|
||||||
"""Process, lien pour la reinitialisation du mot de passe"""
|
"""Process, lien pour la reinitialisation du mot de passe
|
||||||
|
et la confirmation de l'email"""
|
||||||
valid_reqs = Request.objects.filter(expires_at__gt=timezone.now())
|
valid_reqs = Request.objects.filter(expires_at__gt=timezone.now())
|
||||||
req = get_object_or_404(valid_reqs, token=token)
|
req = get_object_or_404(valid_reqs, token=token)
|
||||||
|
|
||||||
if req.type == Request.PASSWD:
|
if req.type == Request.PASSWD:
|
||||||
return process_passwd(request, req)
|
return process_passwd(request, req)
|
||||||
|
elif req.type == Request.EMAIL:
|
||||||
|
return process_email(request, req)
|
||||||
else:
|
else:
|
||||||
messages.error(request, _("Error: please contact an admin."))
|
messages.error(request, _("Error: please contact an admin."))
|
||||||
redirect(reverse("index"))
|
redirect(reverse("index"))
|
||||||
|
@ -1024,31 +1032,31 @@ def process_passwd(request, req):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def resend_confirmation_email(request):
|
def resend_confirmation_email(request, userid):
|
||||||
""" Renvoie du mail de confirmation """
|
""" Renvoie du mail de confirmation """
|
||||||
userform = ResendConfirmationEmailForm(request.POST or None)
|
userform = ResendConfirmationEmailForm(request.POST or None)
|
||||||
if userform.is_valid():
|
if userform.is_valid():
|
||||||
request.user.confirm_email_address_mail()
|
try:
|
||||||
|
user = User.objects.get(
|
||||||
|
id=userid,
|
||||||
|
state__in=[User.STATE_EMAIL_NOT_YET_CONFIRMED],
|
||||||
|
)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
messages.error(request, _("The user doesn't exist."))
|
||||||
|
return form(
|
||||||
|
{"userform": userform, "action_name": _("Reset")},
|
||||||
|
"users/user.html",
|
||||||
|
request,
|
||||||
|
)
|
||||||
|
user.confirm_email_address_mail(request)
|
||||||
messages.success(request, _("An email to confirm your address was sent."))
|
messages.success(request, _("An email to confirm your address was sent."))
|
||||||
return redirect(reverse("index"))
|
return redirect(reverse("users:profil", kwargs={"userid": userid}))
|
||||||
|
|
||||||
return form(
|
return form(
|
||||||
{"userform": userform, "action_name": _("Send")}, "users/user.html", request
|
{"userform": userform, "action_name": _("Send")}, "users/user.html", request
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def confirm_email(request, token):
|
|
||||||
"""Lien pour la confirmation de l'email"""
|
|
||||||
valid_reqs = Request.objects.filter(expires_at__gt=timezone.now())
|
|
||||||
req = get_object_or_404(valid_reqs, token=token)
|
|
||||||
|
|
||||||
if req.type == Request.EMAIL:
|
|
||||||
return process_email(request, req)
|
|
||||||
else:
|
|
||||||
messages.error(request, _("Error: please contact an admin."))
|
|
||||||
redirect(reverse("index"))
|
|
||||||
|
|
||||||
|
|
||||||
def process_email(request, req):
|
def process_email(request, req):
|
||||||
"""Process la confirmation de mail, renvoie le formulaire
|
"""Process la confirmation de mail, renvoie le formulaire
|
||||||
de validation"""
|
de validation"""
|
||||||
|
|
Loading…
Reference in a new issue