annotate libervia/pages/register/page_meta.py @ 1212:ece192e6b4db

install (setup.py): updated sat version
author Goffi <goffi@goffi.org>
date Wed, 24 Jul 2019 20:50:00 +0200
parents 29eb15062416
children b2d067339de3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
963
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2.7
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
3
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from libervia.server.constants import Const as C
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from libervia.server import session_iface
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from twisted.internet import defer
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
7 from sat.core.log import getLogger
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 963
diff changeset
8
1145
29eb15062416 pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
9 log = getLogger(__name__)
963
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
10
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
11 """SàT account registration page"""
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
12
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
13 name = u"register"
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
14 access = C.PAGES_ACCESS_PUBLIC
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
15 template = u"login/register.html"
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
16
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
17
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
18 def prepare_render(self, request):
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
19 profile = self.getProfile(request)
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
20 if profile is not None:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 963
diff changeset
21 self.pageRedirect("/login/logged", request)
963
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
22 template_data = request.template_data
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 963
diff changeset
23 template_data["login_url"] = self.getPageByName("login").url
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 963
diff changeset
24 template_data["S_C"] = C # we need server constants in template
963
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
25
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
26 # login error message
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
27 session_data = self.host.getSessionData(request, session_iface.ISATSession)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 963
diff changeset
28 login_error = session_data.popPageData(self, "login_error")
963
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
29 if login_error is not None:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 963
diff changeset
30 template_data["login_error"] = login_error
963
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
31
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 963
diff changeset
32 #  if fields were already filled, we reuse them
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 963
diff changeset
33 for k in (u"login", u"email", u"password"):
963
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
34 template_data[k] = session_data.popPageData(self, k)
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
35
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 963
diff changeset
36
963
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
37 @defer.inlineCallbacks
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
38 def on_data_post(self, request):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 963
diff changeset
39 type_ = self.getPostedData(request, u"type")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 963
diff changeset
40 if type_ == u"register":
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 963
diff changeset
41 login, email, password = self.getPostedData(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 963
diff changeset
42 request, (u"login", u"email", u"password")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 963
diff changeset
43 )
963
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
44 status = yield self.host.registerNewAccount(request, login, password, email)
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
45 session_data = self.host.getSessionData(request, session_iface.ISATSession)
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
46 if status == C.REGISTRATION_SUCCEED:
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
47 # we prefill login field for login page
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 963
diff changeset
48 session_data.setPageData(self.getPageByName(u"login"), u"login", login)
963
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
49 # if we have a redirect_url we follow it
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
50 self.redirectOrContinue(request)
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
51 # else we redirect to login page
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 963
diff changeset
52 self.HTTPRedirect(request, self.getPageByName(u"login").url)
963
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
53 else:
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
54 session_data.setPageData(self, u"login_error", status)
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
55 l = locals()
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 963
diff changeset
56 for k in (u"login", u"email", u"password"):
963
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
57 # we save fields so user doesn't have to enter them again
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
58 session_data.setPageData(self, k, l[k])
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
59 defer.returnValue(C.POST_NO_CONFIRM)
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
60 else:
2932170bb526 pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff changeset
61 self.pageError(request, C.HTTP_BAD_REQUEST)