ail-framework/var/www/create_default_user.py
2023-03-16 14:47:59 +01:00

32 lines
980 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 Users
if __name__ == "__main__":
# create role_list
Users._create_roles_list()
user_id = 'admin@admin.test'
password = Users.gen_password()
Users.create_user(user_id, password=password, role='admin')
token = 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('new user created: {}'.format(user_id))
print('password: {}'.format(password))
print('token: {}'.format(token))