VirtualMailManager/Account.py
branchv0.6.x
changeset 316 31d8931dc535
parent 306 504fd29b4712
equal deleted inserted replaced
315:81bccfd14355 316:31d8931dc535
    11 
    11 
    12 from VirtualMailManager.Domain import Domain
    12 from VirtualMailManager.Domain import Domain
    13 from VirtualMailManager.EmailAddress import EmailAddress
    13 from VirtualMailManager.EmailAddress import EmailAddress
    14 from VirtualMailManager.Transport import Transport
    14 from VirtualMailManager.Transport import Transport
    15 from VirtualMailManager.common import version_str
    15 from VirtualMailManager.common import version_str
    16 from VirtualMailManager.constants.ERROR import \
    16 from VirtualMailManager.constants import \
    17      ACCOUNT_EXISTS, ACCOUNT_MISSING_PASSWORD, ALIAS_PRESENT, \
    17      ACCOUNT_EXISTS, ACCOUNT_MISSING_PASSWORD, ALIAS_PRESENT, \
    18      INVALID_AGUMENT, INVALID_MAIL_LOCATION, NO_SUCH_ACCOUNT, NO_SUCH_DOMAIN, \
    18      INVALID_ARGUMENT, INVALID_MAIL_LOCATION, NO_SUCH_ACCOUNT, \
    19      UNKNOWN_SERVICE
    19      NO_SUCH_DOMAIN, UNKNOWN_SERVICE
    20 from VirtualMailManager.errors import AccountError as AErr
    20 from VirtualMailManager.errors import AccountError as AErr
    21 from VirtualMailManager.maillocation import MailLocation
    21 from VirtualMailManager.maillocation import MailLocation
    22 from VirtualMailManager.password import pwhash
    22 from VirtualMailManager.password import pwhash
    23 
    23 
    24 
    24 
   274           The attribute name: 'name', 'password' or 'transport'
   274           The attribute name: 'name', 'password' or 'transport'
   275         `value` : basestring
   275         `value` : basestring
   276           The new value of the attribute.
   276           The new value of the attribute.
   277         """
   277         """
   278         if field not in ('name', 'password', 'transport'):
   278         if field not in ('name', 'password', 'transport'):
   279             raise AErr(_(u"Unknown field: '%s'") % field, INVALID_AGUMENT)
   279             raise AErr(_(u"Unknown field: '%s'") % field, INVALID_ARGUMENT)
   280         self._chk_state()
   280         self._chk_state()
   281         dbc = self._dbh.cursor()
   281         dbc = self._dbh.cursor()
   282         if field == 'password':
   282         if field == 'password':
   283             dbc.execute('UPDATE users SET passwd = %s WHERE uid = %s',
   283             dbc.execute('UPDATE users SET passwd = %s WHERE uid = %s',
   284                         pwhash(value, user=self._addr), self._uid)
   284                         pwhash(value, user=self._addr), self._uid)
   400       a database connection for the database access.
   400       a database connection for the database access.
   401     """
   401     """
   402     try:
   402     try:
   403         uid = long(uid)
   403         uid = long(uid)
   404     except ValueError:
   404     except ValueError:
   405         raise AErr(_(u'UID must be an int/long.'), INVALID_AGUMENT)
   405         raise AErr(_(u'UID must be an int/long.'), INVALID_ARGUMENT)
   406     if uid < 1:
   406     if uid < 1:
   407         raise AErr(_(u'UID must be greater than 0.'), INVALID_AGUMENT)
   407         raise AErr(_(u'UID must be greater than 0.'), INVALID_ARGUMENT)
   408     dbc = dbh.cursor()
   408     dbc = dbh.cursor()
   409     dbc.execute("SELECT local_part||'@'|| domain_name.domainname AS address, "
   409     dbc.execute("SELECT local_part||'@'|| domain_name.domainname AS address, "
   410                 "uid, users.gid FROM users LEFT JOIN domain_name ON "
   410                 "uid, users.gid FROM users LEFT JOIN domain_name ON "
   411                 "(domain_name.gid = users.gid AND is_primary) WHERE uid = %s",
   411                 "(domain_name.gid = users.gid AND is_primary) WHERE uid = %s",
   412                 uid)
   412                 uid)