comparison src/plugins/plugin_misc_account.py @ 571:1cb24325485c

plugin account: errReceived fix + emails are now sent on new account + generic example server constants
author Goffi <goffi@goffi.org>
date Mon, 07 Jan 2013 23:10:26 +0100
parents 06faf5bffbc0
children ca13633d3b6b
comparison
equal deleted inserted replaced
570:bf1505df088c 571:1cb24325485c
22 from logging import debug, info, warning, error 22 from logging import debug, info, warning, error
23 from sat.core import exceptions 23 from sat.core import exceptions
24 from twisted.internet import reactor, defer, protocol 24 from twisted.internet import reactor, defer, protocol
25 from os.path import join, dirname 25 from os.path import join, dirname
26 from twisted.python.procutils import which 26 from twisted.python.procutils import which
27 from email.mime.text import MIMEText
28 from twisted.mail.smtp import sendmail
27 29
28 PLUGIN_INFO = { 30 PLUGIN_INFO = {
29 "name": "Account Plugin", 31 "name": "Account Plugin",
30 "import_name": "MISC-ACCOUNT", 32 "import_name": "MISC-ACCOUNT",
31 "type": "MISC", 33 "type": "MISC",
35 "handler": "no", 37 "handler": "no",
36 "description": _(u"""SàT account creation""") 38 "description": _(u"""SàT account creation""")
37 } 39 }
38 40
39 #You need do adapt the following consts to your server 41 #You need do adapt the following consts to your server
40 _REG_EMAIL_FROM = "NOREPLY@libervia.org" 42 _REG_EMAIL_FROM = "NOREPLY@example.net"
41 _REG_EMAIL_SERVER = "localhost" 43 _REG_EMAIL_SERVER = "localhost"
42 _REG_ADMIN_EMAIL = "goffi@goffi.org" 44 _REG_ADMIN_EMAIL = "admin@example.net"
43 _NEW_ACCOUNT_SERVER = "localhost" 45 _NEW_ACCOUNT_SERVER = "localhost"
44 _NEW_ACCOUNT_DOMAIN = "necton3.int" 46 _NEW_ACCOUNT_DOMAIN = "example.net"
45 _NEW_ACCOUNT_RESOURCE = "libervia" 47 _NEW_ACCOUNT_RESOURCE = "libervia"
46 _PROSODY_PATH = None #prosody path (where prosodyctl will be executed from), or None to automaticaly find it 48 _PROSODY_PATH = None #prosody path (where prosodyctl will be executed from), or None to automaticaly find it
47 _PROSODYCTL = "prosodyctl" 49 _PROSODYCTL = "prosodyctl"
48 50
49 RESERVED = ['libervia'] 51 RESERVED = ['libervia']
63 65
64 def outReceived(self, data): 66 def outReceived(self, data):
65 self.data += data 67 self.data += data
66 68
67 def errReceived(self, data): 69 def errReceived(self, data):
68 self.err += data 70 self.data += data
69 71
70 def processEnded(self, reason): 72 def processEnded(self, reason):
71 if (reason.value.exitCode == 0): 73 if (reason.value.exitCode == 0):
72 info(_('Prosody registration success')) 74 info(_('Prosody registration success'))
73 self.deferred.callback(None) 75 self.deferred.callback(None)
127 d = defer.Deferred() 129 d = defer.Deferred()
128 prosody_reg = ProsodyRegisterProtocol(password, d) 130 prosody_reg = ProsodyRegisterProtocol(password, d)
129 prosody_exe = join (self._prosody_path, _PROSODYCTL) 131 prosody_exe = join (self._prosody_path, _PROSODYCTL)
130 reactor.spawnProcess(prosody_reg, prosody_exe, [prosody_exe, 'adduser', "%s@%s" % (profile, _NEW_ACCOUNT_DOMAIN)], path=self._prosody_path) 132 reactor.spawnProcess(prosody_reg, prosody_exe, [prosody_exe, 'adduser', "%s@%s" % (profile, _NEW_ACCOUNT_DOMAIN)], path=self._prosody_path)
131 133
132 d.addCallback(self._accountCreated) 134 d.addCallback(self._accountCreated, profile, email, password)
133 return d 135 return d
134 136
135 def _accountCreated(self, result): 137 def _accountCreated(self, result, login, email, password):
136 print "_accountCreated" 138 #time to send the email
137
138 #action_id = self.sat_host.bridge.registerNewAccount(login, password, email, _NEW_ACCOUNT_DOMAIN, 5222)
139 #self.sat_host.action_handler.waitForId(self._postAccountCreation, action_id, profile)
140 139
141 ##time to send the email 140 _email_host = _REG_EMAIL_SERVER
141 _email_from = _REG_EMAIL_FROM
142 142
143 #_email_host = _REG_EMAIL_SERVER 143 def email_ok(ignore):
144 #_email_from = _REG_EMAIL_FROM 144 print ("Account creation email sent to %s" % email)
145 145
146 #def email_ok(ignore): 146 def email_ko(ignore):
147 # print ("Account creation email sent to %s" % email) 147 #TODO: return error code to user
148 error ("Failed to send email to %s" % email)
149
150 body = (u"""Welcome to Libervia, a Salut à Toi project part
148 151
149 #def email_ko(ignore): 152 /!\\ WARNING, THIS IS ONLY A TECHNICAL DEMO, DON'T USE THIS ACCOUNT FOR ANY SERIOUS PURPOSE /!\\
150 # #TODO: return error code to user
151 # error ("Failed to send email to %s" % email)
152 #
153 #body = (u"""Welcome to Libervia, a Salut à Toi project part
154 #
155 #/!\\ WARNING, THIS IS ONLY A TECHNICAL DEMO, DON'T USE THIS ACCOUNT FOR ANY SERIOUS PURPOSE /!\\
156 #
157 #Here are your connection informations:
158 #login: %(login)s
159 #password: %(password)s
160 #
161 #Your Jabber ID (JID) is: %(jid)s
162 #
163 #Any feedback welcome
164 #
165 #Cheers
166 #Goffi""" % { 'login': login, 'password': password, 'jid':"%s@%s" % (login, _NEW_ACCOUNT_DOMAIN) }).encode('utf-8')
167 #msg = MIMEText(body, 'plain', 'UTF-8')
168 #msg['Subject'] = 'Libervia account created'
169 #msg['From'] = _email_from
170 #msg['To'] = email
171 153
172 #d = sendmail(_email_host, _email_from, email, msg.as_string()) 154 Here are your connection informations:
173 #d.addCallbacks(email_ok, email_ko) 155 ---
156 login: %(login)s
157 password: %(password)s
174 158
175 ##email to the administrator 159 Your Jabber ID (JID) is: %(jid)s
160 ---
176 161
177 #body = (u"""New account created: %(login)s [%(email)s]""" % { 'login': login, 'email': email }).encode('utf-8') 162 SàT website: http://sat.goffi.org
178 #msg = MIMEText(body, 'plain', 'UTF-8') 163 follow SàT news: http://www.goffi.org
179 #msg['Subject'] = 'Libervia new account created'
180 #msg['From'] = _email_from
181 #msg['To'] = _REG_ADMIN_EMAIL
182 164
183 #d = sendmail(_email_host, _email_from, _REG_ADMIN_EMAIL, msg.as_string()) 165 Any feedback welcome
184 #d.addCallbacks(email_ok, email_ko) 166
185 #return "REGISTRATION" 167 Cheers
168 Goffi""" % { 'login': login, 'password': password, 'jid':"%s@%s" % (login, _NEW_ACCOUNT_DOMAIN) }).encode('utf-8')
169 msg = MIMEText(body, 'plain', 'UTF-8')
170 msg['Subject'] = 'Libervia account created'
171 msg['From'] = _email_from
172 msg['To'] = email
173
174 d = sendmail(_email_host, _email_from, email, msg.as_string())
175 d.addCallbacks(email_ok, email_ko)
176
177 #email to the administrator
178
179 body = (u"""New account created: %(login)s [%(email)s]""" % { 'login': login, 'email': email }).encode('utf-8')
180 msg = MIMEText(body, 'plain', 'UTF-8')
181 msg['Subject'] = 'Libervia new account created'
182 msg['From'] = _email_from
183 msg['To'] = _REG_ADMIN_EMAIL
184
185 d = sendmail(_email_host, _email_from, _REG_ADMIN_EMAIL, msg.as_string())
186 d.addCallbacks(email_ok, email_ko)