def reset_request():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RequestResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        send_reset_email(user)
        flash('An email has been sent with instructions to reset your password.', 'info')
        return redirect(url_for('login'))
    return render_template('reset_request.html', title='Reset Password', form=form)
Beispiel #2
0
def reset_request():
    if current_user.is_authenticated:
        return redirect(url_for("home"))
    form = RequestResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        send_reset_email(user)
        flash(
            "An email has been sent with instructions to reset your password.",
            "info")
        return redirect(url_for("login"))
    return render_template("reset_request.html",
                           title="Reset Password",
                           form=form)
Beispiel #3
0
def reset_request():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RequestResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        send_reset_email(user)
        flash(
            'An Email has been sent with instructions to reset your password.',
            'info')
        return redirect(url_for('login'))
    return render_template('reset_request.html',
                           title='Reset Password',
                           form=form)
Beispiel #4
0
def reset_request():
    if current_user.is_authenticated:
        return redirect(url_for("home"))
    form = RequestResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        send_reset_email(user)
        flash(
            "If an account with this email address exists, a password reset message will be sent shortly.",
            "danger")
        return redirect(url_for("login"))
    return render_template("reset_request.html",
                           title="Reset Password",
                           form=form)
def reset_request():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RequestResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        send_reset_email(user)
        flash(
            'An email with the reset link has been sent to your registered email account',
            'info')
        return redirect(url_for('login'))
    return render_template('reset_request.html',
                           title='Reset Password',
                           form=form)
def reset_request():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RequestResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        send_reset_email(user)
        flash(
            'Un email vient d\'être envoyé avec les informations permettant le changement de mots de passe.',
            'info')
        return redirect(url_for('login'))
    return render_template('reset_request.html',
                           title='Reset Password',
                           form=form)
Beispiel #7
0
def reset_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.home_page'))
    form = RequestResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        send_reset_email(user)
        flash(
            'An email has been sent to your account with proper instructios. ',
            'succes')
        return redirect(url_for('users.login'))
    return render_template('reset_request.html',
                           title='request reset password ',
                           form=form)
Beispiel #8
0
def reset_request():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RequestResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        try:
            send_reset_email(user)
        except socket.gaierror:
            return redirect(url_for('no_internet'))
        else:
            flash('An email sent with instructions to reset your password',
                  'info')
            return redirect(url_for('signin'))
    return render_template('reset_request.html', title="Reset Password", form=form)
Beispiel #9
0
def reset_request():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RequestResetForm()
    return render_template('reset_request.html',
                           title='Reset Password',
                           form=form)
Beispiel #10
0
def reset_request():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RequestResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is None:
            flash('No user exists with that email address', 'warning')
            return redirect(url_for('reset_request'))
        send_reset_email(user)
        flash(
            'An email has been sent with instructions to reset your password',
            'info')
        return redirect(url_for('login'))
    return render_template("reset_request.html",
                           title="Reset Password",
                           form=form)
Beispiel #11
0
def reset_request():

    if current_user.is_authenticated:
        logger.debug(
            f"Logged in user tried to reset password. User: {current_user.email}. IP: {request.remote_addr}"
        )
        flash("User already logged in!", "danger")
        return redirect(url_for("home"))

    form = RequestResetForm()
    if form.validate_on_submit():

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

        except:
            logger.warning(
                f"Could not search in database. User: {form.email.data}. IP: {request.remote_addr}"
            )
            flash(
                "Unexpected error at searching in database. Redirected to home.",
                "danger",
            )
            redirect(url_for(home))

        try:
            send_reset_email(user)

        except Exception as e:
            flash("Unexpected error at sending mail. Please try again!",
                  "danger")
            logger.warning(
                f"Mail could not be sent. User: {user.email}. IP: {request.remote_addr}. Error: {e}"
            )
            return redirect(url_for("register"))

        logger.debug(
            f"Recovery mail sent. Email: {user.email} . IP: {request.remote_addr}"
        )
        flash("A reset email was sent!", "info")

        return redirect(url_for("login"))

    return render_template("reset_request.html",
                           title="Reset Password",
                           form=form)
Beispiel #12
0
def request_reset():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RequestResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        message = Message(subject='Reset Password - Flaskblog',
                          recipients=[user.email],
                          sender=('Flaskblog', '*****@*****.**'))
        message.body = f'''Click the link below to reset your password:
{url_for('users.password_reset', token=user.generate_user_token(), _external=True)}

If you did not request a password reset you can safely ignore this email.
'''
        mail.send(message)
        flash('An email has been sent with reset instructions.', 'info')
    return render_template('request_reset.html', form=form)
Beispiel #13
0
def reset_request():
    try:
        if current_user.is_authenticated:
            return redirect(url_for('home'))
    except:
        pass
    form = RequestResetForm()
    if form.validate_on_submit():
        user = check_user(form.email.data)
        user_model = User_Model(user)
        send_reset_email(user_model)
        flash(
            'An email has been sent with instructions to reset your password',
            'info')
        return redirect(url_for('login'))
    return render_template('reset_request.html',
                           title='Reset Password',
                           form=form)
Beispiel #14
0
def reset_request():
    # make sure they are logged out
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RequestResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        # If the user exists send email with instructions
        # send_reset_email(user)
        flash(
            'An email has been sent with instructions to reset your password.',
            'info')
        # redirect them to the login page
        return redirect(url_for('login'))

    return render_template('reset_request.html',
                           title='Reset Password',
                           form=form)
Beispiel #15
0
def reset_request():
    page = request.args.get('page', 1, type=int)
    posts = Post.query.order_by(Post.date_posted.desc()).paginate(page=page,
                                                                  per_page=5)
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RequestResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        send_reset_email(user)
        flash(
            'An email has been sent with instructions to reset your password.',
            'info')
        return redirect(url_for('login'))
    return render_template('reset_request.html',
                           title='Reset Password',
                           form=form,
                           posts=posts)
Beispiel #16
0
def reset_request():
	if current_user.is_authenticated:
		return redirect(url_for('index'))
	form = RequestResetForm()
	if form.validate_on_submit():
		user = User.query.filter_by(email=form.email.data).first()
		token = user.get_reset_token()
		msg = Message('Password Reset', sender=app.config['MAIL_USERNAME'], recipients=[user.email])
		msg.body = f'''
				To reset your password, follow the link:
		{url_for('reset_password', token=token, _external=True)}
		link is valid for 30 minutes
	
		If you didn't make this request, kindly ignore
		'''
		send_email(msg)
		flash('Password reset email has been sent to your email','info')
		return redirect('login')
	return render_template('reset_request.html', title='Reset Request', form=form)
Beispiel #17
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('That token is no longer valid', 'warning')
        return redirect(url_for('reset_request'))
    form = RequestResetForm()
    return render_template('reset_token.html',
                           title='Reset password',
                           form=form)
def account():
    form = RequestResetForm()
    return render_template('account.html', title='Account',form=form)
Beispiel #19
0
                  sender='*****@*****.**',
                  recipients=[user.email])
    msg.body = "
    To reset your password, visit the following link:
{}
If you did not make this request then simply ignore this email and no changes will be made.
".format(url_for('reset_token', token=token, _external=True)

    mail.send(msg)


@app.route("/reset_password", methods=['GET', 'POST'])
def reset_request():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RequestResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        send_reset_email(user)
        flash('An email has been sent with instructions to reset your password.', 'info')
        return redirect(url_for('login'))
    return render_template('reset_request.html', title='Reset Password', form=form)


@app.route("/reset_password/<token>", methods=['GET', 'POST'])
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('That is an invalid or expired token', 'warning')