comparison libervia/pages/login/page_meta.py @ 1216:b2d067339de3

python 3 port: /!\ Python 3.6+ is now needed to use libervia /!\ instability may occur and features may not be working anymore, this will improve with time /!\ TxJSONRPC dependency has been removed The same procedure as in backend has been applied (check backend commit ab2696e34d29 logs for details). Removed now deprecated code (Pyjamas compiled browser part, legacy blog, JSON RPC related code). Adapted code to work without `html` and `themes` dirs.
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:12:31 +0200
parents 29eb15062416
children 15f90fd688b5
comparison
equal deleted inserted replaced
1215:f14ab8a25e8b 1216:b2d067339de3
1 #!/usr/bin/env python2.7 1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 from sat.core.i18n import _ 4 from sat.core.i18n import _
5 from sat.core import exceptions 5 from sat.core import exceptions
6 from libervia.server.constants import Const as C 6 from libervia.server.constants import Const as C
10 10
11 log = getLogger(__name__) 11 log = getLogger(__name__)
12 12
13 """SàT log-in page, with link to create an account""" 13 """SàT log-in page, with link to create an account"""
14 14
15 name = u"login" 15 name = "login"
16 access = C.PAGES_ACCESS_PUBLIC 16 access = C.PAGES_ACCESS_PUBLIC
17 template = u"login/login.html" 17 template = "login/login.html"
18 18
19 19
20 def prepare_render(self, request): 20 def prepare_render(self, request):
21 template_data = request.template_data 21 template_data = request.template_data
22 22
57 def on_data_post(self, request): 57 def on_data_post(self, request):
58 profile = self.getProfile(request) 58 profile = self.getProfile(request)
59 type_ = self.getPostedData(request, "type") 59 type_ = self.getPostedData(request, "type")
60 if type_ == "disconnect": 60 if type_ == "disconnect":
61 if profile is None: 61 if profile is None:
62 log.warning(_(u"Disconnect called when no profile is logged")) 62 log.warning(_("Disconnect called when no profile is logged"))
63 self.pageError(request, C.HTTP_BAD_REQUEST) 63 self.pageError(request, C.HTTP_BAD_REQUEST)
64 else: 64 else:
65 self.host.purgeSession(request) 65 self.host.purgeSession(request)
66 defer.returnValue(C.POST_NO_CONFIRM) 66 defer.returnValue(C.POST_NO_CONFIRM)
67 elif type_ == "login": 67 elif type_ == "login":
68 login, password = self.getPostedData(request, (u"login", u"password")) 68 login, password = self.getPostedData(request, ("login", "password"))
69 try: 69 try:
70 status = yield self.host.connect(request, login, password) 70 status = yield self.host.connect(request, login, password)
71 except ValueError as e: 71 except ValueError as e:
72 if e.message in (C.XMPP_AUTH_ERROR, C.PROFILE_AUTH_ERROR): 72 if str(e) in (C.XMPP_AUTH_ERROR, C.PROFILE_AUTH_ERROR):
73 defer.returnValue(login_error(self, request, e.message)) 73 defer.returnValue(login_error(self, request, str(e)))
74 else: 74 else:
75 # this error was not expected! 75 # this error was not expected!
76 raise e 76 raise e
77 except exceptions.TimeOutError: 77 except exceptions.TimeOutError:
78 defer.returnValue(login_error(self, request, C.NO_REPLY)) 78 defer.returnValue(login_error(self, request, C.NO_REPLY))
79 else: 79 else:
80 if status in (C.PROFILE_LOGGED, C.PROFILE_LOGGED_EXT_JID, C.SESSION_ACTIVE): 80 if status in (C.PROFILE_LOGGED, C.PROFILE_LOGGED_EXT_JID, C.SESSION_ACTIVE):
81 # Profile has been logged correctly 81 # Profile has been logged correctly
82 self.redirectOrContinue(request) 82 self.redirectOrContinue(request)
83 else: 83 else:
84 log.error(_(u"Unhandled status: {status}".format(status=status))) 84 log.error(_("Unhandled status: {status}".format(status=status)))
85 else: 85 else:
86 self.pageError(request, C.HTTP_BAD_REQUEST) 86 self.pageError(request, C.HTTP_BAD_REQUEST)