1 """authentication using google authentication service |
1 """authentication using google authentication service |
2 |
2 |
3 :organization: Logilab |
3 :organization: Logilab |
4 :copyright: 2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
4 :copyright: 2008-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 """ |
6 """ |
7 __docformat__ = "restructuredtext en" |
7 __docformat__ = "restructuredtext en" |
8 |
8 |
9 from cubicweb.common.registerers import priority_registerer |
|
10 from cubicweb.web.views.basecomponents import UserLink |
9 from cubicweb.web.views.basecomponents import UserLink |
11 from cubicweb.web.views.actions import LogoutAction |
10 from cubicweb.web.views.actions import LogoutAction |
12 |
11 |
13 from google.appengine.api import users |
12 from google.appengine.api import users |
14 |
13 |
15 |
14 |
16 class use_google_auth_registerer(priority_registerer): |
|
17 """register object if use-google-auth is true""" |
|
18 |
|
19 def do_it_yourself(self, registered): |
|
20 if not hasattr(self.config, 'has_resource'): |
|
21 return |
|
22 return super(use_google_auth_registerer, self).do_it_yourself(registered) |
|
23 |
|
24 |
|
25 class GAEUserLink(UserLink): |
15 class GAEUserLink(UserLink): |
26 __registerer__ = use_google_auth_registerer |
|
27 |
16 |
28 def anon_user_link(self): |
17 def anon_user_link(self): |
29 self.w(self.req._('anonymous')) |
18 self.w(self.req._('anonymous')) |
30 self.w(u' [<a class="logout" href="%s">%s</a>]' |
19 self.w(u' [<a class="logout" href="%s">%s</a>]' |
31 % (users.create_login_url(self.req.url()), self.req._('login'))) |
20 % (users.create_login_url(self.req.url()), self.req._('login'))) |
32 |
21 |
33 class GAELogoutAction(LogoutAction): |
22 class GAELogoutAction(LogoutAction): |
34 __registerer__ = use_google_auth_registerer |
|
35 |
23 |
36 def url(self): |
24 def url(self): |
37 return users.create_logout_url(self.req.build_url('logout') ) |
25 return users.create_logout_url(self.req.build_url('logout') ) |
|
26 |
|
27 def registration_callback(vreg): |
|
28 if hasattr(vreg.config, 'has_resource'): |
|
29 vreg.register(GAEUserLink, clear=True) |
|
30 vreg.register(GAELogoutAction, clear=True) |