VirtualMailManager/Account.py
changeset 17 fe9be0081e5f
parent 9 e3d3dbeb5b84
child 19 bf9a03c476fc
equal deleted inserted replaced
16:3388b96fd3ed 17:fe9be0081e5f
   118         if self._uid < 1:
   118         if self._uid < 1:
   119             self._prepare(maillocation)
   119             self._prepare(maillocation)
   120             dbc = self._dbh.cursor()
   120             dbc = self._dbh.cursor()
   121             dbc.execute("""INSERT INTO users (local_part, passwd, uid, gid,\
   121             dbc.execute("""INSERT INTO users (local_part, passwd, uid, gid,\
   122  mid, tid) VALUES (%s, %s, %s, %s, %s, %s)""", self._localpart, self._passwd,
   122  mid, tid) VALUES (%s, %s, %s, %s, %s, %s)""", self._localpart, self._passwd,
   123                     self._uid, self._gid, self._mid, self._tid )
   123                     self._uid, self._gid, self._mid, self._tid)
   124             self._dbh.commit()
   124             self._dbh.commit()
   125             dbc.close()
   125             dbc.close()
   126         else:
   126         else:
   127             raise VMMAccountException(('Account already exists.',
   127             raise VMMAccountException(('Account already exists.',
   128                 ERR.ACCOUNT_EXISTS))
   128                 ERR.ACCOUNT_EXISTS))
   129        
   129        
   130     def modify(self, what, value):
   130     def modify(self, what, value):
   131         if self._uid == 0:
   131         if self._uid == 0:
   132             raise VMMAccountException(("Account doesn't exists",
   132             raise VMMAccountException(("Account doesn't exists",
   133                 ERR.NO_SUCH_ACCOUNT))
   133                 ERR.NO_SUCH_ACCOUNT))
   134         if what not in ['name', 'password']:
   134         if what not in ['name', 'password', 'transport']:
   135             return False
   135             return False
   136         dbc = self._dbh.cursor()
   136         dbc = self._dbh.cursor()
   137         if what == 'password':
   137         if what == 'password':
   138             dbc.execute("UPDATE users SET passwd=%s WHERE local_part=%s AND\
   138             dbc.execute("UPDATE users SET passwd=%s WHERE local_part=%s AND\
   139  gid=%s", value, self._localpart, self._gid)
   139  gid=%s", value, self._localpart, self._gid)
       
   140         elif what == 'transport':
       
   141             self._tid = Transport(self._dbh, transport=value).getID()
       
   142             dbc.execute("UPDATE users SET tid=%s WHERE local_part=%s AND\
       
   143  gid=%s", self._tid, self._localpart, self._gid)
   140         else:
   144         else:
   141             dbc.execute("UPDATE users SET name=%s WHERE local_part=%s AND\
   145             dbc.execute("UPDATE users SET name=%s WHERE local_part=%s AND\
   142  gid=%s", value, self._localpart, self._gid)
   146  gid=%s", value, self._localpart, self._gid)
   143         if dbc.rowcount > 0:
   147         if dbc.rowcount > 0:
   144             self._dbh.commit()
   148             self._dbh.commit()