Mercurial > libervia-web
annotate libervia/web/pages/register/page_meta.py @ 1536:dc81403a5b2f
browser: chat page:
since the move to Brython, the chat was really basic and not really usable. Now that
dynamism has been re-implemented correctly in the new frontend, a real advanced chat page
can be done. This is the first draft in this direction.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 28 Jun 2023 10:05:13 +0200 |
parents | eb00d593801d |
children | 291a7026cb2b |
rev | line source |
---|---|
1216 | 1 #!/usr/bin/env python3 |
1239 | 2 |
963
2932170bb526
pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
1518
eb00d593801d
refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents:
1509
diff
changeset
|
4 from libervia.web.server.constants import Const as C |
eb00d593801d
refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents:
1509
diff
changeset
|
5 from libervia.web.server import session_iface |
963
2932170bb526
pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 from twisted.internet import defer |
1518
eb00d593801d
refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents:
1509
diff
changeset
|
7 from libervia.backend.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 |
1216 | 13 name = "register" |
963
2932170bb526
pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 access = C.PAGES_ACCESS_PUBLIC |
1216 | 15 template = "login/register.html" |
963
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): |
1404
6a35167a4e2c
pages (login, register): fix `allow_registration`:
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
19 if not self.host.options["allow_registration"]: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1506
diff
changeset
|
20 self.page_error(request, C.HTTP_FORBIDDEN) |
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1506
diff
changeset
|
21 profile = self.get_profile(request) |
963
2932170bb526
pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 if profile is not None: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1506
diff
changeset
|
23 self.page_redirect("/login/logged", request) |
963
2932170bb526
pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 template_data = request.template_data |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1506
diff
changeset
|
25 template_data["login_url"] = self.get_page_by_name("login").url |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
963
diff
changeset
|
26 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
|
27 |
2932170bb526
pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 # login error message |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1506
diff
changeset
|
29 session_data = self.host.get_session_data(request, session_iface.IWebSession) |
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1506
diff
changeset
|
30 login_error = session_data.pop_page_data(self, "login_error") |
963
2932170bb526
pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 if login_error is not None: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
963
diff
changeset
|
32 template_data["login_error"] = login_error |
963
2932170bb526
pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
963
diff
changeset
|
34 # if fields were already filled, we reuse them |
1216 | 35 for k in ("login", "email", "password"): |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1506
diff
changeset
|
36 template_data[k] = session_data.pop_page_data(self, k) |
963
2932170bb526
pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
963
diff
changeset
|
38 |
963
2932170bb526
pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 @defer.inlineCallbacks |
2932170bb526
pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 def on_data_post(self, request): |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1506
diff
changeset
|
41 type_ = self.get_posted_data(request, "type") |
1216 | 42 if type_ == "register": |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1506
diff
changeset
|
43 login, email, password = self.get_posted_data( |
1216 | 44 request, ("login", "email", "password") |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
963
diff
changeset
|
45 ) |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1506
diff
changeset
|
46 status = yield self.host.register_new_account(request, login, password, email) |
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1506
diff
changeset
|
47 session_data = self.host.get_session_data(request, session_iface.IWebSession) |
963
2932170bb526
pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 if status == C.REGISTRATION_SUCCEED: |
2932170bb526
pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 # we prefill login field for login page |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1506
diff
changeset
|
50 session_data.set_page_data(self.get_page_by_name("login"), "login", login) |
963
2932170bb526
pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 # if we have a redirect_url we follow it |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1506
diff
changeset
|
52 self.redirect_or_continue(request) |
963
2932170bb526
pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 # else we redirect to login page |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1506
diff
changeset
|
54 self.http_redirect(request, self.get_page_by_name("login").url) |
963
2932170bb526
pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 else: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1506
diff
changeset
|
56 session_data.set_page_data(self, "login_error", status) |
963
2932170bb526
pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 l = locals() |
1216 | 58 for k in ("login", "email", "password"): |
963
2932170bb526
pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 # we save fields so user doesn't have to enter them again |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1506
diff
changeset
|
60 session_data.set_page_data(self, k, l[k]) |
963
2932170bb526
pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 defer.returnValue(C.POST_NO_CONFIRM) |
2932170bb526
pages: added login/logged and register pages
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 else: |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1506
diff
changeset
|
63 self.page_error(request, C.HTTP_BAD_REQUEST) |