# HG changeset patch # User Goffi # Date 1357596626 -3600 # Node ID 1cb24325485cc444e90a5557535fa53f67f8ec16 # Parent bf1505df088c9af5cf9e28e84effbdaff026a2ed plugin account: errReceived fix + emails are now sent on new account + generic example server constants diff -r bf1505df088c -r 1cb24325485c src/plugins/plugin_misc_account.py --- a/src/plugins/plugin_misc_account.py Mon Jan 07 23:08:45 2013 +0100 +++ b/src/plugins/plugin_misc_account.py Mon Jan 07 23:10:26 2013 +0100 @@ -24,6 +24,8 @@ 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 @@ } #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 @@ 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 @@ 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 + + _email_host = _REG_EMAIL_SERVER + _email_from = _REG_EMAIL_FROM + + def email_ok(ignore): + print ("Account creation email sent to %s" % email) - ##time to send the 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 + +/!\\ WARNING, THIS IS ONLY A TECHNICAL DEMO, DON'T USE THIS ACCOUNT FOR ANY SERIOUS PURPOSE /!\\ - #_email_host = _REG_EMAIL_SERVER - #_email_from = _REG_EMAIL_FROM +Here are your connection informations: +--- +login: %(login)s +password: %(password)s - #def email_ok(ignore): - # print ("Account creation email sent to %s" % email) +Your Jabber ID (JID) is: %(jid)s +--- - #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 +SàT website: http://sat.goffi.org +follow SàT news: http://www.goffi.org + +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) + d = sendmail(_email_host, _email_from, email, msg.as_string()) + d.addCallbacks(email_ok, email_ko) - ##email to the administrator + #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 + 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) - #return "REGISTRATION" + d = sendmail(_email_host, _email_from, _REG_ADMIN_EMAIL, msg.as_string()) + d.addCallbacks(email_ok, email_ko)