Beispiel #1
0
def reset_password(serialized_token):
    expired, invalid, user = unserialize_token(serialized_token, 'reset')
    if expired:
        flash(msgs['LINK_EXPIRED'], 'error')
        return redirect(url_for('.index'))
    if invalid:
        flash(msgs['LINK_INVALID'], 'error')
        return redirect(url_for('.index'))
    
    form = ResetPasswordForm()
    form.login.data = user.login
    if form.validate_on_submit():
        encrypted_password = encrypt_password(form.password.data)
        user.passhash = encrypted_password

        db.session.add(user)
        db.session.commit()

        form.dispose_password()

        flash(msgs['RESET_PASSWORD_SUCCESS'])
        return redirect(url_for('.login'))
    
    for field in form.errors:
        flash('<strong>' + field.capitalize() + '</strong>' + ': ' + form.errors[field][0], 'error')
    
    return render_template('reset_password.html', form=form, serialized_token=serialized_token)
Beispiel #2
0
def activate(serialized_token):
    expired, invalid, user = unserialize_token(serialized_token, 'activate')
    if expired:
        flash(msgs['LINK_EXPIRED'], 'error')
        return redirect(url_for('.index'))
    if invalid:
        flash(msgs['LINK_INVALID'], 'error')
        return redirect(url_for('.index'))
    user.activate()
    flash(msgs['ACTIVATION_SUCCESS'])
    login_user(user)
    return redirect(url_for('.admin_index'))