Hey there,

it goes something like this, I sadly dont have access to the exact
code currently... that contains the repoze code

@expose('json')
def somejsonhandler(self, **kw):
     # also possible to manually check permissions with repoze, see
their website
     if not request.identity:
         abort(403) #abort with 403 http code

    # your good code goes here...
     somevalue = u'something'
     someint = 123
     return dict(somevalue=somevalue, someint=someint)

2011/1/10 Timuçin Kızılay <[email protected]>:
> Can you give me a simple example code to show how to use predicate manually
> inside controller methods?
>
>
>
>
> 10-01-2011 19:19, Crusty yazmış:
>>
>> Hello there,
>>
>> maybe this is not the prettiest version, but I had to get going, and I
>> solved a similar problem by not decorating the controller methods that
>> use AJAX with @require decorators. Instead I checked the predicated
>> manually inside the controller methods in question. Solved my problem
>> just fine, so if you just need it to work for now its good. You can
>> always keep a ticket open for the future to make it prettier.
>> Maybe somone else has a cleaner solution.
>>
>> cheers,
>>
>> Tom
>>
>> 2011/1/7 Timuçin Kızılay<[email protected]>:
>>>
>>> 07-01-2011 01:21, Timuçin Kızılay yazmış:
>>>>
>>>>
>>>> I have a code like this in one of my controller code:
>>>> -----------
>>>> @expose('json')
>>>> @require(predicates.has_permission(u'something', msg=u'You do not have
>>>> permission!'))
>>>> def somejsonhandler(self, **kw):
>>>> somevalue = u'something'
>>>> someint = 123
>>>> return dict(somevalue=somevalue, someint=someint)
>>>> ----------
>>>>
>>>> This is called by an ajax code from the browser.
>>>> I can not catch the error, that code always returns status code 200.
>>>>
>>>> I'm using jquery library for ajax.
>>>> The error handler code like this:
>>>> function AJAX_error(xhr, textStatus, errorThrown){
>>>> alert('Message from Server: ' + xhr.status + '\n:\n' + errorThrown +
>>>> '\n:\n' + textStatus);
>>>> };
>>>>
>>>> this javascript is called and I see that status is 200 and it's actually
>>>> sending me the login page and it errors because ajax function was
>>>> waiting for a json response.
>>>>
>>>> can you point me some hints to "how can I get 403 status code or
>>>> something other than 200 ?"
>>>
>>> I'd like to update about this post:
>>>
>>> When the user logged in, I can get 403 status code from javasript. But
>>> when
>>> user is not logged in, controller tries to redirect to login page and I
>>> get
>>> status code 200 and login page from ajax.
>>>
>>> So, this redirect thing is only for 401 response. How can I disable
>>> redirect
>>> for some controller methods that are called by ajax?
>>>
>>> What I want to do is:
>>> some controller methods are web pages so redirect to login page, and
>>> others
>>> are called by javascript ajax functions so they should not redirect to
>>> login
>>> page, they should return 401 or 403 responses so that I can catch the
>>> erron
>>> on javascript side.
>>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "TurboGears" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/turbogears?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to