diff --git a/invenio_accounts/ext.py b/invenio_accounts/ext.py index 94596416..284681d8 100644 --- a/invenio_accounts/ext.py +++ b/invenio_accounts/ext.py @@ -25,6 +25,7 @@ confirm_register_form_factory, login_form_factory, register_form_factory, + send_confirmation_form_factory, ) from . import config @@ -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 diff --git a/invenio_accounts/forms.py b/invenio_accounts/forms.py index cb3fdef5..597121bb 100644 --- a/invenio_accounts/forms.py +++ b/invenio_accounts/forms.py @@ -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): @@ -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 diff --git a/invenio_accounts/templates/semantic-ui/invenio_accounts/send_confirmation.html b/invenio_accounts/templates/semantic-ui/invenio_accounts/send_confirmation.html index 9838ceaf..55c74860 100644 --- a/invenio_accounts/templates/semantic-ui/invenio_accounts/send_confirmation.html +++ b/invenio_accounts/templates/semantic-ui/invenio_accounts/send_confirmation.html @@ -9,55 +9,31 @@ {%- extends config.ACCOUNTS_COVER_TEMPLATE %} {% from "invenio_accounts/_macros.html" import render_field, form_errors %} -{% block page_header %} -
- {{_('Enter your email address below and we will send you an email confirmation link.')}} -
-