Posted By

wpodgorski on 04/15/13


Tagged


Versions (?)

LoginPostAction


 / Published in: Java
 

Marcin

  1. import java.io.IOException;
  2.  
  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;
  5.  
  6. import com.liferay.portal.kernel.events.Action;
  7. import com.liferay.portal.kernel.events.ActionException;
  8. import com.liferay.portal.kernel.log.Log;
  9. import com.liferay.portal.kernel.log.LogFactoryUtil;
  10. import com.liferay.portal.kernel.struts.LastPath;
  11. import com.liferay.portal.kernel.util.WebKeys;
  12. import com.uds.hbo.commons.util.PageConstants;
  13. import com.uds.hbo.commons.util.SessionConstants;
  14. import com.uds.hbo.commons.web.url.ApplicationURL;
  15.  
  16. public class LoginPostAction extends Action {
  17.  
  18. private static Log LOG = LogFactoryUtil.getLog(LoginPostAction.class);
  19.  
  20. @Override
  21. public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException {
  22.  
  23. String voucher = (String) request.getSession().getAttribute(SessionConstants.VOUCHER);
  24. LastPath lastPath = (LastPath) request.getSession().getAttribute(WebKeys.LAST_PATH);
  25. String redirectiontUrl = (String) request.getSession().getAttribute(PageConstants.REDIRECTION_URL);
  26. String uri = request.getRequestURI();
  27.  
  28. // In case of order completed or canceled
  29. if (uri.contains(ApplicationURL.ORDER_CANCEL.getUrl()) || uri.contains(ApplicationURL.ORDER_COMPLETE.getUrl())) {
  30. return;
  31. }
  32. // In case of voucher passed by user
  33. if (voucher != null && voucher.length() > 0) {
  34. tryToRedirect(response, redirectiontUrl);
  35. // In case of redirection to Payex service from iframe
  36. } else if (redirectiontUrl != null) {
  37. tryToRedirect(response, PageConstants.CONTINUE_WITH_PAYMENTS);
  38. // In case there is no last path
  39. } else if (lastPath == null) {
  40. tryToRedirect(response, "/home");
  41. // In other cases redirect to: <host>/<contextPath>/<lastPath>
  42. } else {
  43. String contextPath = lastPath.getContextPath();
  44. String path = lastPath.getPath();
  45.  
  46. if (contextPath != null && contextPath.length() > 0) {
  47. s.append(contextPath);
  48. }
  49. s.append(path);
  50.  
  51. tryToRedirect(response, s.toString());
  52. }
  53. }
  54.  
  55. private void tryToRedirect(HttpServletResponse response, String path) {
  56. try {
  57. if (LOG.isDebugEnabled()) {
  58. LOG.debug("Trying to redirect to " + path);
  59. }
  60. response.sendRedirect(path);
  61. } catch (IOException e) {
  62. LOG.error("Cannot redirect after login to " + path, e);
  63. }
  64. }
  65.  
  66. }

Report this snippet  

You need to login to post a comment.