Exemplo n.º 1
0
def confirm_email(token):
    success = 'You have replaced your password successfully!'
    failed = 'The confirmation link is invalid or has expired.'
    url_f = url_for('web.getback')
    url_s = url_for('web.login')
    form = ReplacePasswdForm()
    try:
        email = verify_email_token(token)
        if email is None:
            return render_template("web/failed.html", failed=failed, url=url_f)
    except:
        return render_template("web/falied.html", failed=failed, url=url_f)

    if request.method == 'GET':
        return render_template('web/auth/update_password.html', form=form)

    if form.validate_on_submit():
        password = form.password.data
        password_again = form.password_again.data
        try:
            user = UserService.get_userinfo_by_email(email['email'])
            user.password = password_again
            UserService.update_userpasswd_by_confirm(user)
            flash(u"您的密码已经成功更新,请登录")
            return redirect(url_for('web.logout'))
        except:
            flash(u"您的密码更新失败,请重试")
            return redirect(url_for('web.confirm_email', token=token))

    return render_template('web/auth/update_password.html', form=form)
Exemplo n.º 2
0
def getback():
    form = GetbackPwdForm()

    if request.method == 'GET':
        return render_template('web/auth/forgotpwd.html', form=form)

    if form.validate_on_submit():
        username = form.username.data
        email = form.email.data
        user = UserService.get_userinfo_by_email(email)
        if user is None or username != user.user_name:
            flash(u'您的用户名和邮箱不匹配,请确认后重新输入')
            return redirect(url_for('web.getback'))

        token = generate_email_token(email)
        confirm_url = url_for('web.confirm_email', token=token, external=True)
        html = 'Please click url to finishing confirm. After, you can replace your password.<br>' + confirm_url
        sender = '*****@*****.**'
        subject = 'OnlineTest Confirm Email'
        try:
            send_email(subject, sender, email, html)
            flash('Your confirm email send successful! :)', 'success')
        except:
            flash('Your confirm email send failed :(', 'danger')

        return redirect(url_for('web.getback'))
    return render_template('web/auth/forgotpwd.html', form=form)