From e4ad43af8a6864e0c2d036adf9ea168a2ebbfd15 Mon Sep 17 00:00:00 2001 From: Priyanshu Jha <73730939+priyanshu87694@users.noreply.github.com> Date: Tue, 16 Mar 2021 12:08:33 +0530 Subject: [PATCH] Changed the authentication by a little I tried to create a user with an email address that does not exists in the database but it showed me an error that the email already exists. It happened with any email that I tried with, then I changed the code a little bit instead of checking that the email exists or not I checked that the user exists or not. The previous code didn't worked for me. Thanks --- 12 - User Authentication Part 2/market/forms.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/12 - User Authentication Part 2/market/forms.py b/12 - User Authentication Part 2/market/forms.py index cea81ef..a46e9d6 100644 --- a/12 - User Authentication Part 2/market/forms.py +++ b/12 - User Authentication Part 2/market/forms.py @@ -9,11 +9,11 @@ def validate_username(self, username_to_check): user = User.query.filter_by(username=username_to_check.data).first() if user: raise ValidationError('Username already exists! Please try a different username') - - def validate_email_address(self, email_address_to_check): - email_address = User.query.filter_by(email_address=email_address_to_check.data).first() - if email_address: - raise ValidationError('Email Address already exists! Please try a different email address') + + def validate_email_address(self, email_to_check): + user = User.query.filter_by(email=email_to_check.data).first() + if user is not None: + raise ValidationError('Email already exists!') username = StringField(label='User Name:', validators=[Length(min=2, max=30), DataRequired()]) email_address = StringField(label='Email Address:', validators=[Email(), DataRequired()]) @@ -25,4 +25,4 @@ def validate_email_address(self, email_address_to_check): class LoginForm(FlaskForm): username = StringField(label='User Name:', validators=[DataRequired()]) password = PasswordField(label='Password:', validators=[DataRequired()]) - submit = SubmitField(label='Sign in') \ No newline at end of file + submit = SubmitField(label='Sign in')