Commit | Line | Data |
---|---|---|
fc3dc255 WKG |
1 | # GNU MediaGoblin -- federated, autonomous media hosting |
2 | # Copyright (C) 2011 Free Software Foundation, Inc | |
3 | # | |
4 | # This program is free software: you can redistribute it and/or modify | |
5 | # it under the terms of the GNU Affero General Public License as published by | |
6 | # the Free Software Foundation, either version 3 of the License, or | |
7 | # (at your option) any later version. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU Affero General Public License for more details. | |
13 | # | |
14 | # You should have received a copy of the GNU Affero General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | ||
96108ea2 | 17 | from mediagoblin.gmg_commands import util as commands_util |
96108ea2 AV |
18 | from mediagoblin.auth import lib as auth_lib |
19 | from mediagoblin import mg_globals | |
20 | ||
96108ea2 AV |
21 | |
22 | def adduser_parser_setup(subparser): | |
23 | subparser.add_argument( | |
8781ddb5 | 24 | 'username', |
96108ea2 AV |
25 | help="Username used to login") |
26 | subparser.add_argument( | |
8781ddb5 | 27 | 'password', |
96108ea2 AV |
28 | help="Your supersecret word to login") |
29 | subparser.add_argument( | |
8781ddb5 | 30 | 'email', |
96108ea2 AV |
31 | help="Email to recieve notifications") |
32 | subparser.add_argument( | |
33 | '-cf', '--conf_file', default='mediagoblin.ini', | |
34 | help="Config file used to set up environment") | |
35 | ||
36 | ||
37 | def adduser(args): | |
38 | #TODO: Lets trust admins this do not validate Emails :) | |
8781ddb5 | 39 | commands_util.setup_app(args) |
96108ea2 | 40 | |
8781ddb5 CAW |
41 | db = mg_globals.database |
42 | users_with_username = \ | |
43 | db.User.find({ | |
44 | 'username': args.username.lower() | |
45 | }).count() | |
96108ea2 | 46 | |
8781ddb5 CAW |
47 | if users_with_username: |
48 | print u'Sorry, a user with that name already exists.' | |
96108ea2 | 49 | |
8781ddb5 CAW |
50 | else: |
51 | # Create the user | |
52 | entry = db.User() | |
53 | entry['username'] = unicode(args.username.lower()) | |
54 | entry['email'] = unicode(args.email) | |
55 | entry['pw_hash'] = auth_lib.bcrypt_gen_password_hash(args.password) | |
a3fae1bd | 56 | entry['status'] = u'active' |
8781ddb5 CAW |
57 | entry['email_verified'] = True |
58 | entry.save(validate=True) | |
96108ea2 | 59 | |
64201d12 | 60 | print "User created (and email marked as verified)" |
96108ea2 AV |
61 | |
62 | ||
63 | def makeadmin_parser_setup(subparser): | |
64 | subparser.add_argument( | |
8781ddb5 | 65 | 'username', |
96108ea2 AV |
66 | help="Username to give admin level") |
67 | subparser.add_argument( | |
68 | '-cf', '--conf_file', default='mediagoblin.ini', | |
69 | help="Config file used to set up environment") | |
70 | ||
71 | ||
72 | def makeadmin(args): | |
8781ddb5 | 73 | commands_util.setup_app(args) |
96108ea2 | 74 | |
8781ddb5 | 75 | db = mg_globals.database |
96108ea2 | 76 | |
8781ddb5 CAW |
77 | user = db.User.one({'username':unicode(args.username.lower())}) |
78 | if user: | |
79 | user['is_admin'] = True | |
80 | user.save() | |
81 | print 'The user is now Admin' | |
82 | else: | |
83 | print 'The user doesn\'t exist' | |
96108ea2 AV |
84 | |
85 | ||
86 | def changepw_parser_setup(subparser): | |
87 | subparser.add_argument( | |
8781ddb5 | 88 | 'username', |
96108ea2 AV |
89 | help="Username used to login") |
90 | subparser.add_argument( | |
8781ddb5 | 91 | 'password', |
96108ea2 AV |
92 | help="Your NEW supersecret word to login") |
93 | subparser.add_argument( | |
94 | '-cf', '--conf_file', default='mediagoblin.ini', | |
95 | help="Config file used to set up environment") | |
96 | ||
97 | ||
98 | def changepw(args): | |
8781ddb5 | 99 | commands_util.setup_app(args) |
96108ea2 | 100 | |
8781ddb5 | 101 | db = mg_globals.database |
96108ea2 | 102 | |
8781ddb5 CAW |
103 | user = db.User.one({'username':unicode(args.username.lower())}) |
104 | if user: | |
105 | user['pw_hash'] = auth_lib.bcrypt_gen_password_hash(args.password) | |
106 | user.save() | |
107 | print 'Password successfully changed' | |
108 | else: | |
109 | print 'The user doesn\'t exist' | |
96108ea2 | 110 |