Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更换邮箱源码有问题,或者作者忘记去改源码了? #46

Open
wggglggg opened this issue Jul 2, 2021 · 0 comments
Open

更换邮箱源码有问题,或者作者忘记去改源码了? #46

wggglggg opened this issue Jul 2, 2021 · 0 comments

Comments

@wggglggg
Copy link

wggglggg commented Jul 2, 2021

我是初学者小白, 看这书有一段时间了, 消化起来有些慢, 不过好在每天都要跟着书和源码来敲代码学习.今天发现了一个问题就是更换邮箱能收到邮件, 却无法改掉数据库里的邮箱地址, 开始以为代码有问题, 再次检查源码发现了一个问题,

@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函数.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant