def change_email_request(): """Respond to existing user's request to change their email.""" form = ChangeEmailForm() if form.validate_on_submit(): if current_user.verify_password(form.password.data): new_email = form.email.data token = current_user.generate_email_change_token(new_email) change_email_link = url_for('account.change_email', token=token, _external=True) get_queue().enqueue( send_email, recipient=new_email, subject='Confirm Your New Email', template='account/email/change_email', # current_user is a LocalProxy, we want the underlying user # object user=current_user._get_current_object(), change_email_link=change_email_link) flash('A confirmation link has been sent to {}.'.format(new_email), 'warning') return redirect(url_for('main.index')) else: flash('Invalid email or password.', 'form-error') return render_template('account/manage.html', user=current_user, form=form)
def change_email_request(): """Respond to existing user's request to change their email.""" form = ChangeEmailForm() if form.validate_on_submit(): if current_user.verify_password(form.password.data): new_email = form.email.data token = current_user.generate_email_change_token(new_email) change_email_link = url_for("account.change_email", token=token, _external=True) user = current_user._get_current_object() user.__dict__.pop("storage_files") get_queue().enqueue( send_email, recipient=new_email, subject="Confirm Your New Email", template="account/email/change_email", # current_user is a LocalProxy, we want the underlying user # object user=user, change_email_link=change_email_link, ) flash("A confirmation link has been sent to {}.".format(new_email), "warning") return redirect(url_for("main.index")) else: flash("Invalid email or password.", "form-error") return render_template("account/manage.html", form=form)
def change_email_request(): """Respond to existing user's request to change their email.""" form = ChangeEmailForm() if form.validate_on_submit(): if current_user.verify_password(form.password.data): user_id = current_user.id user = User.query.filter_by(id=user_id).first() 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 redirect(url_for('account.manage')) else: flash('Invalid email or password.', 'form-error') return render_template('account/manage.html', form=form)