Mercurial > libervia-web
annotate src/pages/g/page_meta.py @ 933:e4c13a995e0b
pages (common/blog): data post (i.e. new comments) is now handled
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 17 Apr 2017 20:44:10 +0200 |
parents | b5490fa65348 |
children | 9be057e23ce6 |
rev | line source |
---|---|
930
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python2.7 |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 from libervia.server.constants import Const as C |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 from sat.core.i18n import _ |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 from twisted.internet import defer |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 from libervia.server import session_iface |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 from sat.core.log import getLogger |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 log = getLogger('pages/g') |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 access = C.PAGES_ACCESS_PUBLIC |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 template = u"invitation/welcome.html" |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 @defer.inlineCallbacks |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 def parse_url(self, request): |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 """check invitation id in URL and start session if needed |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 if a session already exists for an other guest/profile, it will be purged |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 """ |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 try: |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 invitation_id = self.nextPath(request) |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 except IndexError: |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 self.pageError(request) |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 sat_session, guest_session = self.host.getSessionData(request, session_iface.ISATSession, session_iface.ISATGuestSession) |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 current_id = guest_session.id |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 if current_id is not None and current_id != invitation_id: |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 log.info(_(u'killing guest session [{old_id}] because it is connecting with an other ID [{new_id}]').format( |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 old_id = current_id, |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 new_id = invitation_id)) |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 self.host.purgeSession(request) |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 sat_session, guest_session = self.host.getSessionData(request, session_iface.ISATSession, session_iface.ISATGuestSession) |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 current_id = None # FIXME: id non mis à zéro ici |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 profile = None |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 profile = sat_session.profile |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 if profile is not None and current_id is None: |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 log.info(_(u'killing current profile session [{profile}] because a guest id is used').format( |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 profile = profile)) |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 self.host.purgeSession(request) |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 sat_session, guest_session = self.host.getSessionData(request, session_iface.ISATSession, session_iface.ISATGuestSession) |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 profile = None |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 if current_id is None: |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 log.debug(_(u"checking invitation [{id}]").format(id=invitation_id)) |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 try: |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 data = yield self.host.bridge.invitationGet(invitation_id) |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 except Exception: |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 self.pageError(request, 401) |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 else: |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 guest_session.id = invitation_id |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 guest_session.data = data |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 else: |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 data = guest_session.data |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 if profile is None: |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 log.debug(_(u"connecting profile [{}]").format(profile)) |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 # we need to connect the profile |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 profile = data['guest_profile'] |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 password = data['password'] |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 try: |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 yield self.host.bridge.connect(profile, password, {}) |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 except Exception as e: |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 log.warning(_(u"Can't connect profile: {msg}").format( |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 msg=e)) |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 # FIXME: no good error code correspond |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 # maybe use a custom one? |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 self.pageError(request, code=503) |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 log.info(_(u"guest session started, connected with profile [{profile}]".format( |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 profile = profile))) |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 sat_session.profile = profile |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 def prepare_render(self, request): |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 template_data = request.template_data |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 guest_session = self.host.getSessionData(request, session_iface.ISATGuestSession) |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 main_uri = guest_session.data.get('main_uri') |
b5490fa65348
pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 template_data[u"include_url"] = self.getPagePathFromURI(main_uri) |