Author: justi9
Date: 2008-02-27 15:10:18 -0500 (Wed, 27 Feb 2008)
New Revision: 1731
Modified:
mgmt/cumin/bin/cumin-admin
Log:
Check that the user name is unique
Modified: mgmt/cumin/bin/cumin-admin
===================================================================
--- mgmt/cumin/bin/cumin-admin 2008-02-27 19:37:37 UTC (rev 1730)
+++ mgmt/cumin/bin/cumin-admin 2008-02-27 20:10:18 UTC (rev 1731)
@@ -7,6 +7,7 @@
from random import sample
from crypt import crypt
from mint import MintDatabase, ConsoleUser
+from psycopg2 import IntegrityError
from cumin.util import *
@@ -90,15 +91,22 @@
print "Error: no user name given"
usage()
+ name = args[1]
+
+ if ConsoleUser.selectBy(name=name).count():
+ print "Error: a user called '%s' already exists" % name
+ sys.exit(1)
+
password = getpass()
-
chs = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
- ch0, ch1 = sample(chs, 2)
+ crypted = crypt(password, "".join(sample(chs, 2)))
- user = ConsoleUser()
- user.name = args[1]
- user.password = crypt(password, ch0 + ch1)
- user.syncUpdate()
+ try:
+ ConsoleUser(name=name, password=crypted)
+ except IntegrityError:
+ print "Error: a user called '%s' already exists" % name
+ sys.exit(1)
+
elif command == "remove-user":
if force:
if len(args) != 2:
Show replies by date