Mercurial > libervia-backend
comparison src/plugins/plugin_misc_account.py @ 1727:68e498b3367e
reverted revision 2ebe66a96d05
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 08 Dec 2015 16:55:54 +0100 |
parents | 2ebe66a96d05 |
children | 9037161e28f0 |
comparison
equal
deleted
inserted
replaced
1726:2ebe66a96d05 | 1727:68e498b3367e |
---|---|
25 from sat.memory.memory import Sessions | 25 from sat.memory.memory import Sessions |
26 from sat.memory.crypto import PasswordHasher | 26 from sat.memory.crypto import PasswordHasher |
27 from sat.core.constants import Const as C | 27 from sat.core.constants import Const as C |
28 | 28 |
29 from twisted.internet import reactor, defer, protocol | 29 from twisted.internet import reactor, defer, protocol |
30 from twisted.words.protocols.jabber import jid | |
31 from twisted.python.procutils import which | 30 from twisted.python.procutils import which |
32 from twisted.python.failure import Failure | 31 from twisted.python.failure import Failure |
33 from twisted.mail.smtp import sendmail | 32 from twisted.mail.smtp import sendmail |
34 from os.path import join, dirname | 33 from os.path import join, dirname |
35 from email.mime.text import MIMEText | 34 from email.mime.text import MIMEText |
60 "admin_email": "admin@example.net", | 59 "admin_email": "admin@example.net", |
61 "new_account_server": "localhost", | 60 "new_account_server": "localhost", |
62 "new_account_domain": "example.net", | 61 "new_account_domain": "example.net", |
63 "prosody_path": None, # prosody path (where prosodyctl will be executed from), or None to automaticaly find it | 62 "prosody_path": None, # prosody path (where prosodyctl will be executed from), or None to automaticaly find it |
64 "prosodyctl": "prosodyctl", | 63 "prosodyctl": "prosodyctl", |
65 "reserved_list": ['libervia'], # profiles which can't be used | 64 "reserved_list": ['libervia'] # profiles which can't be used |
66 "auto_add_contacts": ['salut-a-toi@libervia.org'], | |
67 } | 65 } |
68 | 66 |
69 | 67 |
70 class PasswordsMatchingError(Exception): | 68 class PasswordsMatchingError(Exception): |
71 pass | 69 pass |
168 #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 |
169 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)] |
170 return ''.join([random.choice(charset) for i in range(15)]) | 168 return ''.join([random.choice(charset) for i in range(15)]) |
171 | 169 |
172 def _registerAccount(self, email, password, profile): | 170 def _registerAccount(self, email, password, profile): |
173 d = self.registerAccount(email, password, None, profile) | 171 return self.registerAccount(email, password, None, profile) |
174 d.addCallback(lambda dummy: self.autoAddContacts(password, profile)) | |
175 return d | |
176 | 172 |
177 def registerAccount(self, email, password, jid_s, profile): | 173 def registerAccount(self, email, password, jid_s, profile): |
178 """Register a new profile and its associated XMPP account. | 174 """Register a new profile and its associated XMPP account. |
179 | 175 |
180 @param email (unicode): where to send to confirmation email to | 176 @param email (unicode): where to send to confirmation email to |
228 d.addCallback(lambda dummy: self.host.memory.startSession(password, profile)) | 224 d.addCallback(lambda dummy: self.host.memory.startSession(password, profile)) |
229 d.addCallback(setParams) | 225 d.addCallback(setParams) |
230 d.addCallback(lambda dummy: self.host.memory.stopSession(profile)) | 226 d.addCallback(lambda dummy: self.host.memory.stopSession(profile)) |
231 d.addErrback(removeProfile) | 227 d.addErrback(removeProfile) |
232 return d | 228 return d |
233 | |
234 def autoAddContacts(self, password, profile): | |
235 """Auto-add some roster contacts after the profile creation. | |
236 | |
237 @param password (unicode): XMPP account password | |
238 """ | |
239 contacts = self.getConfig('auto_add_contacts') | |
240 if not contacts: | |
241 return | |
242 | |
243 def addContact(was_connected, contacts): | |
244 for contact in contacts: | |
245 d = self.host.addContact(contact, profile) | |
246 if not was_connected: | |
247 d.addCallback(lambda dummy: self.host.disconnect(profile)) | |
248 | |
249 try: | |
250 contacts_jid = [jid.JID(contact) for contact in contacts] | |
251 except (RuntimeError, jid.InvalidFormat, AttributeError): | |
252 log.error("Invalid JIDs list: %s" % ", ".join(contacts)) | |
253 else: | |
254 d = self.host.asyncConnect(profile, password, max_retries=0) | |
255 d.addCallback(addContact, contacts_jid) | |
256 | 229 |
257 def sendEmails(self, email, jid_s, password, profile): | 230 def sendEmails(self, email, jid_s, password, profile): |
258 # time to send the email | 231 # time to send the email |
259 | 232 |
260 _email_host = self.getConfig('email_server') | 233 _email_host = self.getConfig('email_server') |
573 def removeProfile(failure): # profile has been successfully created but the XMPP credentials are wrong! | 546 def removeProfile(failure): # profile has been successfully created but the XMPP credentials are wrong! |
574 log.debug("Removing previously auto-created profile: %s" % failure.getErrorMessage()) | 547 log.debug("Removing previously auto-created profile: %s" % failure.getErrorMessage()) |
575 self.host.memory.asyncDeleteProfile(jid_s) | 548 self.host.memory.asyncDeleteProfile(jid_s) |
576 raise failure | 549 raise failure |
577 | 550 |
578 d.addCallback(self.autoAddContacts(password, jid_s)) | |
579 d.addErrback(removeProfile) | 551 d.addErrback(removeProfile) |
580 return d | 552 return d |