Mercurial > libervia-web
comparison libervia/pages/register/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/register/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 libervia.server.constants import Const as C | |
5 from libervia.server import session_iface | |
6 from twisted.internet import defer | |
7 from sat.core.log import getLogger | |
8 | |
9 log = getLogger("pages/register") | |
10 | |
11 """SàT account registration page""" | |
12 | |
13 name = u"register" | |
14 access = C.PAGES_ACCESS_PUBLIC | |
15 template = u"login/register.html" | |
16 | |
17 | |
18 def prepare_render(self, request): | |
19 profile = self.getProfile(request) | |
20 if profile is not None: | |
21 self.pageRedirect("/login/logged", request) | |
22 template_data = request.template_data | |
23 template_data["login_url"] = self.getPageByName("login").url | |
24 template_data["S_C"] = C # we need server constants in template | |
25 | |
26 # login error message | |
27 session_data = self.host.getSessionData(request, session_iface.ISATSession) | |
28 login_error = session_data.popPageData(self, "login_error") | |
29 if login_error is not None: | |
30 template_data["login_error"] = login_error | |
31 | |
32 # if fields were already filled, we reuse them | |
33 for k in (u"login", u"email", u"password"): | |
34 template_data[k] = session_data.popPageData(self, k) | |
35 | |
36 | |
37 @defer.inlineCallbacks | |
38 def on_data_post(self, request): | |
39 type_ = self.getPostedData(request, u"type") | |
40 if type_ == u"register": | |
41 login, email, password = self.getPostedData( | |
42 request, (u"login", u"email", u"password") | |
43 ) | |
44 status = yield self.host.registerNewAccount(request, login, password, email) | |
45 session_data = self.host.getSessionData(request, session_iface.ISATSession) | |
46 if status == C.REGISTRATION_SUCCEED: | |
47 # we prefill login field for login page | |
48 session_data.setPageData(self.getPageByName(u"login"), u"login", login) | |
49 # if we have a redirect_url we follow it | |
50 self.redirectOrContinue(request) | |
51 # else we redirect to login page | |
52 self.HTTPRedirect(request, self.getPageByName(u"login").url) | |
53 else: | |
54 session_data.setPageData(self, u"login_error", status) | |
55 l = locals() | |
56 for k in (u"login", u"email", u"password"): | |
57 # we save fields so user doesn't have to enter them again | |
58 session_data.setPageData(self, k, l[k]) | |
59 defer.returnValue(C.POST_NO_CONFIRM) | |
60 else: | |
61 self.pageError(request, C.HTTP_BAD_REQUEST) |