1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 Free Software Foundation, Inc
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.
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.
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/>.
17 from mediagoblin
.gmg_commands
import util
as commands_util
18 from mediagoblin
.auth
import lib
as auth_lib
19 from mediagoblin
import mg_globals
22 def adduser_parser_setup(subparser
):
23 subparser
.add_argument(
25 help="Username used to login")
26 subparser
.add_argument(
28 help="Your supersecret word to login")
29 subparser
.add_argument(
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")
38 #TODO: Lets trust admins this do not validate Emails :)
39 commands_util
.setup_app(args
)
41 db
= mg_globals
.database
42 users_with_username
= \
44 'username': args
.username
.lower()
47 if users_with_username
:
48 print u
'Sorry, a user with that name already exists.'
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
)
56 entry
['status'] = u
'active'
57 entry
['email_verified'] = True
58 entry
.save(validate
=True)
60 print "User created (and email marked as verified)"
63 def makeadmin_parser_setup(subparser
):
64 subparser
.add_argument(
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")
73 commands_util
.setup_app(args
)
75 db
= mg_globals
.database
77 user
= db
.User
.one({'username':unicode(args
.username
.lower())})
79 user
['is_admin'] = True
81 print 'The user is now Admin'
83 print 'The user doesn\'t exist'
86 def changepw_parser_setup(subparser
):
87 subparser
.add_argument(
89 help="Username used to login")
90 subparser
.add_argument(
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")
99 commands_util
.setup_app(args
)
101 db
= mg_globals
.database
103 user
= db
.User
.one({'username':unicode(args
.username
.lower())})
105 user
['pw_hash'] = auth_lib
.bcrypt_gen_password_hash(args
.password
)
107 print 'Password successfully changed'
109 print 'The user doesn\'t exist'