def post(self): data = ImmutableMultiDict(request.json) forgot_password_form = ForgotPasswordForm(data, csrf_enabled=False) if forgot_password_form.validate(): instance = User.query.filter(User.email == data['email']).first() forgot_password_form.send_mail(instance) return {"status": "success"} return forgot_password_form.errors
def forgot(): form = ForgotPasswordForm(request.form) if request.method == "POST" and form.validate(): s = Signer(app.config['SECRET_KEY']) token = s.sign(request.form['email']) send_password_reset(form.get_user(), token) return redirect('/forgot_confirmation') return render_template("forgot.html", form=form)
def forgot_password(): forgot_form = ForgotPasswordForm(request.form) error = None if request.method == 'POST': if forgot_form.validate() and recaptcha_check(request.form["g-recaptcha-response"]): user = User.get(email=forgot_form.email.data) if user is not None: if user.forgot_password(): link = url_for("common_views.change_password", user_id=user.user_id, secret=user.forgot_secret, _external=True) current_app.logger.info(link) mail = mail_handler.Mail(user.email, link) mail.send() return redirect(url_for("common_views.index")) else: error = "A user with this email does not exist!" else: error = "Please enter email address and prove you are not a robot!" return render_template("forgot.html", forgot_form=forgot_form, error=error)
def forgot_password(): forgot_form = ForgotPasswordForm(request.form) error = None if request.method == 'POST': if forgot_form.validate() and recaptcha_check( request.form["g-recaptcha-response"]): user = User.get(email=forgot_form.email.data) if user is not None: if user.forgot_password(): link = url_for("common_views.change_password", user_id=user.user_id, secret=user.forgot_secret, _external=True) current_app.logger.info(link) mail = mail_handler.Mail(user.email, link) mail.send() return redirect(url_for("common_views.index")) else: error = "A user with this email does not exist!" else: error = "Please enter email address and prove you are not a robot!" return render_template("forgot.html", forgot_form=forgot_form, error=error)
def forgot_password(): if current_user.is_authenticated: return render_view(url_for('latest'), redirect=True, message=_('SESSIONS_MSG_ALREADY_SIGNED_IN')) form = ForgotPasswordForm() if form.is_submitted(): try: if not form.validate(): raise Exception(_('ERROR_INVALID_SUBMISSION')) if not verify_captcha(): raise Exception(_('SESSIONS_ERROR_UNFINISHED_CHALLENGE_LBL')) email = form.email.data user = User.find_by_email(email) if not user: raise Exception(_('SESSIONS_ERROR_MAIL_NOT_FOUND', email=email)) user.generate_reset_password() flash(_('SESSIONS_PASSWORD_RESET', email=email)) # send reset password email send_email('reset_password', user) return render_view(url_for('sessions.forgot_password'), redirect=True) except Exception as e: flash(e.message, 'error') return render_view('admin/sessions/forgot_password.html', form=form)