plugin account: errReceived fix + emails are now sent on new account + generic example server constants

This commit is contained in:
Goffi 2013-01-07 23:10:26 +01:00
commit 9b4dbbbff6

View file

@ -24,6 +24,8 @@ from sat.core import exceptions
from twisted.internet import reactor, defer, protocol from twisted.internet import reactor, defer, protocol
from os.path import join, dirname from os.path import join, dirname
from twisted.python.procutils import which from twisted.python.procutils import which
from email.mime.text import MIMEText
from twisted.mail.smtp import sendmail
PLUGIN_INFO = { PLUGIN_INFO = {
"name": "Account Plugin", "name": "Account Plugin",
@ -37,11 +39,11 @@ PLUGIN_INFO = {
} }
#You need do adapt the following consts to your server #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_EMAIL_SERVER = "localhost"
_REG_ADMIN_EMAIL = "goffi@goffi.org" _REG_ADMIN_EMAIL = "admin@example.net"
_NEW_ACCOUNT_SERVER = "localhost" _NEW_ACCOUNT_SERVER = "localhost"
_NEW_ACCOUNT_DOMAIN = "necton3.int" _NEW_ACCOUNT_DOMAIN = "example.net"
_NEW_ACCOUNT_RESOURCE = "libervia" _NEW_ACCOUNT_RESOURCE = "libervia"
_PROSODY_PATH = None #prosody path (where prosodyctl will be executed from), or None to automaticaly find it _PROSODY_PATH = None #prosody path (where prosodyctl will be executed from), or None to automaticaly find it
_PROSODYCTL = "prosodyctl" _PROSODYCTL = "prosodyctl"
@ -65,7 +67,7 @@ class ProsodyRegisterProtocol(protocol.ProcessProtocol):
self.data += data self.data += data
def errReceived(self, data): def errReceived(self, data):
self.err += data self.data += data
def processEnded(self, reason): def processEnded(self, reason):
if (reason.value.exitCode == 0): if (reason.value.exitCode == 0):
@ -129,57 +131,56 @@ class MiscAccount():
prosody_exe = join (self._prosody_path, _PROSODYCTL) 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) 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 return d
def _accountCreated(self, result): def _accountCreated(self, result, login, email, password):
print "_accountCreated" #time to send the email
#action_id = self.sat_host.bridge.registerNewAccount(login, password, email, _NEW_ACCOUNT_DOMAIN, 5222) _email_host = _REG_EMAIL_SERVER
#self.sat_host.action_handler.waitForId(self._postAccountCreation, action_id, profile) _email_from = _REG_EMAIL_FROM
##time to send the email def email_ok(ignore):
print ("Account creation email sent to %s" % email)
#_email_host = _REG_EMAIL_SERVER def email_ko(ignore):
#_email_from = _REG_EMAIL_FROM #TODO: return error code to user
error ("Failed to send email to %s" % email)
#def email_ok(ignore): body = (u"""Welcome to Libervia, a Salut à Toi project part
# print ("Account creation email sent to %s" % email)
#def email_ko(ignore): /!\\ WARNING, THIS IS ONLY A TECHNICAL DEMO, DON'T USE THIS ACCOUNT FOR ANY SERIOUS PURPOSE /!\\
# #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
#d = sendmail(_email_host, _email_from, email, msg.as_string()) Here are your connection informations:
#d.addCallbacks(email_ok, email_ko) ---
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') SàT website: http://sat.goffi.org
#msg = MIMEText(body, 'plain', 'UTF-8') follow SàT news: http://www.goffi.org
#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()) Any feedback welcome
#d.addCallbacks(email_ok, email_ko)
#return "REGISTRATION" 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)