def register(): from .forms import RegisterForm form = RegisterForm() # 在这里,flask-wtf默认地完成了与request.form的绑定 if request.method == "GET": return render_template("account/register.html", form=form) if request.method == "POST": if form.validate_on_submit(): username = form.username.data email = form.email.data password = form.password.data user = User(username=username, email=email, password=password) user.save() user.nickname = u"友友[" + str.format("1%07d" % int(user.id)) + "]" if user.save(): if not current_app.config["IN_FAKE_TEST"]: token = generate_confirm_token(user.id, current_app.config["SECRET_KEY"]) if current_app.config["MAIL_TEST_ACCOUNT"]: print current_app.config["MAIL_TEST_ACCOUNT"] sendmail.send_email( current_app.config["MAIL_TEST_ACCOUNT"], u"请确认您的账号", "account/mail/confirm", user=user, token=token, ) flash(u"一封账号激活邮件已发送到您的邮箱,请查收邮件并完成激活.") return redirect(url_for("account.register")) return render_template("account/register.html", form=form)
def resend_confirmation(): token = generate_confirm_token(current_user.id, current_app.config["SECRET_KEY"]) if current_app.config["MAIL_TEST_ACCOUNT"]: print current_app.config["MAIL_TEST_ACCOUNT"] sendmail.send_email( current_app.config["MAIL_TEST_ACCOUNT"], u"请确认您的账号", "mail/confirm", user=current_user, token=token ) flash(u"一封新的账号激活邮件已经发送到您的邮箱。") return redirect(url_for("main.index"))