Mercurial > libervia-web
comparison libervia.py @ 250:38e6211d36ca
browser_side: added auto-connection with URL parameters:
- format: http://libervia.org/login=xxx&passwd=yyy
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 23 Oct 2013 18:33:16 +0200 |
parents | 43a27ffc74df |
children | 24335e82fef0 |
comparison
equal
deleted
inserted
replaced
249:c24715dcd2f6 | 250:38e6211d36ca |
---|---|
24 from pyjamas.ui.HTML import HTML | 24 from pyjamas.ui.HTML import HTML |
25 from pyjamas.ui.KeyboardListener import KEY_ESCAPE | 25 from pyjamas.ui.KeyboardListener import KEY_ESCAPE |
26 from pyjamas.Timer import Timer | 26 from pyjamas.Timer import Timer |
27 from pyjamas import Window, DOM | 27 from pyjamas import Window, DOM |
28 from pyjamas.JSONService import JSONProxy | 28 from pyjamas.JSONService import JSONProxy |
29 from pyjamas import Location | |
29 from browser_side.register import RegisterBox | 30 from browser_side.register import RegisterBox |
30 from browser_side.contact import ContactPanel | 31 from browser_side.contact import ContactPanel |
31 from browser_side.base_widget import WidgetsPanel | 32 from browser_side.base_widget import WidgetsPanel |
32 from browser_side.panels import MicroblogItem | 33 from browser_side.panels import MicroblogItem |
33 from browser_side import panels, dialog | 34 from browser_side import panels, dialog |
34 from browser_side.jid import JID | 35 from browser_side.jid import JID |
35 from browser_side.tools import html_sanitize | 36 from browser_side.tools import html_sanitize |
36 from sat.tools.frontends.misc import InputHistory | 37 from sat.tools.frontends.misc import InputHistory |
37 | 38 from sat.tools.frontends.strings import getURLParams |
38 | 39 |
39 MAX_MBLOG_CACHE = 500 # Max microblog entries kept in memories | 40 MAX_MBLOG_CACHE = 500 # Max microblog entries kept in memories |
40 | 41 |
41 # Set to true to not create a new LiberviaWidget when a similar one | 42 # Set to true to not create a new LiberviaWidget when a similar one |
42 # already exist (i.e. a chat panel with the same target). Instead | 43 # already exist (i.e. a chat panel with the same target). Instead |
239 def dataReceived(result): | 240 def dataReceived(result): |
240 if 'avatar' in result: | 241 if 'avatar' in result: |
241 self._entityDataUpdatedCb(jid_str, 'avatar', result['avatar']) | 242 self._entityDataUpdatedCb(jid_str, 'avatar', result['avatar']) |
242 else: | 243 else: |
243 self.bridge.call("getCard", None, jid_str) | 244 self.bridge.call("getCard", None, jid_str) |
245 | |
244 def avatarError(error_data): | 246 def avatarError(error_data): |
245 # The jid is maybe not in our roster, we ask for the VCard | 247 # The jid is maybe not in our roster, we ask for the VCard |
246 self.bridge.call("getCard", None, jid_str) | 248 self.bridge.call("getCard", None, jid_str) |
247 | 249 |
248 if jid_str not in self.avatars_cache: | 250 if jid_str not in self.avatars_cache: |
283 def _isRegisteredCB(self, registered): | 285 def _isRegisteredCB(self, registered): |
284 if not registered: | 286 if not registered: |
285 self._register_box = RegisterBox(self.logged) | 287 self._register_box = RegisterBox(self.logged) |
286 self._register_box.centerBox() | 288 self._register_box.centerBox() |
287 self._register_box.show() | 289 self._register_box.show() |
290 self._tryAutoConnect() | |
288 else: | 291 else: |
289 self._register.call('isConnected', self._isConnectedCB) | 292 self._register.call('isConnected', self._isConnectedCB) |
290 | 293 |
291 def _isConnectedCB(self, connected): | 294 def _isConnectedCB(self, connected): |
292 if not connected: | 295 if not connected: |
293 self._register.call('connect', lambda x:self.logged()) | 296 self._register.call('connect', lambda x: self.logged()) |
294 else: | 297 else: |
295 self.logged() | 298 self.logged() |
296 | 299 |
297 def logged(self): | 300 def logged(self): |
298 if self._register_box: | 301 if self._register_box: |
312 | 315 |
313 def domain_eb(value): | 316 def domain_eb(value): |
314 self._defaultDomain = "libervia.org" | 317 self._defaultDomain = "libervia.org" |
315 | 318 |
316 self.bridge.call("getNewAccountDomain", (domain_cb, domain_eb)) | 319 self.bridge.call("getNewAccountDomain", (domain_cb, domain_eb)) |
320 | |
321 def _tryAutoConnect(self): | |
322 """This method retrieve the eventual URL parameters to auto-connect the user.""" | |
323 params = getURLParams(Window.getLocation().getSearch()) | |
324 if "login" in params: | |
325 self._register_box._form.login_box.setText(params["login"]) | |
326 self._register_box._form.login_pass_box.setFocus(True) | |
327 if "passwd" in params: | |
328 # try to connect | |
329 self._register_box._form.login_pass_box.setText(params["passwd"]) | |
330 self._register_box._form.onLogin(None) | |
331 return True | |
332 else: | |
333 # this would eventually set the browser saved password | |
334 Timer(5, lambda: self._register_box._form.login_pass_box.setFocus(True)) | |
317 | 335 |
318 def _getContactsCB(self, contacts_data): | 336 def _getContactsCB(self, contacts_data): |
319 for contact in contacts_data: | 337 for contact in contacts_data: |
320 jid, attributes, groups = contact | 338 jid, attributes, groups = contact |
321 self._newContactCb(jid, attributes, groups) | 339 self._newContactCb(jid, attributes, groups) |