Como editar um decoratordo web2py

23 views
Skip to first unread message

Kimus

unread,
Jul 30, 2019, 2:29:09 AM7/30/19
to web2py-users
Ola estou com um problema , estou trabalhando com um template usando bootstrap (peguei na net ) diferente do web2py logo tenho que fazer td na mão e até msm inventar as coisas pra fazer acontecer, e agora estou com um problem, tenho um controllor chamado template e nele em uma das funções eu uso o decorator @auth.requires_login() funciona , só que ele redireciona parao controler default/user/login eeu quero que ele redifrecione pra outro controler, teria como editar essa decorator para isso ??

Константин Комков

unread,
Jul 30, 2019, 7:14:27 AM7/30/19
to web...@googlegroups.com
As variant, you can write decorator by yourself, like:
def yourDecorator(fun):
   def decorated():

        if (auth.user_id is not None):
           redirect(URL('yourController','yourFunction'))
       else:
           return fun()
   return decorated

@yourDecorator
def yourFunction():




Dave S

unread,
Jul 30, 2019, 5:08:47 PM7/30/19
to web2py-users


On Monday, July 29, 2019 at 11:29:09 PM UTC-7, Kimus wrote:
Ola estou com um problema , estou trabalhando com um template usando bootstrap (peguei na net ) diferente do web2py logo tenho que fazer td na mão e até msm inventar as coisas pra fazer acontecer, e agora estou com um problem, tenho um controllor chamado template e nele em uma das funções eu uso o decorator @auth.requires_login() funciona , só que ele redireciona parao controler default/user/login eeu quero que ele redifrecione pra outro controler, teria como editar essa decorator para isso ??

[Per Google Translate, you're using a different template for your views, and you have some controller  functions decorated with "@auth.requires_login()",
and you don't want to redirect to default/user/login.

Why do you want to redirect to another controller or function, rather than giving your user a chance to login? 

If you want to use a different login method than the "out of the box" method, then you should be reading Chapter 9 on Access Control.  That's also where you will find the information about the settings auth.settings.login_url and auth.settings.on_failed_authorization.
<URL:http://web2py.com/books/default/chapter/29/09/access-control#Auth-Settings-and-messages>

Good luck!

/dps

Reply all
Reply to author
Forward
0 new messages