Skip to content

Commit

Permalink
templates: refactor send confirmation template
Browse files Browse the repository at this point in the history
  • Loading branch information
zzacharo committed Aug 29, 2023
1 parent 0491c58 commit 5c239f3
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 48 deletions.
7 changes: 7 additions & 0 deletions invenio_accounts/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
confirm_register_form_factory,
login_form_factory,
register_form_factory,
send_confirmation_form_factory,
)

from . import config
Expand Down Expand Up @@ -173,6 +174,12 @@ def init_app(self, app, sessionstore=None, register_blueprint=True):
app.extensions["security"].login_form, app
)

# send confirmation form
app.extensions["security"].send_confirmation_form = \
send_confirmation_form_factory(
app.extensions["security"].send_confirmation_form, app
)

if app.config["ACCOUNTS_USE_CELERY"]:
from invenio_accounts.tasks import send_security_email

Expand Down
21 changes: 21 additions & 0 deletions invenio_accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from flask_wtf import FlaskForm, Recaptcha, RecaptchaField
from invenio_i18n import gettext as _
from wtforms import FormField, HiddenField
from invenio_accounts.proxies import current_datastore


class RegistrationFormRecaptcha(FlaskForm):
Expand Down Expand Up @@ -74,3 +75,23 @@ class LoginForm(Form):
pass

return LoginForm


def send_confirmation_form_factory(Form, app):
"""Return extended login form."""

class SendConfirmationEmailView(Form):
"""Form which sends confirmation instructions.
If user not in the system, do not raise but ignore.
The overriden behaviour exists because the endpoint is public and users can
take an insight on which emails exist in the system otherwise.
"""

def validate(self, extra_validators=None):
self.user = current_datastore.get_user(self.data["email"])
if self.user is not None and self.user.confirmed_at is None:
return True
return False

return SendConfirmationEmailView
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,31 @@
{%- extends config.ACCOUNTS_COVER_TEMPLATE %}

{% from "invenio_accounts/_macros.html" import render_field, form_errors %}
{% block page_header %}
<div class="ui two column centered grid">
<div class="row"></div>
<div class="row"></div>
<div class="column">
{%- block brand %}
{%- if config.THEME_LOGO %}
<a href="/">
<img
class="ui centered image masthead-brand"
src="{{ url_for('static', filename=config.THEME_LOGO)}}"
alt="{{ _(config.THEME_SITENAME) }}"
width="250px"
/>
</a>
{%- elif config.THEME_SITENAME %}
<a href="/" class="text-center masthead-brand">
{{ _(config.THEME_SITENAME) }}
</a>
{% endif %}
{%- endblock %}
</div>
</div>
{% endblock page_header%}

{% block page_body %}
{%- with form = send_confirmation_form %}
<div class="ui doubling three column centered grid">
<div class="row"></div>
<div class="row">
<div class="column ui middle">
<h1 class="ui header aligned center">{{config.ACCOUNTS_SITENAME}}</h1>
<div class="ui segment">
<h2 class="ui header aligned center">{{_('Resend confirmation email')}}</h2>
<div class="column ui middle">
<p class="left floated">
{{_('Enter your email address below and we will send you an email confirmation link.')}}
</p>
</div>
<form class="ui large form" action="{{ url_for_security('login') }}" method="POST" name="login_user_form">
{{form.hidden_tag()}}
{{ render_field(form.email, icon="icon user", autofocus=True, errormsg='email' in form.errors) }}
<button type="submit" class="ui fluid large submit primary button">
<i class="ui sign-in icon" aria-hidden="true"></i>{{_('Send confirmation')}}
</button>
</form>
</div>
</div>

<div class="ui padded segments big form">
<div class="ui login segment padded">
<div class="divider hidden"></div>
{%- block form_header %}
<h1 class="ui small login header">{{ _('Resend confirmation email') }}</h1>
{%- endblock form_header %}

{%- block form_outer %}
{%- with form = send_confirmation_form %}
<form action="{{ url_for_security('send_confirmation') }}" method="POST"
name="send_confirmation_form" class="ui big form">
{{ form.hidden_tag() }}
{{ render_field(form.email, icon="icon user", autofocus=True, errormsg='email' in form.errors) }}
<button type="submit" class="ui fluid large submit primary button">
<i class="ui send icon" aria-hidden="true"></i>{{ _('Send') }}
</button>
</form>
{%- endwith %}
{%- endblock form_outer %}
<div class="divider hidden"></div>
</div>

</div>
{%- endwith %}

{% endblock page_body %}
1 change: 0 additions & 1 deletion invenio_accounts/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from .settings import blueprint


@anonymous_user_required
@blueprint.route("/login")
def login(*args, **kwargs):
Expand Down

0 comments on commit 5c239f3

Please sign in to comment.