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
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
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
def setup_admin_user_publisher(): """ Setup Juice User and Publisher Admin :return: """ # ==== Setup User Admin === # admin_email = conf.APPLICATION_ADMIN_EMAIL if not admin_email: print("ERROR: APPLICATION_ADMIN_EMAIL is empty") exit() password = utils.generate_random_string() if user.setup(model.User, admin_email=admin_email, password=password): if mail.validated: body = "Admin Password: %s" % password mail.send(to=admin_email, subject="Admin Password", body=body) print("---- Setup SUPER ADMIN User ----") print(("- Admin Email: %s" % admin_email)) print(("- Admin Password: %s" % password)) print(("-" * 40)) print("") # ==== Setup Publisher === # # admin user admin_user = model.User.User.get_by_email(admin_email) # Set default categories and post types post_categories = ["Uncategorized"] post_types = ["Page", "Blog", "Document", "Other"] if admin_user and admin_user.role.name.lower() == "superadmin": print("---- Setup PUBLISHER ----") if publisher.setup(model.Publisher, admin_user_id=admin_user.id, post_types=post_types, post_categories=post_categories): print("Completed") print(("-" * 40)) print("")
def setup_admin_user_publisher(): """ Setup Juice User and Publisher Admin :return: """ # ==== Setup User Admin === # admin_email = conf.APPLICATION_ADMIN_EMAIL if not admin_email: print("ERROR: APPLICATION_ADMIN_EMAIL is empty") exit() password = utils.generate_random_string() if user.setup(model.User, admin_email=admin_email, password=password): if mail.validated: body = "Admin Password: %s" % password mail.send(to=admin_email, subject="Admin Password", body=body) print("---- Setup SUPER ADMIN User ----") print("- Admin Email: %s" % admin_email) print("- Admin Password: %s" % password) print("-" * 40) print("") # ==== Setup Publisher === # # admin user admin_user = model.User.User.get_by_email(admin_email) # Set default categories and post types post_categories = ["Uncategorized"] post_types = ["Page", "Blog", "Document", "Other"] if admin_user and admin_user.role.name.lower() == "superadmin": print("---- Setup PUBLISHER ----") if publisher.setup( model.Publisher, admin_user_id=admin_user.id, post_types=post_types, post_categories=post_categories ): print("Completed") print("-" * 40) print("")