invitation: display the invitation link even if the mail could not be sent

This commit is contained in:
Éloi Rivard 2021-12-07 18:32:37 +01:00
parent c8f33cd77a
commit 694a5bacc8
2 changed files with 26 additions and 8 deletions

View file

@ -155,9 +155,11 @@ def users(user):
def user_invitation(user): def user_invitation(user):
form = InvitationForm(request.form or None) form = InvitationForm(request.form or None)
success = False mail_sent = None
registration_url = None registration_url = None
form_validated = False
if request.form and form.validate(): if request.form and form.validate():
form_validated = True
registration_url = url_for( registration_url = url_for(
"account.registration", "account.registration",
data=obj_to_b64([form.uid.data, form.mail.data, form.groups.data]), data=obj_to_b64([form.uid.data, form.mail.data, form.groups.data]),
@ -165,15 +167,14 @@ def user_invitation(user):
_external=True, _external=True,
) )
success = send_invitation_mail(form.mail.data, registration_url) mail_sent = send_invitation_mail(form.mail.data, registration_url)
if not success:
flash(_("An error happened whilen sending the invitation link."), "error")
return render_template( return render_template(
"invite.html", "invite.html",
form=form, form=form,
menuitems="users", menuitems="users",
success=success, form_validated=form_validated,
mail_sent=mail_sent,
registration_url=registration_url, registration_url=registration_url,
) )

View file

@ -7,22 +7,37 @@
{% block content %} {% block content %}
<div class="invitationform"> <div class="invitationform">
{% if success %} {% if form_validated %}
<div class="ui attached segment"> <div class="ui attached segment">
<h2 class="ui center aligned header"> <h2 class="ui center aligned header">
<div class="content"> <div class="content">
{% if mail_sent %}
{{ _("Invitation sent") }} {{ _("Invitation sent") }}
{% else %}
{{ _("Invitation not sent") }}
{% endif %}
</div> </div>
</h2> </h2>
</div> </div>
{% if mail_sent %}
<div class="ui attached success message"> <div class="ui attached success message">
{% set email = form.mail.data %} {% set email = form.mail.data %}
{% trans %}This invitation link has been to {{ email }}{% endtrans %} {% trans %}This invitation link has been sent to {{ email }}{% endtrans %}
{% trans %}If you need to provide this link by other ways than email, you can copy it there:{% endtrans %} {% trans %}If you need to provide this link by other ways than email, you can copy it there:{% endtrans %}
</div> </div>
{% else %}
<div class="ui attached error message">
{% set email = form.mail.data %}
{% trans %}This invitation link could not be sent to {{ email }} due to technical issues.{% endtrans %}
{% trans %}However you can copy the there to provide it by other ways than email:{% endtrans %}
</div>
{% endif %}
<div class="ui attached segment"> <div class="ui attached segment">
<div class="ui center aligned container"> <div class="ui center aligned container">
<div class="ui fields"> <div class="ui fields">
@ -39,9 +54,11 @@
<a class="ui right floated button" href="{{ url_for("account.profile_creation") }}"> <a class="ui right floated button" href="{{ url_for("account.profile_creation") }}">
{{ _("Create a user") }} {{ _("Create a user") }}
</a> </a>
{% if mail_sent %}
<a href="{{ url_for('account.user_invitation') }}" class="ui right floated button" name="action" value="invite" id="invite"> <a href="{{ url_for('account.user_invitation') }}" class="ui right floated button" name="action" value="invite" id="invite">
{{ _("Invite another user") }} {{ _("Invite another user") }}
</a> </a>
{% endif %}
</div> </div>
</div> </div>
</div> </div>