264
264
# Do not return passhash when reading from the DB
265
265
login_getfields = login_fields - frozenset(["passhash"])
267
def create_user(self, dict, dry=False):
267
def create_user(self, dry=False, **kwargs):
268
268
"""Creates a user login entry in the database.
269
dict is a dictionary mapping string keys to values. The string keys
269
All user fields are to be passed as args. The argument names
270
270
are the field names of the "login" table of the DB schema.
271
271
However, instead of supplying a "passhash", you must supply a
272
"password", which will be hashed internally.
272
"password" argument, which will be hashed internally.
273
273
Also "state" must not given explicitly; it is implicitly set to
275
275
Raises an exception if the user already exists, or the dict contains
276
276
invalid keys or is missing required keys.
278
if 'passhash' in dict:
279
raise DBException("Supplied dictionary contains passhash (invalid).")
278
if 'passhash' in kwargs:
279
raise DBException("Supplied arguments include passhash (invalid).")
280
280
# Make a copy of the dict. Change password to passhash (hashing it),
281
281
# and set 'state' to "no_agreement".
282
dict = copy.copy(dict)
283
dict['passhash'] = _passhash(dict['password'])
285
dict['state'] = "no_agreement"
282
kwargs = copy.copy(kwargs)
283
kwargs['passhash'] = _passhash(kwargs['password'])
284
del kwargs['password']
285
kwargs['state'] = "no_agreement"
286
286
# Execute the query.
287
return self.insert(dict, "login", self.login_fields, dry=dry)
287
return self.insert(kwargs, "login", self.login_fields, dry=dry)
289
def update_user(self, login, dict, dry=False):
289
def update_user(self, login, dry=False, **kwargs):
290
290
"""Updates fields of a particular user. login is the name of the user
291
291
to update. The dict contains the fields which will be modified, and
292
292
their new values. If any value is omitted from the dict, it does not
300
300
that the user knows the existing password before calling this function
303
if 'passhash' in dict:
304
raise DBException("Supplied dictionary contains passhash (invalid).")
305
if "password" in dict:
306
dict = copy.copy(dict)
307
dict['passhash'] = _passhash(dict['password'])
309
return self.update({"login": login}, dict, "login", self.login_fields,
310
self.login_primary, ["login", "studentid"], dry=dry)
303
if 'passhash' in kwargs:
304
raise DBException("Supplied arguments include passhash (invalid).")
305
if "password" in kwargs:
306
kwargs = copy.copy(kwargs)
307
kwargs['passhash'] = _passhash(kwargs['password'])
308
del kwargs['password']
309
return self.update({"login": login}, kwargs, "login",
310
self.login_fields, self.login_primary, ["login", "studentid"],
312
313
def get_user(self, login, dry=False):
313
314
"""Given a login, returns a dictionary of the user's DB fields,