plugin account: errReceived fix + emails are now sent on new account + generic example server constants
This commit is contained in:
parent
44a042df6d
commit
9b4dbbbff6
1 changed files with 57 additions and 56 deletions
|
|
@ -24,6 +24,8 @@ from sat.core import exceptions
|
|||
from twisted.internet import reactor, defer, protocol
|
||||
from os.path import join, dirname
|
||||
from twisted.python.procutils import which
|
||||
from email.mime.text import MIMEText
|
||||
from twisted.mail.smtp import sendmail
|
||||
|
||||
PLUGIN_INFO = {
|
||||
"name": "Account Plugin",
|
||||
|
|
@ -37,11 +39,11 @@ PLUGIN_INFO = {
|
|||
}
|
||||
|
||||
#You need do adapt the following consts to your server
|
||||
_REG_EMAIL_FROM = "NOREPLY@libervia.org"
|
||||
_REG_EMAIL_FROM = "NOREPLY@example.net"
|
||||
_REG_EMAIL_SERVER = "localhost"
|
||||
_REG_ADMIN_EMAIL = "goffi@goffi.org"
|
||||
_REG_ADMIN_EMAIL = "admin@example.net"
|
||||
_NEW_ACCOUNT_SERVER = "localhost"
|
||||
_NEW_ACCOUNT_DOMAIN = "necton3.int"
|
||||
_NEW_ACCOUNT_DOMAIN = "example.net"
|
||||
_NEW_ACCOUNT_RESOURCE = "libervia"
|
||||
_PROSODY_PATH = None #prosody path (where prosodyctl will be executed from), or None to automaticaly find it
|
||||
_PROSODYCTL = "prosodyctl"
|
||||
|
|
@ -65,7 +67,7 @@ class ProsodyRegisterProtocol(protocol.ProcessProtocol):
|
|||
self.data += data
|
||||
|
||||
def errReceived(self, data):
|
||||
self.err += data
|
||||
self.data += data
|
||||
|
||||
def processEnded(self, reason):
|
||||
if (reason.value.exitCode == 0):
|
||||
|
|
@ -129,57 +131,56 @@ class MiscAccount():
|
|||
prosody_exe = join (self._prosody_path, _PROSODYCTL)
|
||||
reactor.spawnProcess(prosody_reg, prosody_exe, [prosody_exe, 'adduser', "%s@%s" % (profile, _NEW_ACCOUNT_DOMAIN)], path=self._prosody_path)
|
||||
|
||||
d.addCallback(self._accountCreated)
|
||||
d.addCallback(self._accountCreated, profile, email, password)
|
||||
return d
|
||||
|
||||
def _accountCreated(self, result):
|
||||
print "_accountCreated"
|
||||
|
||||
#action_id = self.sat_host.bridge.registerNewAccount(login, password, email, _NEW_ACCOUNT_DOMAIN, 5222)
|
||||
#self.sat_host.action_handler.waitForId(self._postAccountCreation, action_id, profile)
|
||||
def _accountCreated(self, result, login, email, password):
|
||||
#time to send the email
|
||||
|
||||
##time to send the email
|
||||
_email_host = _REG_EMAIL_SERVER
|
||||
_email_from = _REG_EMAIL_FROM
|
||||
|
||||
#_email_host = _REG_EMAIL_SERVER
|
||||
#_email_from = _REG_EMAIL_FROM
|
||||
def email_ok(ignore):
|
||||
print ("Account creation email sent to %s" % email)
|
||||
|
||||
#def email_ok(ignore):
|
||||
# print ("Account creation email sent to %s" % email)
|
||||
def email_ko(ignore):
|
||||
#TODO: return error code to user
|
||||
error ("Failed to send email to %s" % email)
|
||||
|
||||
body = (u"""Welcome to Libervia, a Salut à Toi project part
|
||||
|
||||
#def email_ko(ignore):
|
||||
# #TODO: return error code to user
|
||||
# error ("Failed to send email to %s" % email)
|
||||
#
|
||||
#body = (u"""Welcome to Libervia, a Salut à Toi project part
|
||||
#
|
||||
#/!\\ WARNING, THIS IS ONLY A TECHNICAL DEMO, DON'T USE THIS ACCOUNT FOR ANY SERIOUS PURPOSE /!\\
|
||||
#
|
||||
#Here are your connection informations:
|
||||
#login: %(login)s
|
||||
#password: %(password)s
|
||||
#
|
||||
#Your Jabber ID (JID) is: %(jid)s
|
||||
#
|
||||
#Any feedback welcome
|
||||
#
|
||||
#Cheers
|
||||
#Goffi""" % { 'login': login, 'password': password, 'jid':"%s@%s" % (login, _NEW_ACCOUNT_DOMAIN) }).encode('utf-8')
|
||||
#msg = MIMEText(body, 'plain', 'UTF-8')
|
||||
#msg['Subject'] = 'Libervia account created'
|
||||
#msg['From'] = _email_from
|
||||
#msg['To'] = email
|
||||
/!\\ WARNING, THIS IS ONLY A TECHNICAL DEMO, DON'T USE THIS ACCOUNT FOR ANY SERIOUS PURPOSE /!\\
|
||||
|
||||
#d = sendmail(_email_host, _email_from, email, msg.as_string())
|
||||
#d.addCallbacks(email_ok, email_ko)
|
||||
Here are your connection informations:
|
||||
---
|
||||
login: %(login)s
|
||||
password: %(password)s
|
||||
|
||||
##email to the administrator
|
||||
Your Jabber ID (JID) is: %(jid)s
|
||||
---
|
||||
|
||||
#body = (u"""New account created: %(login)s [%(email)s]""" % { 'login': login, 'email': email }).encode('utf-8')
|
||||
#msg = MIMEText(body, 'plain', 'UTF-8')
|
||||
#msg['Subject'] = 'Libervia new account created'
|
||||
#msg['From'] = _email_from
|
||||
#msg['To'] = _REG_ADMIN_EMAIL
|
||||
SàT website: http://sat.goffi.org
|
||||
follow SàT news: http://www.goffi.org
|
||||
|
||||
#d = sendmail(_email_host, _email_from, _REG_ADMIN_EMAIL, msg.as_string())
|
||||
#d.addCallbacks(email_ok, email_ko)
|
||||
#return "REGISTRATION"
|
||||
Any feedback welcome
|
||||
|
||||
Cheers
|
||||
Goffi""" % { 'login': login, 'password': password, 'jid':"%s@%s" % (login, _NEW_ACCOUNT_DOMAIN) }).encode('utf-8')
|
||||
msg = MIMEText(body, 'plain', 'UTF-8')
|
||||
msg['Subject'] = 'Libervia account created'
|
||||
msg['From'] = _email_from
|
||||
msg['To'] = email
|
||||
|
||||
d = sendmail(_email_host, _email_from, email, msg.as_string())
|
||||
d.addCallbacks(email_ok, email_ko)
|
||||
|
||||
#email to the administrator
|
||||
|
||||
body = (u"""New account created: %(login)s [%(email)s]""" % { 'login': login, 'email': email }).encode('utf-8')
|
||||
msg = MIMEText(body, 'plain', 'UTF-8')
|
||||
msg['Subject'] = 'Libervia new account created'
|
||||
msg['From'] = _email_from
|
||||
msg['To'] = _REG_ADMIN_EMAIL
|
||||
|
||||
d = sendmail(_email_host, _email_from, _REG_ADMIN_EMAIL, msg.as_string())
|
||||
d.addCallbacks(email_ok, email_ko)
|
||||
|
|
|
|||
Loading…
Reference in a new issue