Last active
August 29, 2015 14:25
-
-
Save bq1990/5a0f037c13b312b68bcc to your computer and use it in GitHub Desktop.
Flask edit Stormpath account
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route('/account/edit', methods=['GET', 'POST']) | |
@login_required | |
def edit_account(): | |
sp = app.stormpath_manager.client | |
form = AccountForm(request.form, obj=user, | |
company_name=user.custom_data.get('company', None)) | |
if form.validate_on_submit(): | |
try: | |
_user = sp.accounts.get(user.href) | |
_user.email = form.email.data | |
_user.given_name = form.given_name.data | |
_user.surname = form.surname.data | |
_user.custom_data['company'] = form.company_name.data | |
if form.password.data: | |
_user.password = form.password.data | |
app.logger.info('password updated') | |
_user.save() | |
flash('Account updated', 'alert-success') | |
return redirect(url_for('show_account')) | |
except StormpathError as err: | |
flash(err.message.get('message'), 'alert-danger') | |
return render_template('edit_account.html', form=form) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment