Mercurial > libervia-web
comparison libervia/pages/login/page_meta.py @ 1124:28e3eb3bb217
files reorganisation and installation rework:
- files have been reorganised to follow other SàT projects and usual Python organisation (no more "/src" directory)
- VERSION file is now used, as for other SàT projects
- replace the overcomplicated setup.py be a more sane one. Pyjamas part is not compiled anymore by setup.py, it must be done separatly
- removed check for data_dir if it's empty
- installation tested working in virtual env
- libervia launching script is now in bin/libervia
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 25 Aug 2018 17:59:48 +0200 |
parents | src/pages/login/page_meta.py@cdd389ef97bc |
children | 29eb15062416 |
comparison
equal
deleted
inserted
replaced
1123:63a4b8fe9782 | 1124:28e3eb3bb217 |
---|---|
1 #!/usr/bin/env python2.7 | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 from sat.core.i18n import _ | |
5 from sat.core import exceptions | |
6 from libervia.server.constants import Const as C | |
7 from libervia.server import session_iface | |
8 from twisted.internet import defer | |
9 from sat.core.log import getLogger | |
10 | |
11 log = getLogger("pages/login") | |
12 | |
13 """SàT log-in page, with link to create an account""" | |
14 | |
15 name = u"login" | |
16 access = C.PAGES_ACCESS_PUBLIC | |
17 template = u"login/login.html" | |
18 | |
19 | |
20 def prepare_render(self, request): | |
21 template_data = request.template_data | |
22 | |
23 # we redirect to logged page if a session is active | |
24 profile = self.getProfile(request) | |
25 if profile is not None: | |
26 self.pageRedirect("/login/logged", request) | |
27 | |
28 # login error message | |
29 session_data = self.host.getSessionData(request, session_iface.ISATSession) | |
30 login_error = session_data.popPageData(self, "login_error") | |
31 if login_error is not None: | |
32 template_data["S_C"] = C # we need server constants in template | |
33 template_data["login_error"] = login_error | |
34 template_data["empty_password_allowed"] = bool( | |
35 self.host.options["empty_password_allowed_warning_dangerous_list"] | |
36 ) | |
37 | |
38 # register page url | |
39 template_data["register_url"] = self.getPageRedirectURL(request, "register") | |
40 | |
41 # if login is set, we put it in template to prefill field | |
42 template_data["login"] = session_data.popPageData(self, "login") | |
43 | |
44 | |
45 def login_error(self, request, error_const): | |
46 """set login_error in page data | |
47 | |
48 @param error_const(unicode): one of login error constant | |
49 @return C.POST_NO_CONFIRM: avoid confirm message | |
50 """ | |
51 session_data = self.host.getSessionData(request, session_iface.ISATSession) | |
52 session_data.setPageData(self, "login_error", error_const) | |
53 return C.POST_NO_CONFIRM | |
54 | |
55 | |
56 @defer.inlineCallbacks | |
57 def on_data_post(self, request): | |
58 profile = self.getProfile(request) | |
59 type_ = self.getPostedData(request, "type") | |
60 if type_ == "disconnect": | |
61 if profile is None: | |
62 log.warning(_(u"Disconnect called when no profile is logged")) | |
63 self.pageError(request, C.HTTP_BAD_REQUEST) | |
64 else: | |
65 self.host.purgeSession(request) | |
66 defer.returnValue(C.POST_NO_CONFIRM) | |
67 elif type_ == "login": | |
68 login, password = self.getPostedData(request, (u"login", u"password")) | |
69 try: | |
70 status = yield self.host.connect(request, login, password) | |
71 except ValueError as e: | |
72 if e.message in (C.XMPP_AUTH_ERROR, C.PROFILE_AUTH_ERROR): | |
73 defer.returnValue(login_error(self, request, e.message)) | |
74 else: | |
75 # this error was not expected! | |
76 raise e | |
77 except exceptions.TimeOutError: | |
78 defer.returnValue(login_error(self, request, C.NO_REPLY)) | |
79 else: | |
80 if status in (C.PROFILE_LOGGED, C.PROFILE_LOGGED_EXT_JID, C.SESSION_ACTIVE): | |
81 # Profile has been logged correctly | |
82 self.redirectOrContinue(request) | |
83 else: | |
84 log.error(_(u"Unhandled status: {status}".format(status=status))) | |
85 else: | |
86 self.pageError(request, C.HTTP_BAD_REQUEST) |