comparison libervia/pages/login/page_meta.py @ 1504:409d10211b20

server, browser: dynamic pages refactoring: dynamic pages has been reworked, to change the initial basic implementation. Pages are now dynamic by default, and a websocket is established by the first connected page of a session. The socket is used to transmit bridge signals, and then the signal is broadcasted to other tabs using broadcast channel. If the connecting tab is closed, an other one is chosen. Some tests are made to retry connecting in case of problem, and sometimes reload the pages (e.g. if profile is connected). Signals (or other data) are cached during reconnection phase, to avoid lost of data. All previous partial rendering mechanism have been removed, chat page is temporarily not working anymore, but will be eventually redone (one of the goal of this work is to have proper chat).
author Goffi <goffi@goffi.org>
date Wed, 01 Mar 2023 18:02:44 +0100
parents 6a35167a4e2c
children ce879da7fcf7
comparison
equal deleted inserted replaced
1503:2796e73ed50c 1504:409d10211b20
52 session_data = self.host.getSessionData(request, session_iface.ISATSession) 52 session_data = self.host.getSessionData(request, session_iface.ISATSession)
53 session_data.setPageData(self, "login_error", error_const) 53 session_data.setPageData(self, "login_error", error_const)
54 return C.POST_NO_CONFIRM 54 return C.POST_NO_CONFIRM
55 55
56 56
57 @defer.inlineCallbacks 57 async def on_data_post(self, request):
58 def on_data_post(self, request):
59 profile = self.getProfile(request) 58 profile = self.getProfile(request)
60 type_ = self.getPostedData(request, "type") 59 type_ = self.getPostedData(request, "type")
61 if type_ == "disconnect": 60 if type_ == "disconnect":
62 if profile is None: 61 if profile is None:
63 log.warning(_("Disconnect called when no profile is logged")) 62 log.warning(_("Disconnect called when no profile is logged"))
64 self.pageError(request, C.HTTP_BAD_REQUEST) 63 self.pageError(request, C.HTTP_BAD_REQUEST)
65 else: 64 else:
66 self.host.purgeSession(request) 65 self.host.purgeSession(request)
67 defer.returnValue(C.POST_NO_CONFIRM) 66 return C.POST_NO_CONFIRM
68 elif type_ == "login": 67 elif type_ == "login":
69 login, password = self.getPostedData(request, ("login", "password")) 68 login, password = self.getPostedData(request, ("login", "password"))
70 try: 69 try:
71 status = yield self.host.connect(request, login, password) 70 status = await self.host.connect(request, login, password)
72 except exceptions.ProfileUnknownError: 71 except exceptions.ProfileUnknownError:
73 # the profile doesn't exist, we return the same error as for invalid password 72 # the profile doesn't exist, we return the same error as for invalid password
74 # to avoid bruteforcing valid profiles 73 # to avoid bruteforcing valid profiles
75 log.warning(f"login tentative with invalid profile: {login!r}") 74 log.warning(f"login tentative with invalid profile: {login!r}")
76 defer.returnValue(login_error(self, request, C.PROFILE_AUTH_ERROR)) 75 return login_error(self, request, C.PROFILE_AUTH_ERROR)
77 except ValueError as e: 76 except ValueError as e:
78 message = str(e) 77 message = str(e)
79 if message in (C.XMPP_AUTH_ERROR, C.PROFILE_AUTH_ERROR): 78 if message in (C.XMPP_AUTH_ERROR, C.PROFILE_AUTH_ERROR):
80 defer.returnValue(login_error(self, request, message)) 79 return login_error(self, request, message)
81 else: 80 else:
82 # this error was not expected! 81 # this error was not expected!
83 raise e 82 raise e
84 except exceptions.TimeOutError: 83 except exceptions.TimeOutError:
85 defer.returnValue(login_error(self, request, C.NO_REPLY)) 84 return login_error(self, request, C.NO_REPLY)
86 else: 85 else:
87 if status in (C.PROFILE_LOGGED, C.PROFILE_LOGGED_EXT_JID, C.SESSION_ACTIVE): 86 if status in (C.PROFILE_LOGGED, C.PROFILE_LOGGED_EXT_JID, C.SESSION_ACTIVE):
88 # Profile has been logged correctly 87 # Profile has been logged correctly
89 self.redirectOrContinue(request) 88 self.redirectOrContinue(request)
90 else: 89 else: