comparison libervia.tac @ 61:80c490e6a1a7

server side: misc stuff: - using twisted.web.resource.NoResource instead of deprecated twisted.web.error.NoResource - session's jid was badly saved, fixed - fixed bad account domain and bad administrator mail when sending mails - added a specialy return value for session already active
author Goffi <goffi@goffi.org>
date Tue, 31 May 2011 17:03:37 +0200
parents d0fa4e96a5e4
children 9d8e79ac4c9c
comparison
equal deleted inserted replaced
60:d9f4a3256da8 61:80c490e6a1a7
33 from twisted.internet import reactor, defer 33 from twisted.internet import reactor, defer
34 from twisted.mail.smtp import sendmail 34 from twisted.mail.smtp import sendmail
35 from twisted.web import server 35 from twisted.web import server
36 from twisted.web import error as weberror 36 from twisted.web import error as weberror
37 from twisted.web.static import File 37 from twisted.web.static import File
38 from twisted.web.resource import Resource 38 from twisted.web.resource import Resource, NoResource
39 from twisted.web.error import NoResource
40 from twisted.python.components import registerAdapter 39 from twisted.python.components import registerAdapter
41 from twisted.words.protocols.jabber.jid import JID 40 from twisted.words.protocols.jabber.jid import JID
42 from txjsonrpc.web import jsonrpc 41 from txjsonrpc.web import jsonrpc
43 from txjsonrpc import jsonrpclib 42 from txjsonrpc import jsonrpclib
44 from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService 43 from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService
139 138
140 def jsonrpc_getProfileJid(self): 139 def jsonrpc_getProfileJid(self):
141 """Return the jid of the profile""" 140 """Return the jid of the profile"""
142 sat_session = ISATSession(self.session) 141 sat_session = ISATSession(self.session)
143 profile = sat_session.profile 142 profile = sat_session.profile
144 sat_session.sat_jid = JID(self.sat_host.bridge.getParamA("JabberID", "Connection", profile_key=profile)) 143 sat_session.jid = JID(self.sat_host.bridge.getParamA("JabberID", "Connection", profile_key=profile))
145 return sat_session.sat_jid.full() 144 return sat_session.jid.full()
146 145
147 def jsonrpc_getContacts(self): 146 def jsonrpc_getContacts(self):
148 """Return all passed args.""" 147 """Return all passed args."""
149 profile = ISATSession(self.session).profile 148 profile = ISATSession(self.session).profile
150 return self.sat_host.bridge.getContacts(profile) 149 return self.sat_host.bridge.getContacts(profile)
179 return self.sat_host.bridge.getWaitingSub(profile) 178 return self.sat_host.bridge.getWaitingSub(profile)
180 179
181 def jsonrpc_setStatus(self, status): 180 def jsonrpc_setStatus(self, status):
182 """Change the status""" 181 """Change the status"""
183 profile = ISATSession(self.session).profile 182 profile = ISATSession(self.session).profile
184 print "new status received:", status
185 self.sat_host.bridge.setPresence('', '', 0, {'':status}, profile) 183 self.sat_host.bridge.setPresence('', '', 0, {'':status}, profile)
186 184
187 185
188 def jsonrpc_sendMessage(self, to_jid, msg, subject, type): 186 def jsonrpc_sendMessage(self, to_jid, msg, subject, type):
189 """send message""" 187 """send message"""
197 if match: 195 if match:
198 recip = match.group(1) 196 recip = match.group(1)
199 text = match.group(2) 197 text = match.group(2)
200 if recip == '@' and text: 198 if recip == '@' and text:
201 #This text if for the public microblog 199 #This text if for the public microblog
202 print "Sending message to everybody"
203 return self.sat_host.bridge.sendPersonalEvent("MICROBLOG", {'content':text}, profile) 200 return self.sat_host.bridge.sendPersonalEvent("MICROBLOG", {'content':text}, profile)
204 else: 201 else:
205 return self.sat_host.bridge.sendGroupBlog([recip], text, profile) 202 return self.sat_host.bridge.sendGroupBlog([recip], text, profile)
206 203
207 def jsonrpc_getPresenceStatus(self): 204 def jsonrpc_getPresenceStatus(self):
383 #FIXME: values must be in a config file instead of hardcoded 380 #FIXME: values must be in a config file instead of hardcoded
384 self.sat_host.bridge.setParam("JabberID", "%s@%s/%s" % (login, _NEW_ACCOUNT_DOMAIN, _NEW_ACCOUNT_RESOURCE), "Connection", profile) 381 self.sat_host.bridge.setParam("JabberID", "%s@%s/%s" % (login, _NEW_ACCOUNT_DOMAIN, _NEW_ACCOUNT_RESOURCE), "Connection", profile)
385 self.sat_host.bridge.setParam("Server", _NEW_ACCOUNT_SERVER, "Connection", profile) 382 self.sat_host.bridge.setParam("Server", _NEW_ACCOUNT_SERVER, "Connection", profile)
386 self.sat_host.bridge.setParam("Password", password, "Connection", profile) 383 self.sat_host.bridge.setParam("Password", password, "Connection", profile)
387 #and the account 384 #and the account
388 action_id = self.sat_host.bridge.registerNewAccount(login, password, email, "tazar.int", 5222) 385 action_id = self.sat_host.bridge.registerNewAccount(login, password, email, _NEW_ACCOUNT_DOMAIN, 5222)
389 self.sat_host.action_handler.waitForId(action_id, self._postAccountCreation, profile) 386 self.sat_host.action_handler.waitForId(action_id, self._postAccountCreation, profile)
390 387
391 #time to send the email 388 #time to send the email
392 389
393 _email_host = _REG_EMAIL_SERVER 390 _email_host = _REG_EMAIL_SERVER
428 msg = MIMEText(body, 'plain', 'UTF-8') 425 msg = MIMEText(body, 'plain', 'UTF-8')
429 msg['Subject'] = 'Libervia new account created' 426 msg['Subject'] = 'Libervia new account created'
430 msg['From'] = _email_from 427 msg['From'] = _email_from
431 msg['To'] = _REG_ADMIN_EMAIL 428 msg['To'] = _REG_ADMIN_EMAIL
432 429
433 d = sendmail(_email_host, _email_from, email, msg.as_string()) 430 d = sendmail(_email_host, _email_from, _REG_ADMIN_EMAIL, msg.as_string())
434 d.addCallbacks(email_ok, email_ko) 431 d.addCallbacks(email_ok, email_ko)
435 return "REGISTRATION" 432 return "REGISTRATION"
436 433
437 def __cleanWaiting(self, login): 434 def __cleanWaiting(self, login):
438 """Remove login from waiting queue""" 435 """Remove login from waiting queue"""
442 pass 439 pass
443 440
444 def _logged(self, profile, request, finish=True): 441 def _logged(self, profile, request, finish=True):
445 """Set everything when a user just logged 442 """Set everything when a user just logged
446 and return "LOGGED" to the requester""" 443 and return "LOGGED" to the requester"""
444 def result(answer):
445 if finish:
446 request.write(answer)
447 request.finish()
448 else:
449 return answer
450
447 self.__cleanWaiting(profile) 451 self.__cleanWaiting(profile)
448 _session = request.getSession() 452 _session = request.getSession()
449 sat_session = ISATSession(_session) 453 sat_session = ISATSession(_session)
450 if sat_session.profile: 454 if sat_session.profile:
451 error (_('/!\\ Session has already a profile, this should NEVER happen !')) 455 error (('/!\\ Session has already a profile, this should NEVER happen !'))
456 return result('SESSION_ACTIVE')
452 sat_session.profile = profile 457 sat_session.profile = profile
453 self.sat_host.prof_connected.add(profile) 458 self.sat_host.prof_connected.add(profile)
454 459
455 def onExpire(): 460 def onExpire():
456 try: 461 try:
464 _session.notifyOnExpire(onExpire) 469 _session.notifyOnExpire(onExpire)
465 470
466 d = defer.Deferred() 471 d = defer.Deferred()
467 self.sat_host.bridge.getMblogNodes(profile, d.callback, d.errback) 472 self.sat_host.bridge.getMblogNodes(profile, d.callback, d.errback)
468 d.addCallback(self._fillMblogNodes, _session) 473 d.addCallback(self._fillMblogNodes, _session)
469 474 return result('LOGGED')
470 if finish:
471 request.write('LOGGED')
472 request.finish()
473 else:
474 return "LOGGED"
475 475
476 def _logginError(self, login, request, error_type): 476 def _logginError(self, login, request, error_type):
477 """Something went wrong during loggin, return an error""" 477 """Something went wrong during loggin, return an error"""
478 self.__cleanWaiting(login) 478 self.__cleanWaiting(login)
479 return error_type 479 return error_type