How to get redirected to a popup after Facebook login

孤街浪徒 提交于 2020-01-07 02:44:13

问题


on my django app, I have a Facebook connect button (via django allauth). When I click that, the facebook dialog box appears. Now, i want that after login, the user is redirected to a popup (bootstrap modal) with the list of friends of the user.

I have a test function for obtaining the list of friends in my views.py and it works well. What I need is that after the facbook dialog box login, it goes to this function, gets the friendlist, and return the result in a popup on the original page.

I tried setting LOGIN_REDIRECT_URL = '/friends', which takes me to the view function and gets the friendlist, but how do I show this list in that popup? I'm using django-allauth with the bootstrap library.

Any help on this would be greatly appreciated.


回答1:


load the friends page inside a modal

You can use the remote option of the modal to load the html from the friends page inside the modal. See the docs and look for remote.

Add a modal to the page where you want to show the modal:

<div class="modal hide fade" id="myModalFriends" aria-hidden="true" data-show="true">
    <div class="modal-header">
         <h3>Friend list</h3>
    </div>
    <div class="modal-body">Friend page will load here.</div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    </div>
</div>

Then, after successful login:

$('#myModalFriends').modal({
    remote: '/friends'
});

This will load the html from your /friends page inside a modal.

open a modal box the friend page loads

If you want to show your friend list in a modal box on the friends page, you can call $('#myModal').modal(); in document ready to show it on startup; see this fiddle.



来源:https://stackoverflow.com/questions/15697989/how-to-get-redirected-to-a-popup-after-facebook-login

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!