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">×</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.
精彩评论