333 self.state_header() |
334 self.state_header() |
334 self.w(u'</div>') |
335 self.w(u'</div>') |
335 |
336 |
336 def main_header(self, view): |
337 def main_header(self, view): |
337 """build the top menu with authentification info and the rql box""" |
338 """build the top menu with authentification info and the rql box""" |
338 self.w(u'<table id="header"><tr>\n') |
339 w = self.w |
339 self.w(u'<td id="firstcolumn">') |
340 w(u'<table id="header"><tr>\n') |
|
341 w(u'<td id="firstcolumn">') |
340 logo = self._cw.vreg['components'].select_or_none( |
342 logo = self._cw.vreg['components'].select_or_none( |
341 'logo', self._cw, rset=self.cw_rset) |
343 'logo', self._cw, rset=self.cw_rset) |
342 if logo and logo.cw_propval('visible'): |
344 if logo and logo.cw_propval('visible'): |
343 logo.render(w=self.w) |
345 logo.render(w=w) |
344 self.w(u'</td>\n') |
346 w(u'</td>\n') |
345 # appliname and breadcrumbs |
347 # appliname and breadcrumbs |
346 self.w(u'<td id="headtext">') |
348 w(u'<td id="headtext">') |
347 for cid in self.main_cell_components: |
349 for cid in self.main_cell_components: |
348 comp = self._cw.vreg['components'].select_or_none( |
350 comp = self._cw.vreg['components'].select_or_none( |
349 cid, self._cw, rset=self.cw_rset) |
351 cid, self._cw, rset=self.cw_rset) |
350 if comp and comp.cw_propval('visible'): |
352 if comp and comp.cw_propval('visible'): |
351 comp.render(w=self.w) |
353 comp.render(w=self.w) |
352 self.w(u'</td>') |
354 w(u'</td>') |
353 # logged user and help |
355 # logged user and help |
354 self.w(u'<td>\n') |
356 login_components = self._cw.vreg['components'].selectable( |
355 comp = self._cw.vreg['components'].select_or_none( |
|
356 'loggeduserlink', self._cw, rset=self.cw_rset) |
357 'loggeduserlink', self._cw, rset=self.cw_rset) |
357 if comp and comp.cw_propval('visible'): |
358 for comp in login_components: |
358 comp.render(w=self.w) |
359 w(u'<td>\n') |
359 self.w(u'</td>') |
360 if comp.cw_propval('visible'): |
360 # lastcolumn |
361 comp.render(w=w) |
361 self.w(u'<td id="lastcolumn">') |
362 w(u'</td>') |
362 self.w(u'</td>\n') |
363 w(u'</tr></table>\n') |
363 self.w(u'</tr></table>\n') |
|
364 if self._cw.session.anonymous_session: |
|
365 self.wview('logform', rset=self.cw_rset, id='popupLoginBox', |
|
366 klass='hidden', title=False, showmessage=False) |
|
367 |
364 |
368 def state_header(self): |
365 def state_header(self): |
369 state = self._cw.search_state |
366 state = self._cw.search_state |
370 if state[0] == 'normal': |
367 if state[0] == 'normal': |
371 return |
368 return |
436 |
432 |
437 class LogForm(forms.FieldsForm): |
433 class LogForm(forms.FieldsForm): |
438 __regid__ = 'logform' |
434 __regid__ = 'logform' |
439 domid = 'loginForm' |
435 domid = 'loginForm' |
440 needs_css = ('cubicweb.login.css',) |
436 needs_css = ('cubicweb.login.css',) |
|
437 onclick = "javascript: cw.htmlhelpers.popupLoginBox('%s', '%s');" |
441 # XXX have to recall fields name since python is mangling __login/__password |
438 # XXX have to recall fields name since python is mangling __login/__password |
442 __login = ff.StringField('__login', widget=fw.TextInput({'class': 'data'})) |
439 __login = ff.StringField('__login', widget=fw.TextInput({'class': 'data'})) |
443 __password = ff.StringField('__password', label=_('password'), |
440 __password = ff.StringField('__password', label=_('password'), |
444 widget=fw.PasswordSingleInput({'class': 'data'})) |
441 widget=fw.PasswordSingleInput({'class': 'data'})) |
445 form_buttons = [fw.SubmitButton(label=_('log in'), |
442 form_buttons = [fw.SubmitButton(label=_('log in'), |
446 attrs={'class': 'loginButton'})] |
443 attrs={'class': 'loginButton'}), |
|
444 fw.ResetButton(label=_('cancel'), |
|
445 attrs={'class': 'loginButton', |
|
446 'onclick': onclick % ('popupLoginBox', '__login')}),] |
447 |
447 |
448 def form_action(self): |
448 def form_action(self): |
449 if self.action is None: |
449 if self.action is None: |
450 return login_form_url(self._cw) |
450 return login_form_url(self._cw) |
451 return super(LogForm, self).form_action() |
451 return super(LogForm, self).form_action() |
452 |
452 |
453 |
453 |
454 class LogFormView(View): |
454 class LogFormView(View): |
|
455 # XXX an awfull lot of hardcoded assumptions there |
|
456 # makes it unobvious to reuse/specialize |
455 __regid__ = 'logform' |
457 __regid__ = 'logform' |
456 __select__ = match_kwargs('id', 'klass') |
458 __select__ = match_kwargs('id', 'klass') |
457 |
459 |
458 title = 'log in' |
460 title = 'log in' |
459 |
461 |
460 def call(self, id, klass, title=True, showmessage=True): |
462 def call(self, id, klass, title=True, showmessage=True): |
461 self.w(u'<div id="%s" class="%s">' % (id, klass)) |
463 w = self.w |
|
464 w(u'<div id="%s" class="popupLoginBox %s">' % (id, klass)) |
462 if title: |
465 if title: |
463 stitle = self._cw.property_value('ui.site-title') |
466 stitle = self._cw.property_value('ui.site-title') |
464 if stitle: |
467 if stitle: |
465 stitle = xml_escape(stitle) |
468 stitle = xml_escape(stitle) |
466 else: |
469 else: |
467 stitle = u' ' |
470 stitle = u' ' |
468 self.w(u'<div id="loginTitle">%s</div>' % stitle) |
471 w(u'<div class="loginTitle">%s</div>' % stitle) |
469 self.w(u'<div id="loginContent">\n') |
472 w(u'<div class="loginContent">\n') |
470 if showmessage and self._cw.message: |
473 if showmessage and self._cw.message: |
471 self.w(u'<div class="loginMessage">%s</div>\n' % self._cw.message) |
474 w(u'<div class="loginMessage">%s</div>\n' % self._cw.message) |
472 config = self._cw.vreg.config |
475 config = self._cw.vreg.config |
473 if config['auth-mode'] != 'http': |
476 if config['auth-mode'] != 'http': |
474 self.login_form(id) # Cookie authentication |
477 self.login_form(id) # Cookie authentication |
475 self.w(u'</div>') |
478 w(u'</div>') |
476 if self._cw.https and config.anonymous_user()[0]: |
479 if self._cw.https and config.anonymous_user()[0]: |
477 path = xml_escape(config['base-url'] + self._cw.relative_path()) |
480 path = xml_escape(config['base-url'] + self._cw.relative_path()) |
478 self.w(u'<div class="loginMessage"><a href="%s">%s</a></div>\n' |
481 w(u'<div class="loginMessage"><a href="%s">%s</a></div>\n' |
479 % (path, self._cw._('No account? Try public access at %s') % path)) |
482 % (path, self._cw._('No account? Try public access at %s') % path)) |
480 self.w(u'</div>\n') |
483 w(u'</div>\n') |
481 |
484 |
482 def login_form(self, id): |
485 def login_form(self, id): |
483 cw = self._cw |
486 cw = self._cw |
484 form = cw.vreg['forms'].select('logform', cw) |
487 form = cw.vreg['forms'].select('logform', cw) |
485 if cw.vreg.config['allow-email-login']: |
488 if cw.vreg.config['allow-email-login']: |