You should be able to do 

if not auth.user: do_whatever_you_like()

instead of using the decorator.

On Thursday, 20 November 2014 07:40:29 UTC-6, Francesco S wrote:
>
> I am novice in web2py. I am developing an angularjs+web2py web 
> application. 
> In addition to using web2py to write the APIs, at least at the first 
> stage, 
> I would like to use the web2py authentication class (i.e., no API approach 
> for authentication)
> and to have it working even when calling the APIs using curl.
> Anyhow, I do not want to use decorators to force authentication for the 
> APIs but I need to 
> handle it manually (e.g., the some APIs should return different results if 
> the user is   
> logged or not logged but the APIs must always return a result).
>
> To clarify, I would like to write something like that:
>
> auth.settings.allow_basic_login = True
> @request.restful()
> @auth.requires(True, requires_login=False)   # ===> WORKAROUND
> def api_auth_test():
>     response.view = 'generic.json'
>     import gluon.contrib.simplejson
>     def GET():
>         if auth.is_logged_in():
>             return gluon.contrib.simplejson.dumps(dict(results="I am 
> logged"))
>         else:   
>             return gluon.contrib.simplejson.dumps(dict(results="I am NOT 
> logged"))
>     return locals()                                                     
>
>
> But it seems that the authorization works only if I include an 
> authorization decorator 
> which I do not want to add. As a workaround I added the fake decorator
> @auth.requires(True, requires_login=False)
> and it seems to work but I wonder if I am missing something and if there 
> is a clean
> way to achieve the result. Thanks.
>
> Francesco
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to