예제 #1
0
파일: demo.py 프로젝트: juxiaoqigong/PyCode
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
        flash('Check your email for the instructions to reset your password')
        return redirect(url_for('login'))
    return render_template('reset_password_request.html',
                           title='Reset Password', form=form)
예제 #2
0
def reset_password_request():
    # if user is already logged in:
    if current_user.is_authenticated:
        # send user home
        return redirect(url_for('home'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        # gets email to send password reset to and sends
        user = models.User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
        # tells user to check email for reset password link and sends them to
        # login page
        flash('Check your email for the instructions to reset your password')
        return redirect(url_for('login'))
    return render_template('reset_password_request.html',
                           title='Reset Password', form=form)
예제 #3
0
def resetrequest():
    form = ResetPasswordRequestForm(csrf_enabled=False)

    if request.method == 'POST':
        if form.username.data != 'admin':
            return render_template('resetrequest.html',
                                   invalid=True,
                                   form=form)
        else:

            seed = int(time.time())
            random.seed(seed)
            expiration = seed + (60 * 10)
            token = random.randint(0, 2**32)

            t = open('data/token', 'w')
            t.write(str(token) + ':' + str(expiration))
            t.close()
            return render_template('resetrequest.html',
                                   success=True,
                                   form=form)

    return render_template('resetrequest.html', form=form)