Thanks a lot for reply. It is the problem.
And there is minor change in fff function needed
def fff(args):
raise HTTP(403, "HTTP 403: Not authenticated to access this URL.")
because if do not put args in fff(), it complains error
Now it works fine. Thanks a lot!
This forum is really useful and thanks all!
On Oct 19, 11:58 am, Anthony <[email protected]> wrote:
> I think you actually want:
>
> auth.settings.on_failed_authentication = fff
>
> Note, authentication rather than authorization. I believe
> on_failed_authentication will be called before any redirect to the login
> page, and on_failed_authorization gets called after login if the condition
> for authorization fails.
>
> Anthony
>
>
>
>
>
>
>
> On Wednesday, October 19, 2011 11:31:25 AM UTC-4, d wrote:
>
> > Thanks Anthony,
>
> > After change to
>
> > auth.settings.on_failed_authorization = fff
>
> > for controller which requires log in and if user not logged in, it
> > redirect to log in page. But purpose of using fff function is to raise
> > http error but not redirecting to log in page.
>
> > def fff():
> > raise HTTP(403, "Http 403, Login failed or Not logged in")
>
> > auth.settings.on_failed_authorization = fff
>
> > so, any idea where is problem? is it because fff() function is not
> > right?
>
> > Thanks a lot.
>
> > On Oct 19, 10:36 am, Anthony <[email protected]> wrote:
> > > You should do:
>
> > > auth.settings.on_failed_authorization = fff
>
> > > You were calling the function fff() instead of assigning it to
> > > on_failed_authorization. Auth will call the function itself at the
> > > appropriate time.
>
> > > Anthony
>
> > > On Wednesday, October 19, 2011 10:21:18 AM UTC-4, d wrote:
>
> > > > Hi All,
>
> > > > I am newbie in web2py, and currently work on web service of model
> > > > part, say if user is logged in, then then can see the data, otherwise
> > > > I want to raise http 403 error but not redirect user to log in page.
> > > > Right now seems redirect user to log in page is default option.
>
> > > > I tried but failed, here is what I tried:
>
> > > > 1. In Models, db.py
>
> > > > add
>
> > > > def fff():
> > > > raise HTTP(403, "Http 403, Login failed or Not logged in")
>
> > > > auth.settings.on_failed_authorization = fff()
>
> > > > So, I want to tell web2py if on failed authorization, call function
> > > > fff(), which will raise http 403 error
>
> > > > 2. In controller,
> > > > say a.py
>
> > > > in a function
>
> > > > @auth.requires_login()
> > > > def aaa():
> > > > ........
>
> > > > so it says function aaa required logged in, and if not logged in, it
> > > > should see auth.settings.on_failed_authorization = fff() in db.py
>
> > > > but somehow it did not works, because for all the controller and
> > > > normal view, it always display this http 403 error, I dont know where
> > > > is the problem, can someone help me, thanks a lot!