322
319
# USER MANAGEMENT FUNCTIONS #
324
321
login_primary = frozenset(["login"])
325
login_fields_list = [
326
"login", "passhash", "state", "unixid", "email", "nick", "fullname",
327
"rolenm", "studentid", "acct_exp", "pass_exp", "last_login", "svn_pass"
329
login_fields = frozenset(login_fields_list)
331
def create_user(self, user_obj=None, dry=False, **kwargs):
332
"""Creates a user login entry in the database.
333
Two ways to call this - passing a user object, or passing
334
all fields as separate arguments.
336
Either pass a "user_obj" as the first argument (in which case other
337
fields will be ignored), or pass all fields as arguments.
339
All user fields are to be passed as args. The argument names
340
are the field names of the "login" table of the DB schema.
341
However, instead of supplying a "passhash", you must supply a
342
"password" argument, which will be hashed internally.
343
Also "state" must not given explicitly; it is implicitly set to
345
Raises an exception if the user already exists, or the dict contains
346
invalid keys or is missing required keys.
348
if 'passhash' in kwargs:
349
raise DBException("Supplied arguments include passhash (invalid) (1).")
350
# Make a copy of the dict. Change password to passhash (hashing it),
351
# and set 'state' to "no_agreement".
354
fields = copy.copy(kwargs)
356
# Use the user object
357
fields = dict(user_obj)
358
if 'password' in fields:
359
fields['passhash'] = _passhash(fields['password'])
360
del fields['password']
362
# Convert role to rolenm
363
fields['rolenm'] = str(user_obj.role)
366
fields['state'] = "no_agreement"
367
# else, we'll trust the user, but it SHOULD be "no_agreement"
368
# (We can't change it because then the user object would not
370
if 'local_password' in fields:
371
del fields['local_password']
373
return self.insert(fields, "login", self.login_fields, dry=dry)
375
323
def get_user_loginid(self, login, dry=False):
376
324
"""Given a login, returns the integer loginid for this user.