Esempio n. 1
0
def reset_password_request():
    """Request a password reset email if the password has been forgotten.
    
    Returns:
        Redirects to password reset form if form has not been submitted.
        Redirects to home page if user is already logged in.
        Redirects to login page if reset password email is successfully
            sent.
    """
    if current_user.is_authenticated:
        return redirect(url_for('coding.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('auth.login'))

    return render_template(
        'auth/reset_password_request.html',
        title='Reset Password',
        form=form,
    )
Esempio n. 2
0
def test_password_reset(mocked_email, test_client, init_database):
    user = User.query.filter_by(email="*****@*****.**").first()
    value = b64encode(os.urandom(16)).decode("utf-8")
    token = user.get_reset_password_token(value)
    with current_app.test_request_context():
        send_password_reset_email(user, token)
    mocked_email.assert_called()
Esempio n. 3
0
def reset_password_request():
    """
    Page where user can request the reset of the password
    :return:
    """
    # if logged in, return to index.
    if current_user.is_authenticated:
        return redirect(url_for("main.index"))

    # Instantiate the form object.
    form = ResetPasswordRequestForm()

    # if form validate successfully,
    if form.validate_on_submit():

        # Get user by email.
        user = User.query.filter_by(email=form.email.data).first()

        # if user EXIST, send email.
        if user:
            send_password_reset_email(user)

        # Display to inform user.
        flash("Check your email for the instruction to reset your password")

        # Redirect to login.
        return redirect(url_for("auth.login"))

    return render_template("auth/reset_password_request.html",
                           title="Reset Password",
                           form=form)
Esempio n. 4
0
def reset_password():
    data = request.get_json() or {}
    if 'email' in data:
        user = User.query.filter_by(email=data['email']).first()
        if user:
            send_password_reset_email(user)
    data = jsonify()
    data.status_code = 202
    return data
Esempio n. 5
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.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(_('Email sent, please check your inbox.'))
    return render_template('auth/reset_password_request.html', title='Reset password', form=form)
Esempio n. 6
0
def reset_password_request():
	if request.method == "POST":
		user = User.query.filter_by(username=request.form['email']).first()
		if user:
			send_password_reset_email(user)
		flash('Please check your email for instructions on resetting your password',
					 'success')
	if current_user.is_authenticated:
		return redirect(url_for('main.index'))
	return render_template('reset_password_request.html')
Esempio n. 7
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.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('Controlla la tua casella email per conoscere le istruzione per il reset della password')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html', title='Reset password', form=form)
Esempio n. 8
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.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(_('If your email is found in the system, you will get a reset link soon.'))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html.j2', title='Reset Password', form=form)
Esempio n. 9
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.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('auth.login'))
    return render_template('auth/reset_password_request.html', title = 'Reset Password', form= form)
Esempio n. 10
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    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('Link to reset password has been sent to the email entered.')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html', title='Reset Password', form=form)
Esempio n. 11
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for("main.index"))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if not user:
            flash(
                _(
                    "Check your email for the instructions "
                    "to reset your password."
                )
            )
            return redirect(url_for("auth.login"))

        confirming_value = user.get_random_base64_value()
        token = user.get_reset_password_token(confirming_value)
        now = datetime.utcnow()
        should_send_mail = False

        reset_password = ResetPassword.query.filter_by(
            user_id=user.did
        ).first()
        if reset_password:
            user.delete_expired_tokens(reset_password)
            if not reset_password.first_value:
                reset_password.first_value = confirming_value
                reset_password.first_date = now
                should_send_mail = True
            elif not reset_password.second_value:
                reset_password.second_value = confirming_value
                reset_password.second_date = now
                should_send_mail = True
            db.session.add(reset_password)
        else:
            reset_password_new = ResetPassword(
                first_value=confirming_value, first_date=now, user_id=user.did
            )
            db.session.add(reset_password_new)
            should_send_mail = True
        db.session.commit()
        if should_send_mail:
            send_password_reset_email(user, token)

        flash(
            _("Check your email for the instructions to reset your password.")
        )
        return redirect(url_for("auth.login"))
    return render_template(
        "auth/reset_password_request.html",
        title=_("Reset Password"),
        form=form,
    )
Esempio n. 12
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.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(_('请检查你的邮箱,进行重置密码操作'))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title=_('重置密码'), form=form)
Esempio n. 13
0
def reset_password_request():
    """Respond to existing user's request to reset their password."""
    form = RequestResetPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_password_reset_email(user)
        flash(
            'A password reset link has been sent to {}.'.format(
                form.email.data), 'warning')
        return redirect(url_for('account.login'))
    return render_template('home/reset_password.html', form=form)
Esempio n. 14
0
def reset_password():
    data = request.get_json() or {}

    # Validation
    try:
        ResetValidator().validate({'email': str}, data)
    except ValueError as exception:
        return bad_request(exception.args[0])

    # Send reset to the email
    send_password_reset_email(User.query.filter_by(email=data['email']).first())
    return jsonify(True)
Esempio n. 15
0
def reset_password_request():
    # prevent the logged user to see this page
    if current_user.is_authenticated:
        return redirect(url_for('dashboard.overview'))
    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 instruction to reset your password.')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title='Reset Password', form=form)
Esempio n. 16
0
def request_password_reset():
    if (current_user.is_authenticated):
        return redirect(url_for('main.index'))
    form = RequestPasswordResetForm()
    if form.validate_on_submit():
        doc = Doctor.query.filter_by(email=form.email.data).first()
        if doc:
            send_password_reset_email(doc)
        flash('Check email')
        return redirect(url_for('auth.login'))
    return render_template('auth/request_password_reset.html',
                           title='Reset Password',
                           form=form)
Esempio n. 17
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.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("if ur legit, you'll receive a reset link in your inbox")
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_pw_request.html',
                           title='reset password',
                           form=form)
Esempio n. 18
0
def reset_password_request():
    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(
            'Veuillez vérifier votre boite mail pour savoir comment réinitialiser votre mot de passe.'
        )
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title='Réinitialiser votre mot de passe',
                           form=form)
Esempio n. 19
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.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(
            _('Проверьте свою электронную почту для получения инструкций по сбросу пароля'))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title=_('Смена пароля'), form=form)
Esempio n. 20
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.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(_('Kolla din mail för instruktioner'))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title=_('Återställ lösenord'),
                           form=form)
Esempio n. 21
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.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('Письмо с информацией о смене пароля отправлено на почту')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title='Смена пароля',
                           form=form)
Esempio n. 22
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data.lower()).first()
        if user:
            send_password_reset_email(user)
        flash(_('Bitte kontrolliere deine Emails für weitere anweisungen'))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title=_('Passwort zurücksetzen'),
                           form=form)
Esempio n. 23
0
File: routes.py Progetto: bwyt/Blog
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('邮件发送成功,请通过邮箱找回密码')
        return redirect(url_for('auth.login'))
    return render_template('reset_password_request.html',
                           title='Reset Password',
                           form=form)
Esempio n. 24
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.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(
            _("Jette un coup d'oeil à tes emails et suis les instructions de réinitialisation de ton mot de passe."))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title=_('Réinitialisation du mot de passe'), form=form)
Esempio n. 25
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for("main.index"))
    form = ResetPasswordRequstForm()
    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 further instructions!")
        return redirect(url_for("auth.login"))
    return render_template("reset_password_request.html",
                           title="Reset Password",
                           form=form)
Esempio n. 26
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.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('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title=_('Reset Password'), form=form)
Esempio n. 27
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.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(
            _l('Проверьте вашу почту на наличие инструкции для сброса пароля'))
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title='Сброс пароля',
                           form=form)
Esempio n. 28
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.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('Password-resetting mail has been sent. Check your inbox as soon as possible.')
        else:
            flash('Invalid email address. Try entering the email address of your logging account.')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html', title='Reset your password', form=form,
                           Permission=Permission)
Esempio n. 29
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(
            url_for('index'))  #Loggedin users shouldnt be able to access
    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('Reset password instructions have been sent to your email.')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password_request.html',
                           title='Reset Password',
                           form=form)
def reset_password_request():
    # Prevent already logged in users requesting password reset
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = PasswordResetRequestForm()
    if form.validate_on_submit():
        # Query user and return user object or None
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            # If user exist, send reset link to user email
            send_password_reset_email(user)
        flash('Check your email for password reset.')
        return redirect(url_for('auth.login'))
    return render_template('auth/password_reset_request.html', form=form)
Esempio n. 31
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for("main.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("Sprawdź proszę swoją skrzynkę pocztową. Dalsze instrukcje \
              czekają tam na Ciebie.")
        return redirect(url_for("auth.login"))
    return render_template("auth/reset_password_request.html",
                           title="Reset Password",
                           form=form)