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
Exemplo n.º 3
0
def setup_default():

    # Create all db
    model.db.create_all()

    # Setup User
    admin_email = conf.APPLICATION_ADMIN_EMAIL
    password = utils.generate_random_string()
    if user.setup(model.User, admin_email=admin_email, password=password):
        click.echo("---- Setup SUPER ADMIN User ----")
        click.echo("- Admin Email: %s" % admin_email)
        click.echo("- Admin Password: %s" % password)
        click.echo("-" * 40)
        click.echo("")

    # Setup Publisher
    admin_user = model.User.User.get_by_email(admin_email)
    if admin_user and admin_user.role.name.lower() == "superadmin":
        click.echo("---- Setup PUBLISHER ----")
        if publisher.setup(model.Publisher, admin_user_id=admin_user.id):
            click.echo("Completed")
        click.echo("-" * 40)
        click.echo("")