Flask-user ResendEmailConfirmationForm form class does not validate the user email (https://github.com/lingthio/Flask-User/blob/master/flask_user/forms.py) as does other class forms such as ForgotPasswordForm, which incorporates the following validation method:
def validate_email(form, field):
user_manager = current_app.user_manager
if user_manager.USER_SHOW_EMAIL_DOES_NOT_EXIST:
user, user_email = user_manager.db_manager.get_user_and_user_email_by_email(field.data)
if not user:
raise ValidationError(_('%(username_or_email)s does not exist', username_or_email=_('Email')))
I want to add this validation snippet to the ResendEmailConfirmationForm using the customization method they have in their docs (https://flask-user.readthedocs.io/en/latest/customizing_forms.html#customizingformvalidators):
In the forms.py file, I added the following:
from flask_user.forms import ResendEmailConfirmationForm
from flask import current_app
from flask_user import UserManager
from wtforms import ValidationError
class CustomResendEmailConfirmationForm(ResendEmailConfirmationForm):
def validate_email(form, field):
user_manager = current_app.user_manager
user, user_email = user_manager.db_manager.get_user_and_user_email_by_email(field.data)
print(user, user_email)
if not user:
raise ValidationError(_('%(email)s does not exist', email=_('Email')))
class CustomUserManager(UserManager):
def customize(self, app):
# Configure customized forms
self.ResendEmailConfirmationForm = CustomResendEmailConfirmationForm
In the init.py file, I replaced:
user_manager = UserManager(app, db, User)
with
from um_project.forms import CustomUserManager
....
user_manager = CustomUserManager(app, db, User)
But for some reason, the new validation method is not being inherited. I don't know what I am missing. Can someone help me figure it out? thank you!