Mercurial > libervia-web
comparison src/pages/register/page_meta.py @ 963:2932170bb526
pages: added login/logged and register pages
- login page will redirect to logged if a session is already active
- if a redirect url is set, use will be redirected to it when login/registration is successful
- logged page allow to disconnect profile
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 27 Oct 2017 18:47:07 +0200 |
parents | |
children | cdd389ef97bc |
comparison
equal
deleted
inserted
replaced
962:c7fba7709d05 | 963:2932170bb526 |
---|---|
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 log = getLogger('pages/register') | |
9 | |
10 """SàT account registration page""" | |
11 | |
12 name = u"register" | |
13 access = C.PAGES_ACCESS_PUBLIC | |
14 template = u"login/register.html" | |
15 | |
16 | |
17 def prepare_render(self, request): | |
18 profile = self.getProfile(request) | |
19 if profile is not None: | |
20 self.pageRedirect('/login/logged', request) | |
21 template_data = request.template_data | |
22 template_data['login_url'] = self.getPageByName('login').url | |
23 template_data['S_C'] = C # we need server constants in template | |
24 | |
25 # login error message | |
26 session_data = self.host.getSessionData(request, session_iface.ISATSession) | |
27 login_error = session_data.popPageData(self, 'login_error') | |
28 if login_error is not None: | |
29 template_data['login_error'] = login_error | |
30 | |
31 # if fields were already filled, we reuse them | |
32 for k in (u'login', u'email', u'password'): | |
33 template_data[k] = session_data.popPageData(self, k) | |
34 | |
35 @defer.inlineCallbacks | |
36 def on_data_post(self, request): | |
37 type_ = self.getPostedData(request, u'type') | |
38 if type_ == u'register': | |
39 login, email, password = self.getPostedData(request, (u'login', u'email', u'password')) | |
40 status = yield self.host.registerNewAccount(request, login, password, email) | |
41 session_data = self.host.getSessionData(request, session_iface.ISATSession) | |
42 if status == C.REGISTRATION_SUCCEED: | |
43 # we prefill login field for login page | |
44 session_data.setPageData(self.getPageByName(u'login'), u'login', login) | |
45 # if we have a redirect_url we follow it | |
46 self.redirectOrContinue(request) | |
47 # else we redirect to login page | |
48 self.HTTPRedirect(request, self.getPageByName(u'login').url) | |
49 else: | |
50 session_data.setPageData(self, u"login_error", status) | |
51 l = locals() | |
52 for k in (u'login', u'email', u'password'): | |
53 # we save fields so user doesn't have to enter them again | |
54 session_data.setPageData(self, k, l[k]) | |
55 defer.returnValue(C.POST_NO_CONFIRM) | |
56 else: | |
57 self.pageError(request, C.HTTP_BAD_REQUEST) |