def lost_passwd(self, data):
        """ Send a reset link to user to recover its password """
        error = False
        msg = ""

        # Check input format
        email_re = re.compile(
            r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*"  # dot-atom
            r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"'  # quoted-string
            r')@(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$', re.IGNORECASE)  # domain
        if email_re.match(data["recovery_email"]) is None:
            error = True
            msg = _("Invalid email format.")

        if not error:
            reset_hash = hashlib.sha512(str(random.getrandbits(256)).encode("utf-8")).hexdigest()
            user = self.database.users.find_one_and_update({"email": data["recovery_email"]}, {"$set": {"reset": reset_hash}})
            if user is None:
                error = True
                msg = _("This email address was not found in database.")
            else:
                try:
                    web.sendmail(web.config.smtp_sendername, data["recovery_email"], _("INGInious password recovery"),
                                 _("""Dear {realname},

Someone (probably you) asked to reset your INGInious password. If this was you, please click on the following link :
""").format(realname=user["realname"]) + web.ctx.home + "/register?reset=" + reset_hash)
                    msg = _("An email has been sent to you to reset your password.")
                except:
                    error = True
                    msg = _("Something went wrong while sending you reset email. Please contact the administrator.")

        return msg, error
def lost_passwd ( self , data ) : error = False msg = "" email_re = re . compile ( r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' r')@(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$' , re . IGNORECASE ) if email_re . match ( data [ "recovery_email" ] ) is None : error = True msg = _ ( "Invalid email format." ) if not error : reset_hash = hashlib . sha512 ( str ( random . getrandbits ( 256 ) ) . encode ( "utf-8" ) ) . hexdigest ( ) user = self . database . users . find_one_and_update ( { "email" : data [ "recovery_email" ] } , { "$set" : { "reset" : reset_hash } } ) if user is None : error = True msg = _ ( "This email address was not found in database." ) else : try : web . sendmail ( web . config . smtp_sendername , data [ "recovery_email" ] , _ ( "INGInious password recovery" ) , _ ( """Dear {realname},
Someone (probably you) asked to reset your INGInious password. If this was you, please click on the following link :
""" ) . format ( realname = user [ "realname" ] ) + web . ctx . home + "/register?reset=" + reset_hash ) msg = _ ( "An email has been sent to you to reset your password." ) except : error = True msg = _ ( "Something went wrong while sending you reset email. Please contact the administrator." ) return msg , error
Send a reset link to user to recover its password