I want to make authentication in my web app, when some actions occured on page. For example user click button “add to cart” and if he not yet authenticated, then signIn page displayed. After signIn it returns back to previos page.
What i can use in wicket to implement this?
P.S. On product page i have also link “buy now”, which navigate to Buy page with @AuthorizeInstantiation(“USER”) annotation. This link work just fine.
I think MetaDataRoleAuthorizationStrategy can be used to make the same on “add to cart”. But available actions is ENABLE and RENDER only. I can add my own Action to component, but how can i associate Action with onClick() method of component?
—Edited—
Don’t know where to write, so i edit the post. I try Christoph Leiter’s solution:
add(link = new AjaxFallbackLink("add2cart") {
@Override
public void onClick(AjaxRequestTarget target) {
if (!CynephoneSession.get().isSignedIn()) {
throw new RestartResponseAtInterceptPageException(SignIn.class);
}
user.addItem(item.copy());
target.add(cartPanel);
}
});
but after i clicked this link somehow i see ajax response with updated cartPanel in firefox. I mean it show me page with source code:
<?xml version="1.0" encoding="UTF-8"?><ajax-response><component id="cart2" ><![CDATA[<div class="cart" wicket:id="cart" id="cart2">
<span wicket:id="total">11 800</span> <img src="./resource/top.Top/img/rouble-ver-1346040298957.gif"/><br/>
<img src="./resource/top.Top/img/good-ver-1346040298926.gif"/>х<span wicket:id="quantity">2</span>
</div>]]></component></ajax-response>
Don’t understand how it pass the Exception…
I’m not an expert with the authroles module, so I’m not sure whether it’s possible to add another Action to accomplish what you want. I would just use something like that:
In your
LoginPage/Sessionyou should check if there’s a product in the session that should be added to the cart when the user is authenticated successfully. Then callcontinueToOriginalDestinationso that Wicket displays the previous page (orsetResponsePage(CartPage.class)).There may be a better way than to do this “manually”, but this should work.