开发者

Django: set a user as "authenticated" without a page reload

In the webapp I开发者_StackOverflow've built, user authentication is handled in a modal, jQuery window.

My question:

After registration, is it possible to set the user as "authenticated" (in Django's eyes) in the parent window upon closing the modal window without reloading the parent window?

The flow currently goes like this:

1) User visits a page and clicks on a members-only feature

2) Page grays out and a modal jQuery registration box appears (I'm using Colorbox)

3) User registers with my site and closes the modal window

4) Colorbox fires off an "onClosed()" handler to refresh the parent page

I'd like to modify #4 to have the Colorbox handler call a Javascript function to set the user as "authenticated" instead of the coarse method of reloading the page.

Anyone done this before and care to share your advice?


I haven't tried it myself but I would suggest you authenticate/login (from the django.contrib.auth module) the user manually when the user submits the registration from and then render a response that will processed by jquery. This response could be just a status code representing that the account was created successfully. The response is a normal http response so it should contain the cookie info for the new sessionid in the header. This header is processed by the browser before jQuery does anything with it so should be handled the same way as reloading an entire page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜