def forgot(): if request.args.get('expired') and int(request.args.get('expired')) == 1: flash( "This reset link has expired. Please request another password reset." ) token = request.args.get('token', None) form = ForgotPasswordForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user: token = user.get_token() user.forgot_pwd = token link = url_for('authentication.reset', pass_hash=user.forgot_pwd, _external=True) msg = Message("Password Reset Link", sender=("Matcha", "*****@*****.**"), recipients=[user.email]) msg.html = "Hello " + user.first_name + ",<br /> <br />You have requested a password " \ + "reset link.<br /><br />Below is a link to reset your password that expires " \ + " in 24 hours<br /><br /><a href=\""+ link \ + "\">Click here to reset your password</a>" mail.send(msg) db.session.add(user) db.session.commit() flash('Please check your email for the reset link') return render_template('forgot.html', form=form)
def forgot_password(): forgotPasswordForm = ForgotPasswordForm() if forgotPasswordForm.validate_on_submit(): profile = get_profile_from_db(forgotPasswordForm.email.data) newPassword = forgotPasswordForm.password_reset(email=profile.email) send_reset_password_email(destination_profile=profile, new_password=newPassword) db.session.commit() return redirect(url_for('auth.sign_in')) return render_template('forgot_password.html', form=forgotPasswordForm, title='Reset your password')
def forgot_password(): if current_user.is_authenticated: return redirect(url_for("index")) form = ForgotPasswordForm() 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/forgot_password.html", title="Forgot my password", form=form )
def reset_password_request(): if current_user.is_authenticated: return redirect(url_for('main.index')) form = ForgotPasswordForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user: send_password_reset_email(user) flash( 'Instructions for resetting your password have been sent! Please check your email.', 'success') return redirect(url_for('auth.login')) return render_template('auth/reset_password_request.html', title='Reset Password', form=form)
def forgot_password(): if current_user.is_authenticated: return redirect(url_for('main.index')) form = ForgotPasswordForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user: if send_password_reset_email(user): flash('Check your email for instructions to reset your password','success') else: flash('Sorry system error','danger') else: flash('That email does not exist in our database','danger') return redirect(url_for('auth.forgot_password')) return render_template('auth/forgot_password.html',form=form)
def forgotpassword(): if current_user.is_authenticated: return redirect(url_for('main.index')) form = ForgotPasswordForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user: send_password_reset_mail(user) flash( _('Please check your email for instructions to reset your password!' )) return redirect(url_for('auth.login')) return render_template('auth/forgotpassword.html', title=_("Forgot Password"), form=form)
def reset_password(token): #if request.method == 'GET': #manage_prev_page() form = ForgotPasswordForm() user = User.verify_reset_password_token(token) if request.method == 'GET': if not user: flash('You are not authorized') return redirect(session['prev_page']) else: if form.validate_on_submit(): user.set_password(form.newpassword.data) db.session.commit() flash('Your password has been reset') return redirect(url_for('auth.login')) else: flash('Check your credentials') return render_template('auth/forgot_password.html', form=form, token=token)