Mercurial > libervia-backend
comparison src/plugins/plugin_misc_account.py @ 1696:9a7a27c44611
plugin account: fixed profile creation: session is started to set the connection parameters, then stopped
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 27 Nov 2015 16:54:11 +0100 |
parents | cec204c6360c |
children | 94c450972346 |
comparison
equal
deleted
inserted
replaced
1695:5a93f13c1e76 | 1696:9a7a27c44611 |
---|---|
157 def getConfig(self, name): | 157 def getConfig(self, name): |
158 return self.host.memory.getConfig(CONFIG_SECTION, name, default_conf[name]) | 158 return self.host.memory.getConfig(CONFIG_SECTION, name, default_conf[name]) |
159 | 159 |
160 def generatePassword(self): | 160 def generatePassword(self): |
161 """Generate a password with random characters. | 161 """Generate a password with random characters. |
162 | 162 |
163 @return unicode | 163 @return unicode |
164 """ | 164 """ |
165 random.seed() | 165 random.seed() |
166 #charset = [chr(i) for i in range(0x21,0x7F)] #XXX: this charset seems to have some issues with openfire | 166 #charset = [chr(i) for i in range(0x21,0x7F)] #XXX: this charset seems to have some issues with openfire |
167 charset = [chr(i) for i in range(0x30,0x3A) + range(0x41,0x5B) + range (0x61,0x7B)] | 167 charset = [chr(i) for i in range(0x30,0x3A) + range(0x41,0x5B) + range (0x61,0x7B)] |
173 def registerAccount(self, email, password, jid_s, profile): | 173 def registerAccount(self, email, password, jid_s, profile): |
174 """Register a new profile and its associated XMPP account. | 174 """Register a new profile and its associated XMPP account. |
175 | 175 |
176 @param email (unicode): where to send to confirmation email to | 176 @param email (unicode): where to send to confirmation email to |
177 @param password (unicode): password chosen by the user | 177 @param password (unicode): password chosen by the user |
178 while be used for profile *and* XMPP account | |
178 @param jid_s (unicode): JID to re-use or to register: | 179 @param jid_s (unicode): JID to re-use or to register: |
179 - non empty value: bind this JID to the new sat profile | 180 - non empty value: bind this JID to the new sat profile |
180 - None or "": register a new JID on the local XMPP server | 181 - None or "": register a new JID on the local XMPP server |
181 @param profile | 182 @param profile |
182 @return Deferred | 183 @return Deferred |
183 """ | 184 """ |
184 if not password or not profile: | 185 if not password or not profile: |
185 raise exceptions.DataError | 186 raise exceptions.DataError |
186 | 187 |
187 if profile.lower() in self.getConfig('reserved_list'): | 188 if profile.lower() in self.getConfig('reserved_list'): |
212 d.addCallback(lambda dummy: self.sendEmails(email, jid_s, password, profile)) | 213 d.addCallback(lambda dummy: self.sendEmails(email, jid_s, password, profile)) |
213 | 214 |
214 def setParams(dummy): | 215 def setParams(dummy): |
215 self.host.memory.setParam("JabberID", jid_s, "Connection", profile_key=profile) | 216 self.host.memory.setParam("JabberID", jid_s, "Connection", profile_key=profile) |
216 d = self.host.memory.setParam("Password", password, "Connection", profile_key=profile) | 217 d = self.host.memory.setParam("Password", password, "Connection", profile_key=profile) |
217 return d.addCallback(lambda dummy: self.host.memory.auth_sessions.profileDelUnique(profile)) | 218 return d |
218 | 219 |
219 def removeProfile(failure): | 220 def removeProfile(failure): |
220 self.host.memory.asyncDeleteProfile(profile) | 221 self.host.memory.asyncDeleteProfile(profile) |
221 return failure | 222 return failure |
222 | 223 |
224 d.addCallback(lambda dummy: self.host.memory.startSession(password, profile)) | |
223 d.addCallback(setParams) | 225 d.addCallback(setParams) |
226 d.addCallback(lambda dummy: self.host.memory.stopSession(profile)) | |
224 d.addErrback(removeProfile) | 227 d.addErrback(removeProfile) |
225 return d | 228 return d |
226 | 229 |
227 def sendEmails(self, email, jid_s, password, profile): | 230 def sendEmails(self, email, jid_s, password, profile): |
228 # time to send the email | 231 # time to send the email |
513 d.addCallbacks(deleted, errback) | 516 d.addCallbacks(deleted, errback) |
514 return d | 517 return d |
515 | 518 |
516 def asyncConnectWithXMPPCredentials(self, jid_s, password): | 519 def asyncConnectWithXMPPCredentials(self, jid_s, password): |
517 """Create and connect a new SàT profile using the given XMPP credentials. | 520 """Create and connect a new SàT profile using the given XMPP credentials. |
518 | 521 |
519 Re-use given JID and XMPP password for the profile name and profile password. | 522 Re-use given JID and XMPP password for the profile name and profile password. |
520 @param jid_s (unicode): JID | 523 @param jid_s (unicode): JID |
521 @param password (unicode): XMPP password | 524 @param password (unicode): XMPP password |
522 @return Deferred(bool) | 525 @return Deferred(bool) |
523 @raise exceptions.PasswordError, exceptions.ConflictError | 526 @raise exceptions.PasswordError, exceptions.ConflictError |
524 """ | 527 """ |
525 try: # be sure that the profile doesn't exist yet | 528 try: # be sure that the profile doesn't exist yet |
526 self.host.memory.getProfileName(jid_s) | 529 self.host.memory.getProfileName(jid_s) |
527 except exceptions.ProfileUnknownError: | 530 except exceptions.ProfileUnknownError: |
528 pass | 531 pass |
534 d.addCallback(self.host.asyncConnect, password) | 537 d.addCallback(self.host.asyncConnect, password) |
535 | 538 |
536 def removeProfile(failure): # profile has been successfully created but the XMPP credentials are wrong! | 539 def removeProfile(failure): # profile has been successfully created but the XMPP credentials are wrong! |
537 log.debug("Removing previously auto-created profile: %s" % failure.getErrorMessage()) | 540 log.debug("Removing previously auto-created profile: %s" % failure.getErrorMessage()) |
538 self.host.memory.asyncDeleteProfile(jid_s) | 541 self.host.memory.asyncDeleteProfile(jid_s) |
539 raise failure | 542 raise failure |
540 | 543 |
541 d.addErrback(removeProfile) | 544 d.addErrback(removeProfile) |
542 return d | 545 return d |