开发者

Intercept Secure URLs on Client Side

I implemented a nice popup modal login dialog for my main page. When I click on the link I am using:

$(document).ready(function() {
        $('#loginButton').click(function(e) {
            $.ajax({
                url: "@{Secure.login()}",
                success: function(data) {
                    $("#myModal").html(data + '<a class="close-reveal-modal">&#215;</a>');
                    $('#myModal').reveal();
                }
            });
        });
    });

My application is designed that some controllers need authentication from the user and is redirected before to the login view.

What I want to do is that if the user is accessing a secure controller he needs to see the login开发者_JAVA技巧 popup screen instead of beeing redirected to the view so that I have the same user experience.

I already got a suggestion from google groups:

a) It would be nicest to intercept all secure links already on the client side with some JavaScript and show your modal dialog. This is independent from what the secure module provides.

But dont know how to implement this or if there is already a solution for this out there.


Your question is really from jQuery category, not ajax or playframework or web-security. In case all your secure links start with https://

    $('a[href^="https://"]').click(// function here);

in case your links are marked with .secure class:

    $('a.secure').click(// function here);

the function will show popup modal login dialog, return false and redirect user to the original link url in the end of success callback.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜