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