Example usage for com.liferay.portal.struts ActionConstants COMMON_REFERER

List of usage examples for com.liferay.portal.struts ActionConstants COMMON_REFERER

Introduction

In this page you can find the example usage for com.liferay.portal.struts ActionConstants COMMON_REFERER.

Prototype

String COMMON_REFERER

To view the source code for com.liferay.portal.struts ActionConstants COMMON_REFERER.

Click Source Link

Usage

From source file:com.liferay.portlet.login.action.FacebookConnectAction.java

License:Open Source License

@Override
public ActionForward strutsExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    if (!FacebookConnectUtil.isEnabled(themeDisplay.getCompanyId())) {
        return null;
    }// w  w  w .j  a  v a2 s . c o m

    HttpSession session = request.getSession();

    String redirect = ParamUtil.getString(request, "redirect");

    String code = ParamUtil.getString(request, "code");

    String token = FacebookConnectUtil.getAccessToken(themeDisplay.getCompanyId(), redirect, code);

    if (Validator.isNotNull(token)) {
        session.setAttribute(WebKeys.FACEBOOK_ACCESS_TOKEN, token);

        setFacebookCredentials(session, themeDisplay.getCompanyId(), token);
    } else {
        return mapping.findForward(ActionConstants.COMMON_REFERER);
    }

    response.sendRedirect(redirect);

    return null;
}

From source file:com.liferay.portlet.login.action.GoogleConnectAction.java

License:Apache License

@Override
public ActionForward strutsExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    if (!GoogleConnectUtil.isEnabled(themeDisplay.getCompanyId())) {
        return null;
    }//from  w w  w.j  a va  2 s  .co  m

    HttpSession session = request.getSession();

    String redirect = ParamUtil.getString(request, "redirect", (String) session.getAttribute(WebKeys.REDIRECT));
    String code = ParamUtil.getString(request, "code");

    if (_log.isDebugEnabled()) {
        _log.debug("strutsExecute code=" + code + ", redirect=" + redirect);
    }

    String token = GoogleConnectUtil.getAccessToken(themeDisplay.getCompanyId(), redirect, code);

    if (_log.isDebugEnabled()) {
        _log.debug("strutsExecute token =" + token);
    }

    if (Validator.isNotNull(token)) {

        session.setAttribute(GoogleWebKeys.GOOGLE_ACCESS_TOKEN, token);

        setGoogleCredentials(session, themeDisplay.getCompanyId(), token);

    } else {
        return mapping.findForward(ActionConstants.COMMON_REFERER);
    }

    if (Validator.isNull(redirect)) {
        redirect = themeDisplay.getURLSignIn();
    }

    response.sendRedirect(redirect);

    return null;
}