def lost(): """Lost.""" form = LostPasswordForm(request.values) if form.validate_on_submit(): email = request.values['email'] try: if send_reset_password_email(email=email): flash(_('A password reset link has been sent to %(whom)s', whom=email), 'success') else: flash(_('Error happen when the email was send. ' 'Please contact the administrator.'), 'error') except AccountSecurityError as e: flash(e, 'error') return render_template('accounts/lost.html', form=form)
def test_lost_password_form_email(self): """Test LostPasswordForm email.""" from invenio.modules.accounts.forms import LostPasswordForm from invenio.base.globals import cfg cfg['CFG_ACCESS_CONTROL_LIMIT_REGISTRATION_TO_DOMAIN'] = '' form = LostPasswordForm( email="not-email", ) assert form.validate() is False form = LostPasswordForm( email="not@email", ) assert form.validate() is False form = LostPasswordForm( email="notemail", ) assert form.validate() is False form = LostPasswordForm( email="*****@*****.**", ) assert form.validate() is True form = LostPasswordForm( email="", ) assert form.validate() is False form = LostPasswordForm( email=self.email, ) assert form.validate() is True self.delete_objects([self.user]) form = LostPasswordForm( email=self.email, ) assert form.validate() is True cfg['CFG_ACCESS_CONTROL_LIMIT_REGISTRATION_TO_DOMAIN'] = 'fuu.it' form = LostPasswordForm( email="*****@*****.**", ) assert form.validate() is False email = "fuu@" + cfg['CFG_ACCESS_CONTROL_LIMIT_REGISTRATION_TO_DOMAIN'] form = LostPasswordForm( email=email, ) assert form.validate() is True