1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
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
import auth
19 from mediagoblin
import mg_globals
21 def adduser_parser_setup(subparser
):
22 subparser
.add_argument(
24 help="Username used to login")
25 subparser
.add_argument(
27 help="Your supersecret word to login, beware of storing it in bash history")
28 subparser
.add_argument(
30 help="Email to receive notifications")
34 #TODO: Lets trust admins this do not validate Emails :)
35 commands_util
.setup_app(args
)
37 args
.username
= commands_util
.prompt_if_not_set(args
.username
, "Username:")
38 args
.password
= commands_util
.prompt_if_not_set(args
.password
, "Password:",True)
39 args
.email
= commands_util
.prompt_if_not_set(args
.email
, "Email:")
41 db
= mg_globals
.database
42 users_with_username
= \
43 db
.User
.query
.filter_by(
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
.gen_password_hash(args
.password
)
56 entry
.status
= u
'active'
57 entry
.email_verified
= 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")
70 commands_util
.setup_app(args
)
72 db
= mg_globals
.database
74 user
= db
.User
.query
.filter_by(
75 username
=unicode(args
.username
.lower())).one()
79 print 'The user is now Admin'
81 print 'The user doesn\'t exist'
84 def changepw_parser_setup(subparser
):
85 subparser
.add_argument(
87 help="Username used to login")
88 subparser
.add_argument(
90 help="Your NEW supersecret word to login")
94 commands_util
.setup_app(args
)
96 db
= mg_globals
.database
98 user
= db
.User
.query
.filter_by(
99 username
=unicode(args
.username
.lower())).one()
101 user
.pw_hash
= auth
.gen_password_hash(args
.password
)
103 print 'Password successfully changed'
105 print 'The user doesn\'t exist'