26 _ = unicode |
26 _ = unicode |
27 |
27 |
28 from logilab.mtconverter import xml_escape |
28 from logilab.mtconverter import xml_escape |
29 from rql import parse |
29 from rql import parse |
30 |
30 |
31 from cubicweb.selectors import (yes, multi_etypes_rset, |
31 from cubicweb.selectors import (yes, multi_etypes_rset, match_form_params, |
32 match_form_params, match_context, |
32 match_context, configuration_values, |
33 anonymous_user, authenticated_user) |
33 anonymous_user, authenticated_user) |
34 from cubicweb.schema import display_name |
34 from cubicweb.schema import display_name |
35 from cubicweb.utils import wrap_on_write |
35 from cubicweb.utils import wrap_on_write |
36 from cubicweb.uilib import toggle_action |
36 from cubicweb.uilib import toggle_action |
37 from cubicweb.web import component |
37 from cubicweb.web import component |
95 |
95 |
96 class _UserLink(component.Component): |
96 class _UserLink(component.Component): |
97 """if the user is the anonymous user, build a link to login else display a menu |
97 """if the user is the anonymous user, build a link to login else display a menu |
98 with user'action (preference, logout, etc...) |
98 with user'action (preference, logout, etc...) |
99 """ |
99 """ |
|
100 __abstract__ = True |
100 cw_property_defs = VISIBLE_PROP_DEF |
101 cw_property_defs = VISIBLE_PROP_DEF |
101 # don't want user to hide this component using an cwproperty |
102 # don't want user to hide this component using an cwproperty |
102 site_wide = True |
103 site_wide = True |
103 __regid__ = 'loggeduserlink' |
104 __regid__ = 'loggeduserlink' |
104 |
105 |
105 |
106 |
106 class AnonUserLink(_UserLink): |
107 class CookieAnonUserLink(_UserLink): |
107 __select__ = _UserLink.__select__ & anonymous_user() |
108 __select__ = _UserLink.__select__ & configuration_values('auth-mode', 'cookie') & anonymous_user() |
108 def call(self): |
109 loginboxid = 'popupLoginBox' |
109 if self._cw.vreg.config['auth-mode'] == 'cookie': |
110 |
110 self.w(self._cw._('anonymous')) |
111 def call(self): |
111 self.w(u''' [<a class="logout" href="javascript: popupLoginBox();">%s</a>]''' |
112 w = self.w |
112 % (self._cw._('i18n_login_popup'))) |
113 w(self._cw._('anonymous')) |
113 else: |
114 w(u"""[<a class="logout" href="javascript: cw.htmlhelpers.popupLoginBox('%s', '__login');">%s</a>]""" |
114 self.w(self._cw._('anonymous')) |
115 % (self.loginboxid, self._cw._('i18n_login_popup'))) |
115 self.w(u' [<a class="logout" href="%s">%s</a>]' |
116 self.wview('logform', rset=self.cw_rset, id=self.loginboxid, |
116 % (self._cw.build_url('login'), self._cw._('login'))) |
117 klass='hidden', title=False, showmessage=False) |
117 |
118 |
|
119 class HTTPAnonUserLink(_UserLink): |
|
120 __select__ = _UserLink.__select__ & configuration_values('auth-mode', 'http') & anonymous_user() |
|
121 loginboxid = 'popupLoginBox' |
|
122 |
|
123 def call(self): |
|
124 w = self.w |
|
125 w(self._cw._('anonymous')) |
|
126 # this redirects to the 'login' controller which in turn |
|
127 # will raise a 401/Unauthorized |
|
128 w(u' [<a class="logout" href="%s">%s</a>]' |
|
129 % (self._cw.build_url('login'), self._cw._('login'))) |
118 |
130 |
119 class UserLink(_UserLink): |
131 class UserLink(_UserLink): |
120 __select__ = _UserLink.__select__ & authenticated_user() |
132 __select__ = _UserLink.__select__ & authenticated_user() |
121 |
133 |
122 def call(self): |
134 def call(self): |