Skip to content

Commit

Permalink
Use better words
Browse files Browse the repository at this point in the history
  • Loading branch information
vpsx committed Apr 16, 2021
1 parent 848125b commit 09a79e3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions fence/blueprints/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@


class RegistrationForm(FlaskForm):
def EmailSometimesRequired(form, field):
# Define custom validation for email field
def xor_with_user_email(form, field):
"""
Our current registration policy is that if user.email is present from the IdP,
then use that email; otherwise ask for email at registration.
Expand All @@ -33,18 +34,21 @@ def EmailSometimesRequired(form, field):
raise ValidationError("Email field is required")
if flask.g.user.email and field.data:
raise ValidationError(
"This user is connected to the email {} and the form should "
"not have an email field".format(flask.g.user.email)
"Received unexpected 'email' field; this user is already associated with the "
"email {}, so the form should not have had an email field".format(
flask.g.user.email
)
)
if flask.g.user.email and not field.data:
# If user.email is non-empty, the form should not render an email field,
# and empty field.data is expected--all good
field.errors[:] = []
raise StopValidation()

# Define form fields
name = StringField(label="Name", validators=[DataRequired()])
organization = StringField(label="Organization", validators=[DataRequired()])
email = StringField(label="Email", validators=[EmailSometimesRequired, Email()])
email = StringField(label="Email", validators=[xor_with_user_email, Email()])


@blueprint.route("/", methods=["GET", "POST"])
Expand Down

0 comments on commit 09a79e3

Please sign in to comment.