Skip to content

Commit

Permalink
Only pass relevant form fields to User.create() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcass77 committed Feb 7, 2017
1 parent f20a09b commit ffe6b0e
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions flask_stormpath/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,20 @@ def register():
data = form.data
# Attempt to create the user's account on Stormpath.
try:
# Since Stormpath requires both the given_name and surname
# fields be set, we'll just set the both to 'Anonymous' if
# the user has # explicitly said they don't want to collect
# those fields.
data['given_name'] = data['given_name'] or 'Anonymous'
data['surname'] = data['surname'] or 'Anonymous'

# Create the user account on Stormpath. If this fails, an
# exception will be raised.
account = User.create(**data)
optional_params = {k: data[k] for k in ('username','middle_name','custom_data', 'status') if k in data}
account = User.create(
data.get('email'),
data.get('password'),
# Since Stormpath requires both the given_name and surname
# fields be set, we'll just set the both to 'Anonymous' if
# the user has # explicitly said they don't want to collect
# those fields.
data.get('given_name', 'Anonymous') or 'Anonymous',
data.get('surname', 'Anonymous') or 'Anonymous',
**optional_params
)

# If we're able to successfully create the user's account,
# we'll log the user in (creating a secure session using
Expand Down

0 comments on commit ffe6b0e

Please sign in to comment.