1 # vim: set et sw=4 sts=4 encoding=utf-8 :
3 from turbogears import controllers, expose
4 from turbogears import widgets as w, validators
5 from turbogears import identity, redirect
6 from cherrypy import request, response
8 # from sercom import json
11 log = logging.getLogger("sercom.controllers")
13 class Root(controllers.RootController):
15 @expose(template='.templates.welcome')
16 @identity.require(identity.has_permission('entregar'))
19 log.debug('Happy TurboGears Controller Responding For Duty')
20 return dict(now=time.ctime())
22 @expose(template='.templates.login')
23 def login(self, forward_url=None, previous_url=None, tg_errors=None, *args,
27 flash(_(u'Hubo un error en el formulario!'))
29 if not identity.current.anonymous \
30 and identity.was_login_attempted() \
31 and not identity.get_identity_errors():
32 raise redirect(forward_url)
35 previous_url = request.path
37 if identity.was_login_attempted():
38 msg = _(u'Las credenciales proporcionadas no son correctas o no '
39 'le dan acceso al recurso solicitado.')
40 elif identity.get_identity_errors():
41 msg = _(u'Debe proveer sus credenciales antes de acceder a este '
44 msg = _(u'Por favor ingrese.')
45 forward_url = request.headers.get('Referer', '/')
48 w.TextField(name='login_user', label=_(u'Usuario'),
49 validator=validators.NotEmpty()),
50 w.PasswordField(name='login_password', label=_(u'Contraseña'),
51 validator=validators.NotEmpty())
54 fields.append(w.HiddenField(name='forward_url'))
55 fields.extend([w.HiddenField(name=name) for name in request.params
56 if name not in ('login_user', 'login_password', 'login_submit',
59 submit = w.SubmitButton(name='login_submit')
61 login_form = w.TableForm(fields=fields, action=previous_url,
62 submit_text=_(u'Ingresar'), submit=submit)
64 values = dict(forward_url=forward_url)
65 values.update(request.params)
68 return dict(login_form=login_form, form_data=values, message=msg,
73 identity.current.logout()