AIL-framework/var/www/create_default_user.py

33 lines
1005 B
Python
Executable File

#!/usr/bin/env python3
# -*-coding:UTF-8 -*
import os
import sys
sys.path.append(os.environ['AIL_BIN'])
##################################
# Import Project packages
##################################
from lib import ail_users
if __name__ == "__main__":
# create role_list
ail_users._create_roles_list()
user_id = 'admin@admin.test'
password = ail_users.gen_password()
ail_users.create_user(user_id, password=password, admin_id='admin@admin.test', role='admin')
token = ail_users.get_default_admin_token()
default_passwd_file = os.path.join(os.environ['AIL_HOME'], 'DEFAULT_PASSWORD')
to_write_str = '# Password Generated by default\n# This file is deleted after the first login\n#\nemail=admin@admin.test\npassword='
to_write_str = f'{to_write_str}{password}\nAPI_Key={token}\n'
with open(default_passwd_file, 'w') as f:
f.write(to_write_str)
print(f'new user created: {user_id}')
print(f'password: {password}')
print(f'token: {token}')