def send(self, request: Request, session: Session, mail: Mail, validate: Validator): errors = request.validate(validate.required("email"), validate.email("email")) if errors: request.session.flash("error", errors) return request.back() email = request.input("email") user = AUTH["model"].where("email", email).first() if user: if not user.remember_token: user.remember_token = str(uuid.uuid4()) user.save() link = "{}/users/reset-password/{}".format( request.environ["HTTP_HOST"], user.remember_token) mail.subject("{}: Reset Your Password".format( config("application.name"))).template( "users/password-reset-email", { "name": user.name, "link": link }).to(user.email).send() session.flash("success", self.reset_message) return request.redirect("/")
def send(self, request: Request, session: Session, mail: Mail, validate: Validator): errors = request.validate(validate.required('email'), validate.email('email')) if errors: return request.back().with_errors(errors) email = request.input('email') user = AUTH['guards']['web']['model'].where('email', email).first() if user: if not user.remember_token: user.remember_token = str(uuid.uuid4()) user.save() message = 'Please visit {}/password/{}/reset to reset your password'.format( env('SITE', 'http://localhost:8000'), user.remember_token) mail.subject('Reset Password Instructions').to( user.email).send(message) session.flash( 'success', 'If we found that email in our system then the email has been sent. Please follow the instructions in the email to reset your password.' ) return request.redirect('/password')
def send(self, request: Request, session: Session, mail: Mail, validate: Validator): errors = request.validate(validate.required("email"), validate.email("email")) if errors: return request.back().with_errors(errors) email = request.input("email") user = AUTH["guards"]["web"]["model"].where("email", email).first() if user: if not user.remember_token: user.remember_token = str(uuid.uuid4()) user.save() message = "Please visit {}/password/{}/reset to reset your password".format( env("SITE", "http://localhost:8000"), user.remember_token) mail.subject("Reset Password Instructions").to( user.email).send(message) session.flash( "success", "If we found that email in our system then the email has been sent. Please follow the instructions in the email to reset your password.", ) return request.redirect("/password")
def send(self, request: Request, session: Session, mail: Mail): email = request.input('email') user = AUTH['model'].where('email', email).first() if user: if not user.remember_token: user.remember_token = str(uuid.uuid4()) user.save() message = 'Please visit {}/password/{}/reset to reset your password'.format( env('SITE', 'http://localhost:8000'), user.remember_token) mail.subject('Reset Password Instructions').to(email).send(message) session.flash( 'success', 'Email sent. Follow the instruction in the email to reset your password.' ) return request.redirect('/password') else: session.flash( 'error', 'Could not send reset email. Please enter correct email.') return request.redirect('/password')
def send(self, request: Request, session: Session, mail: Mail): email = request.input("email") user = AUTH["model"].where("email", email).first() if user: if not user.remember_token: user.remember_token = str(uuid.uuid4()) user.save() message = "Please visit {}/password/{}/reset to reset your password".format( env("SITE", "http://localhost:8000"), user.remember_token) mail.subject("Reset Password Instructions").to(email).send(message) session.flash( "success", "Email sent. Follow the instruction in the email to reset your password.", ) return request.redirect("/password") else: session.flash( "error", "Could not send reset email. Please enter correct email.") return request.redirect("/password")