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
.auth
import lib
as auth_lib
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
= \
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")
70 commands_util
.setup_app(args
)
72 db
= mg_globals
.database
74 user
= db
.User
.one({'username': unicode(args
.username
.lower())})
78 print 'The user is now Admin'
80 print 'The user doesn\'t exist'
83 def changepw_parser_setup(subparser
):
84 subparser
.add_argument(
86 help="Username used to login")
87 subparser
.add_argument(
89 help="Your NEW supersecret word to login")
93 commands_util
.setup_app(args
)
95 db
= mg_globals
.database
97 user
= db
.User
.one({'username': unicode(args
.username
.lower())})
99 user
.pw_hash
= auth_lib
.bcrypt_gen_password_hash(args
.password
)
101 print 'Password successfully changed'
103 print 'The user doesn\'t exist'