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

« back to all changes in this revision

Viewing changes to lib/common/db.py

  • Committer: mattgiuca
  • Date: 2008-02-15 03:40:10 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:469
db.py: Changed interface (again) to user management methods: Changed the dict
argument to **kwargs.
(Did not do this for the low-level db methods, as all accesses to them should
just be passing a dict anyway).

Show diffs side-by-side

added added

removed removed

Lines of Context:
264
264
    # Do not return passhash when reading from the DB
265
265
    login_getfields = login_fields - frozenset(["passhash"])
266
266
 
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
274
274
        "no_agreement".
275
275
        Raises an exception if the user already exists, or the dict contains
276
276
        invalid keys or is missing required keys.
277
277
        """
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'])
284
 
        del 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)
288
288
 
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
301
301
        with a new one.
302
302
        """
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'])
308
 
            del 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"],
 
311
            dry=dry)
311
312
 
312
313
    def get_user(self, login, dry=False):
313
314
        """Given a login, returns a dictionary of the user's DB fields,