40 self._passwd = password |
40 self._passwd = password |
41 self._setAddr() |
41 self._setAddr() |
42 self._exists() |
42 self._exists() |
43 if self._isAlias(): |
43 if self._isAlias(): |
44 raise VMMAccountException( |
44 raise VMMAccountException( |
45 (_('There is already an alias with address »%s«') % address, |
45 (_(u'There is already an alias with address »%s«') % address, |
46 ERR.ALIAS_EXISTS)) |
46 ERR.ALIAS_EXISTS)) |
47 |
47 |
48 def _exists(self): |
48 def _exists(self): |
49 dbc = self._dbh.cursor() |
49 dbc = self._dbh.cursor() |
50 dbc.execute("SELECT uid, mid, tid FROM users \ |
50 dbc.execute("SELECT uid, mid, tid FROM users \ |
72 def _setAddr(self): |
72 def _setAddr(self): |
73 self._localpart, d = self._addr.split('@') |
73 self._localpart, d = self._addr.split('@') |
74 dom = Domain(self._dbh, d) |
74 dom = Domain(self._dbh, d) |
75 self._gid = dom.getID() |
75 self._gid = dom.getID() |
76 if self._gid == 0: |
76 if self._gid == 0: |
77 #raise VMMAccountException(("Domain »%s« doesn't exist." % d, |
77 raise VMMAccountException((_(u"Domain »%s« doesn't exist.") % d, |
78 errmsg = _('Domain »%s« does not exists.') |
78 ERR.NO_SUCH_DOMAIN)) |
79 raise VMMAccountException((errmsg % d, ERR.NO_SUCH_DOMAIN)) |
|
80 self._base = dom.getDir() |
79 self._base = dom.getDir() |
81 self._tid = dom.getTransportID() |
80 self._tid = dom.getTransportID() |
82 |
81 |
83 def _setID(self): |
82 def _setID(self): |
84 dbc = self._dbh.cursor() |
83 dbc = self._dbh.cursor() |
92 |
91 |
93 def _switchState(self, state, service): |
92 def _switchState(self, state, service): |
94 if not isinstance(state, bool): |
93 if not isinstance(state, bool): |
95 return False |
94 return False |
96 if not service in ['smtp', 'pop3', 'imap', 'managesieve', 'all', None]: |
95 if not service in ['smtp', 'pop3', 'imap', 'managesieve', 'all', None]: |
97 raise VMMAccountException(("Unknown service »%s«" % service, |
96 raise VMMAccountException((_(u"Unknown service »%s«") % service, |
98 ERR.UNKNOWN_SERVICE)) |
97 ERR.UNKNOWN_SERVICE)) |
99 if self._uid < 1: |
98 if self._uid < 1: |
100 raise VMMAccountException(("Account doesn't exists", |
99 raise VMMAccountException((_("Account doesn't exists"), |
101 ERR.NO_SUCH_ACCOUNT)) |
100 ERR.NO_SUCH_ACCOUNT)) |
102 dbc = self._dbh.cursor() |
101 dbc = self._dbh.cursor() |
103 if service in ['smtp', 'pop3', 'imap', 'managesieve']: |
102 if service in ['smtp', 'pop3', 'imap', 'managesieve']: |
104 dbc.execute( |
103 dbc.execute( |
105 "UPDATE users SET %s=%s WHERE local_part='%s' AND gid=%s" |
104 "UPDATE users SET %s=%s WHERE local_part='%s' AND gid=%s" |
144 self._localpart, self._passwd, self._uid, self._gid, self._mid, |
143 self._localpart, self._passwd, self._uid, self._gid, self._mid, |
145 self._tid, smtp, pop3, imap, managesieve) |
144 self._tid, smtp, pop3, imap, managesieve) |
146 self._dbh.commit() |
145 self._dbh.commit() |
147 dbc.close() |
146 dbc.close() |
148 else: |
147 else: |
149 raise VMMAccountException(('Account already exists.', |
148 raise VMMAccountException((_('Account already exists.'), |
150 ERR.ACCOUNT_EXISTS)) |
149 ERR.ACCOUNT_EXISTS)) |
151 |
150 |
152 def modify(self, what, value): |
151 def modify(self, what, value): |
153 if self._uid == 0: |
152 if self._uid == 0: |
154 raise VMMAccountException(("Account doesn't exists", |
153 raise VMMAccountException((_("Account doesn't exists"), |
155 ERR.NO_SUCH_ACCOUNT)) |
154 ERR.NO_SUCH_ACCOUNT)) |
156 if what not in ['name', 'password', 'transport']: |
155 if what not in ['name', 'password', 'transport']: |
157 return False |
156 return False |
158 dbc = self._dbh.cursor() |
157 dbc = self._dbh.cursor() |
159 if what == 'password': |
158 if what == 'password': |
176 managesieve FROM users WHERE local_part=%s AND gid=%s", |
175 managesieve FROM users WHERE local_part=%s AND gid=%s", |
177 self._localpart, self._gid) |
176 self._localpart, self._gid) |
178 info = dbc.fetchone() |
177 info = dbc.fetchone() |
179 dbc.close() |
178 dbc.close() |
180 if info is None: |
179 if info is None: |
181 raise VMMAccountException(("Account doesn't exists", |
180 raise VMMAccountException((_("Account doesn't exists"), |
182 ERR.NO_SUCH_ACCOUNT)) |
181 ERR.NO_SUCH_ACCOUNT)) |
183 else: |
182 else: |
184 keys = ['name', 'uid', 'gid', 'maildir', 'transport', 'smtp', |
183 keys = ['name', 'uid', 'gid', 'maildir', 'transport', 'smtp', |
185 'pop3', 'imap', 'managesieve'] |
184 'pop3', 'imap', 'managesieve'] |
186 info = dict(zip(keys, info)) |
185 info = dict(zip(keys, info)) |
204 self._gid, self._localpart) |
203 self._gid, self._localpart) |
205 if dbc.rowcount > 0: |
204 if dbc.rowcount > 0: |
206 self._dbh.commit() |
205 self._dbh.commit() |
207 dbc.close() |
206 dbc.close() |
208 else: |
207 else: |
209 raise VMMAccountException(("Account doesn't exists", |
208 raise VMMAccountException((_("Account doesn't exists"), |
210 ERR.NO_SUCH_ACCOUNT)) |
209 ERR.NO_SUCH_ACCOUNT)) |
211 |
210 |
212 |
211 |
213 def getAccountByID(uid, dbh): |
212 def getAccountByID(uid, dbh): |
214 try: |
213 try: |
215 uid = long(uid) |
214 uid = long(uid) |
216 except ValueError: |
215 except ValueError: |
217 raise VMMAccountException(('uid must be an int/long.', |
216 raise VMMAccountException((_('uid must be an int/long.'), |
218 ERR.INVALID_AGUMENT)) |
217 ERR.INVALID_AGUMENT)) |
219 if uid < 1: |
218 if uid < 1: |
220 raise VMMAccountException(('uid must be greater than 0.', |
219 raise VMMAccountException((_('uid must be greater than 0.'), |
221 ERR.INVALID_AGUMENT)) |
220 ERR.INVALID_AGUMENT)) |
222 dbc = dbh.cursor() |
221 dbc = dbh.cursor() |
223 dbc.execute("SELECT local_part||'@'||domains.domainname AS address, uid,\ |
222 dbc.execute("SELECT local_part||'@'||domains.domainname AS address, uid,\ |
224 gid FROM users LEFT JOIN domains USING(gid) WHERE uid=%s", uid) |
223 gid FROM users LEFT JOIN domains USING(gid) WHERE uid=%s", uid) |
225 info = dbc.fetchone() |
224 info = dbc.fetchone() |
226 dbc.close() |
225 dbc.close() |
227 if info is None: |
226 if info is None: |
228 raise VMMAccountException(("Account doesn't exists", |
227 raise VMMAccountException((_("Account doesn't exists"), |
229 ERR.NO_SUCH_ACCOUNT)) |
228 ERR.NO_SUCH_ACCOUNT)) |
230 keys = ['address', 'uid', 'gid'] |
229 keys = ['address', 'uid', 'gid'] |
231 info = dict(zip(keys, info)) |
230 info = dict(zip(keys, info)) |
232 return info |
231 return info |
233 |
232 |