VirtualMailManager/account.py
branchv0.7.x
changeset 726 46b37d7c848a
parent 711 2a75058fc064
child 735 ddcad86f7386
equal deleted inserted replaced
725:300b76de5ad0 726:46b37d7c848a
   259         self._new = False
   259         self._new = False
   260 
   260 
   261     def modify(self, field, value):
   261     def modify(self, field, value):
   262         """Update the Account's *field* to the new *value*.
   262         """Update the Account's *field* to the new *value*.
   263 
   263 
   264         Possible values for *field* are: 'name', 'password', 'note'.
   264         Possible values for *field* are: 'name' and 'note'.
   265 
   265 
   266         Arguments:
   266         Arguments:
   267 
   267 
   268         `field` : basestring
   268         `field` : str
   269           The attribute name: 'name', 'password' or 'note'
   269           The attribute name: 'name', or 'note'
   270         `value` : basestring
   270         `value` : str
   271           The new value of the attribute.
   271           The new value of the attribute.
   272         """
   272         """
   273         if field not in ('name', 'password', 'note'):
   273         if field not in ('name', 'note'):
   274             raise AErr(_("Unknown field: '%s'") % field, INVALID_ARGUMENT)
   274             raise AErr(_("Unknown field: '%s'") % field, INVALID_ARGUMENT)
   275         self._chk_state()
   275         self._chk_state()
   276         dbc = self._dbh.cursor()
   276         dbc = self._dbh.cursor()
   277         if field == 'password':
   277         dbc.execute('UPDATE users SET %s = %%s WHERE uid = %%s' % field,
   278             dbc.execute('UPDATE users SET passwd = %s WHERE uid = %s',
   278                     (value, self._uid))
   279                         (pwhash(value, user=self._addr), self._uid))
   279         if dbc.rowcount > 0:
   280         else:
   280             self._dbh.commit()
   281             dbc.execute('UPDATE users SET %s = %%s WHERE uid = %%s' % field,
   281         dbc.close()
   282                         (value, self._uid))
   282 
       
   283     def update_password(self, password, scheme=None):
       
   284         """Update the Account's password.
       
   285 
       
   286         The given *password* will be hashed using password.pwhash.
       
   287         When no *scheme* is specified, the configured scheme
       
   288         (misc.password_scheme) will be used.
       
   289 
       
   290         Arguments:
       
   291 
       
   292         `password' : str
       
   293           The Account's new plain text password
       
   294         `scheme' : str
       
   295           The password scheme used for password hashing; default None
       
   296         """
       
   297         self._chk_state()
       
   298         dbc = self._dbh.cursor()
       
   299         dbc.execute('UPDATE users SET passwd = %s WHERE uid = %s',
       
   300                     (pwhash(password, scheme, self._addr), self.uid))
   283         if dbc.rowcount > 0:
   301         if dbc.rowcount > 0:
   284             self._dbh.commit()
   302             self._dbh.commit()
   285         dbc.close()
   303         dbc.close()
   286 
   304 
   287     def update_quotalimit(self, quotalimit):
   305     def update_quotalimit(self, quotalimit):