Exemplo n.º 1
0
 def set_password(self, password, random=False):
     """
     Encrypt the password and save it in the DB
     Return the password passed or the new password if randomed
     """
     if random:
         password = utils.generate_random_string()
     self.update(password_hash=utils.encrypt_string(password))
     return password
Exemplo n.º 2
0
 def set_temp_login(self, expiration=60):
     """
     Create temp login.
     It will allow to have change password on account
     :param expiration: in minutes the time for expiration
     """
     expiration = datetime.datetime.now() + datetime.timedelta(minutes=expiration)
     while True:
         token = utils.generate_random_string(32).lower()
         if not User.all().filter(User.temp_login_token == token).first():
             break
     self.update(has_temp_login=True, temp_login_token=token, temp_login_expiration=expiration)
     return token