Beispiel #1
0
def reset_password():
    email = request.form.get('email')
    user = User.query.filter_by(email=email).first()
    if not user:
        flash('邮箱不存在,请输入正确的邮箱!', 'danger')
        return redirect(url_for('.forget_pwd'))
    ver_code = generate_ver_code()
    # 将验证码设置到redis中,过期时间为10分钟
    rd.set(user.id, ver_code, ex=current_app.config['EXPIRE_TIME'])
    token = generate_token(user=user, operation=Operations.RESET_PASSWORD)
    send_reset_password_email(user=user, token=token, ver_code=ver_code)
    flash('验证邮件发送成功,请到邮箱查看然后重置密码!', 'success')
    return render_template('main/auth/pwdResetNext.html')
Beispiel #2
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        name = form.user_name.data
        pwd = form.confirm_pwd.data
        email = form.user_email.data.lower()
        user = User(username=name, email=email, password=pwd, )
        user.set_password(pwd)
        user.set_role()
        db.session.add(user)
        db.session.commit()
        token = generate_token(user, operation='confirm')
        send_confirm_email(user=user, token=token)
        flash('注册成功,欢迎加入Blogin.', 'success')
        return redirect(url_for('.login'))
    return render_template('main/register.html', form=form)
Beispiel #3
0
def resend_confirm_mail():
    user = current_user._get_current_object()
    token = generate_token(user=user, operation=Operations.CONFIRM)
    send_confirm_email(user=user, token=token)
    flash('邮箱认证邮件发送成功,请前往邮箱查看认证!', 'success')
    return redirect(request.referrer)