Exemplo n.º 1
0
def recover_password():
    form = RecoverPasswordForm(meta={'csrf_context': session})
    if form.validate_on_submit():
        login = form.login.data
        user = User.query.filter_by(login=login).first()
        email = user.email

        recovery_token = RecoveryToken(user=user)
        db.session.add(recovery_token)
        db.session.commit()

        # Build link
        app_url_parts = urlsplit(request.base_url)
        url_path = url_for('account.validate_password_token')
        url_query = f'user={login}&token={recovery_token.token}'
        recovery_link = urlunsplit(
            (app_url_parts.scheme, app_url_parts.netloc, url_path, url_query, ''))

        topic = 'Recover password'
        message = f'Żeby zresetować hasło przejdź pod ten link: {recovery_link}'

        send_email(email, topic, message)

        flash('Na adres email podany przy rejestracji został wysłany email z linkiem do resetu hasła',
              'alert alert-success')
        return redirect(url_for('account.login'))

    return render_template('recover_password.html', form=form)
Exemplo n.º 2
0
def reset_password():
    form = RecoverPasswordForm()

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()

        if user:
            flash('Please see your email for instructions on '
                  'how to access your account', 'success')

            user.activation_key = str(uuid4())
            db.session.add(user)
            db.session.commit()

            return render_template('frontend/reset_password.html', form=form)
        else:
            flash('Sorry, no user found for that email address', 'error')

    return render_template('frontend/reset_password.html', form=form)
Exemplo n.º 3
0
def reset_password():
    form = RecoverPasswordForm()

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()

        if user:
            flash(
                'Please see your email for instructions on '
                'how to access your account', 'success')

            user.activation_key = str(uuid4())
            db.session.add(user)
            db.session.commit()

            return render_template('frontend/reset_password.html', form=form)
        else:
            flash('Sorry, no user found for that email address', 'error')

    return render_template('frontend/reset_password.html', form=form)