-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathusers.py
More file actions
executable file
·96 lines (79 loc) · 2.74 KB
/
users.py
File metadata and controls
executable file
·96 lines (79 loc) · 2.74 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#############################################################################
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
#############################################################################
from __future__ import print_function
import sys
from getpass import getpass
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "TechnicAntani.settings")
# here be dragons (aka django)
from django.contrib.auth.models import User
def list_users(args):
quiet = False
if "-q" in args:
quiet = True
if not quiet:
print("ID\tusername")
print("------------")
for u in User.objects.all():
print(str(u.id) + " " + u.username)
def create_user(args):
if len(args) < 1:
print_help()
x = User()
x.username = args[0]
if len(args) == 2:
x.email = args[1]
x.set_password(getpass())
x.save()
print("User created.")
def change_pass(args):
if len(args) < 1:
print_help()
x = User.objects.get(pk=args[0])
x.set_password(getpass())
x.save()
print("Password changed.")
def delete_user(args):
if len(args) < 1:
print_help()
x = User.objects.get(pk=args[0])
x.delete()
print("User deleted.")
def main(args):
if args[0] == "list":
list_users(args[1:])
elif args[0] == "create":
create_user(args[1:])
elif args[0] == "chpass":
change_pass(args[1:])
elif args[0] == "delete":
delete_user(args[1:])
else:
print_help()
def print_help():
print("""Usage:
\tlist [-q]
\tcreate name [email]
\tchpass id
\tdelete id
""")
sys.exit(0)
if __name__ == "__main__":
if len(sys.argv) < 2:
print_help()
else:
main(sys.argv[1:])