plugin misc_account: auto add some contacts at profile creation
This commit is contained in:
parent
f3a5cb2a96
commit
9ab8ac9083
1 changed files with 30 additions and 2 deletions
|
|
@ -27,6 +27,7 @@ from sat.memory.crypto import PasswordHasher
|
|||
from sat.core.constants import Const as C
|
||||
|
||||
from twisted.internet import reactor, defer, protocol
|
||||
from twisted.words.protocols.jabber import jid
|
||||
from twisted.python.procutils import which
|
||||
from twisted.python.failure import Failure
|
||||
from twisted.mail.smtp import sendmail
|
||||
|
|
@ -61,7 +62,8 @@ default_conf = {"email_from": "NOREPLY@example.net",
|
|||
"new_account_domain": "example.net",
|
||||
"prosody_path": None, # prosody path (where prosodyctl will be executed from), or None to automaticaly find it
|
||||
"prosodyctl": "prosodyctl",
|
||||
"reserved_list": ['libervia'] # profiles which can't be used
|
||||
"reserved_list": ['libervia'], # profiles which can't be used
|
||||
"auto_add_contacts": ['salut-a-toi@libervia.org'],
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -168,7 +170,9 @@ class MiscAccount(object):
|
|||
return ''.join([random.choice(charset) for i in range(15)])
|
||||
|
||||
def _registerAccount(self, email, password, profile):
|
||||
return self.registerAccount(email, password, None, profile)
|
||||
d = self.registerAccount(email, password, None, profile)
|
||||
d.addCallback(lambda dummy: self.autoAddContacts(password, profile))
|
||||
return d
|
||||
|
||||
def registerAccount(self, email, password, jid_s, profile):
|
||||
"""Register a new profile and its associated XMPP account.
|
||||
|
|
@ -227,6 +231,29 @@ class MiscAccount(object):
|
|||
d.addErrback(removeProfile)
|
||||
return d
|
||||
|
||||
def autoAddContacts(self, password, profile):
|
||||
"""Auto-add some roster contacts after the profile creation.
|
||||
|
||||
@param password (unicode): XMPP account password
|
||||
"""
|
||||
contacts = self.getConfig('auto_add_contacts')
|
||||
if not contacts:
|
||||
return
|
||||
|
||||
def addContact(was_connected, contacts):
|
||||
for contact in contacts:
|
||||
d = self.host.addContact(contact, profile)
|
||||
if not was_connected:
|
||||
d.addCallback(lambda dummy: self.host.disconnect(profile))
|
||||
|
||||
try:
|
||||
contacts_jid = [jid.JID(contact) for contact in contacts]
|
||||
except (RuntimeError, jid.InvalidFormat, AttributeError):
|
||||
log.error("Invalid JIDs list: %s" % ", ".join(contacts))
|
||||
else:
|
||||
d = self.host.asyncConnect(profile, password, max_retries=0)
|
||||
d.addCallback(addContact, contacts_jid)
|
||||
|
||||
def sendEmails(self, email, jid_s, password, profile):
|
||||
# time to send the email
|
||||
|
||||
|
|
@ -548,5 +575,6 @@ http://www.salut-a-toi.org
|
|||
self.host.memory.asyncDeleteProfile(jid_s)
|
||||
raise failure
|
||||
|
||||
d.addCallback(self.autoAddContacts(password, jid_s))
|
||||
d.addErrback(removeProfile)
|
||||
return d
|
||||
|
|
|
|||
Loading…
Reference in a new issue