You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i found this issue as well, i add code under func named generate_token of utils.py below to resolve it.
from itsdangerous import URLSafeSerializer as Serializer
s = (
Serializer(current_app.config['SECRET_KEY']),
Serializer(current_app.config['SECRET_KEY'], expire_in)
)[expire_in is not None]
我是初学者小白, 看这书有一段时间了, 消化起来有些慢, 不过好在每天都要跟着书和源码来敲代码学习.今天发现了一个问题就是更换邮箱能收到邮件, 却无法改掉数据库里的邮箱地址, 开始以为代码有问题, 再次检查源码发现了一个问题,
@user_bp.route('/settings/change-email', methods=['GET', 'POST'])
@fresh_login_required
def change_email_request():
form = ChangeEmailForm()
if form.validate_on_submit():
token = generate_token(user=current_user, operation=Operations.CHANGE_EMAIL, new_email=form.email.data.lower())
send_confirm_email(to=form.email.data, user=current_user, token=token) <--------->问题所在
flash('Confirm email sent, check your inbox.', 'info')
return redirect(url_for('.index', username=current_user.username))
return render_template('user/settings/change_email.html', form=form)
这个还是用的注册时的发确认邮件函数, 这个send_confirm_email会导致发去邮箱的url会是 http:xxxxxxxxx/auth/confirm/tokenxxxxxxxxxxx. 点击邮箱这段地址后,是无法触发 解密token的视图函数def change_email_request():的, 我看到之前有发过isure提问题的, 作者回复源码已经改好, 可是我发现还是无法改掉数据库里的邮箱地址, 也或者作者用了其它的方法, 不过下面是我的解决方法.
我按着作者前面的email.py里的confirm函数写一个新函数来发送change email 的邮件 , 照着confirm函数抄一遍, 不过template要改一下的, template=''emails/change_email_confirm/'', 再去email文件夹下写一个 change_email_confirm.html 和 change_email_confirm.txt,这两文件照抄confirm.html 和confirm.txt, 文件中的url要改一下, url_for('user.change-email', token=token, _external=True) , 这里的user.change-email就是user.py里面的解析token的def change_email函数.
The text was updated successfully, but these errors were encountered: