-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate_user.py
executable file
·77 lines (61 loc) · 2.1 KB
/
create_user.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!venv/bin/python3
# from sys import argv
from getpass import getpass
from argparse import ArgumentParser, RawDescriptionHelpFormatter
from app.modules.auth.auth_users_local import AuthUsers
from app import logger
def add_new_user(email: str):
user = AuthUsers
while True:
email = email
username = input("Username: ")
password = getpass("Password: ", stream=None)
confirm_password = getpass("Retype password: ", stream=None)
role = "sadmin"
auth_method = "local"
if password == confirm_password:
check = user(
username=username,
password=password,
email=email,
role=role,
auth_method=auth_method,
).add_user()
if not check:
logger.info(
f"User {username} has not been added check your database settings"
)
logger.info(f"User {username} has been added")
break
print("Passwords do not match")
def delete_user(email: str) -> bool:
user = AuthUsers
return user(email=email).del_user_by_email()
def cli_parser():
parser = ArgumentParser(
description="Users setting script", formatter_class=RawDescriptionHelpFormatter
)
parser.add_argument("-a", "--add", dest="email", help="Add user by email")
parser.add_argument(
"-d", "--del", dest="deleting_email", help="Delete user by email"
)
args = parser.parse_args()
if args.email is not None:
print(f"Creating user: {args.email}")
add_new_user(email=args.email)
elif args.deleting_email is not None:
print(f"Deleting user: {args.deleting_email}")
delete_user(email=args.deleting_email)
else:
print("You need to use arguments, use -h to see options")
# def main():
# args = argv
# if len(args) > 1:
# if args[1] == "-a":
# add_new_user()
# if args[1] == "-h":
# print("-a add new user")
# else:
# print("-a add new user")
if __name__ == "__main__":
cli_parser()