~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to bin/ivle-makeuser

  • Committer: me at id
  • Date: 2009-01-15 00:37:10 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:branches%2Fstorm:1141
ivle.database.User: Add an authenticate() method, and a hash_password()
     staticmethod to replace the auth functions in ivle.db.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
import os
32
32
import getopt
33
33
 
34
 
if os.getuid() != 0:
35
 
    print "Must run %s as root." % os.path.basename(sys.argv[0])
36
 
    sys.exit(1)
37
 
 
38
 
from ivle.database import get_store, User
39
 
from ivle.pulldown_subj import enrol_user
 
34
import ivle.makeuser
40
35
 
41
36
# Requireds and optionals will be used to display the usage message
42
37
# AND do argument processing
43
38
# The names here must correspond to the fields in the database.
44
 
requireds = ["login", "fullname"]
 
39
requireds = ["login", "fullname", "rolenm"]
45
40
optionals = [
46
41
    ('p', 'password', "Cleartext password for this user"),
47
42
    ('n', 'nick', "Display name (defaults to <fullname>)"),
59
54
        print t + (' ' * max(28 - len(t), 2)) + desc
60
55
    sys.exit(1)
61
56
 
 
57
if os.getuid() != 0:
 
58
    print "Must run %s as root." % os.path.basename(sys.argv[0])
 
59
    sys.exit(1)
 
60
 
62
61
shorts = ''.join([o[0] + ":" for o in optionals])
63
62
longs = [o[1] + "=" for o in optionals]
64
63
opts, args = getopt.gnu_getopt(sys.argv[1:], shorts, longs)
67
66
# Get the dictionary of fields from opts and args
68
67
user = {}
69
68
for i in range(0, len(requireds)):
70
 
    user[requireds[i]] = unicode(args[i])
 
69
    user[requireds[i]] = args[i]
71
70
for short, long, _ in optionals:
72
71
    try:
73
 
        user[long] = unicode(opts['-' + short])
 
72
        user[long] = opts['-' + short]
74
73
    except KeyError:
75
74
        try:
76
 
            user[long] = unicode(opts['--' + long])
 
75
            user[long] = opts['--' + long]
77
76
        except KeyError:
78
77
            pass
79
78
login = user['login']
80
79
if 'nick' not in user:
81
80
    user['nick'] = user['fullname']
82
81
 
83
 
store = get_store()
84
 
 
85
82
try:
86
83
    # Make the user's database entry
87
 
    userobj = User(**user)
88
 
    store.add(userobj)
89
 
    enrol_user(store, userobj)
90
 
    store.commit()
 
84
    ivle.makeuser.make_user_db(**user)
91
85
except Exception, message:
92
86
    print "Error: " + str(message)
93
87
    sys.exit(1)