Exemplo n.º 1
0
 def post(self, *args, **kwargs):
     """ Sends the password reset to email """
     user = User.by_email(self.get_argument("email", ""))
     if user is not None and len(options.mail_host) > 0 and len(user.email) > 0:
         reset_token = encode(urandom(16), "hex")
         passtoken = PasswordToken()
         passtoken.user_id = user.id
         passtoken.value = sha256(reset_token).hexdigest()
         self.dbsession.add(passtoken)
         self.dbsession.commit()
         receivers = [user.email]
         message = self.create_reset_message(user, reset_token)
         smtpObj = smtplib.SMTP(options.mail_host, port=options.mail_port)
         smtpObj.set_debuglevel(False)
         try:
             smtpObj.starttls()
             try:
                 smtpObj.login(options.mail_username, options.mail_password)
             except smtplib.SMTPNotSupportedError as e:
                 logging.warn("SMTP Auth issue (%s). Attempting to send anyway." % e)
             smtpObj.sendmail(options.mail_sender, receivers, message)
         finally:
             smtpObj.quit()
         logging.info("Password Reset sent for %s" % user.email)
     elif not len(options.mail_host) > 0:
         logging.info("Password Reset request failed: No Mail Host in Settings.")
     elif user is None or not len(user.email) > 0:
         logging.info("Password Reset request failed: Email does not exist.")
     self.render(
         "public/forgot.html",
         errors=None,
         info=["If the email exists, a password reset has been sent."],
     )
Exemplo n.º 2
0
    def post(self, *args, **kwargs):
        """ Sends the password reset to email """
        user = User.by_email(self.get_argument("email", ""))
        if user is not None and len(options.mail_host) > 0 and len(
                user.email) > 0:
            reset_token = encode(urandom(16), "hex")
            passtoken = PasswordToken()
            passtoken.user_id = user.id
            passtoken.value = sha256(reset_token).hexdigest()
            self.dbsession.add(passtoken)
            self.dbsession.commit()
            receivers = [user.email]
            message = self.create_message(user, reset_token)
            smtpObj = smtplib.SMTP(options.mail_host, port=options.mail_port)
            smtpObj.set_debuglevel(False)
            try:
                smtpObj.starttls()
                smtpObj.login(options.mail_username, options.mail_password)
                smtpObj.sendmail(options.mail_sender, receivers, message)
            finally:
                smtpObj.quit()

        self.render(
            "public/forgot.html",
            errors=None,
            info=["If the email exists, a password reset has been sent."],
        )