def change_user_email(user_id): """Change a user's email.""" user = User.objects.get_or_404(id=user_id) form = ChangeUserEmailForm() if form.validate_on_submit(): user.email = form.email.data user.save() flash( 'Email for user {} successfully changed to {}.'.format( user.full_name(), user.email), 'form-success') return render_template('admin/manage_user.html', user=user, form=form)
def change_user_email(user_id): """Change a user's email.""" user = User.query.filter_by(id=user_id).first() if user is None: abort(404) form = ChangeUserEmailForm() if form.validate_on_submit(): user.email = form.email.data db.session.add(user) db.session.commit() flash('Email for user {} successfully changed to {}.'.format( user.full_name, user.email), 'form-success') return render_template('admin/manage_user.html', user=user, form=form)