Example usage for com.liferay.portal.kernel.util WebKeys FACEBOOK_INCOMPLETE_USER_ID

List of usage examples for com.liferay.portal.kernel.util WebKeys FACEBOOK_INCOMPLETE_USER_ID

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util WebKeys FACEBOOK_INCOMPLETE_USER_ID.

Prototype

String FACEBOOK_INCOMPLETE_USER_ID

To view the source code for com.liferay.portal.kernel.util WebKeys FACEBOOK_INCOMPLETE_USER_ID.

Click Source Link

Usage

From source file:com.liferay.login.authentication.facebook.connect.web.internal.portlet.action.FacebookConnectAction.java

License:Open Source License

protected User setFacebookCredentials(HttpSession session, long companyId, String token) throws Exception {

    JSONObject jsonObject = _facebookConnect.getGraphResources(companyId, "/me", token,
            "id,email,first_name,last_name,gender,verified");

    if ((jsonObject == null) || (jsonObject.getJSONObject("error") != null)) {

        return null;
    }/*from w w w  .j av  a  2s . c  o m*/

    if (_facebookConnect.isVerifiedAccountRequired(companyId) && !jsonObject.getBoolean("verified")) {

        return null;
    }

    User user = null;

    long facebookId = jsonObject.getLong("id");

    if (facebookId > 0) {
        session.setAttribute(FacebookConnectWebKeys.FACEBOOK_ACCESS_TOKEN, token);

        user = _userLocalService.fetchUserByFacebookId(companyId, facebookId);

        if ((user != null) && !user.isActive()) {
            return null;
        } else if ((user != null) && (user.getStatus() != WorkflowConstants.STATUS_INCOMPLETE)) {

            session.setAttribute(FacebookConnectWebKeys.FACEBOOK_USER_ID, String.valueOf(facebookId));
        }
    }

    String emailAddress = jsonObject.getString("email");

    if ((user == null) && Validator.isNotNull(emailAddress)) {
        user = _userLocalService.fetchUserByEmailAddress(companyId, emailAddress);

        if ((user != null) && !user.isActive()) {
            return null;
        } else if ((user != null) && (user.getStatus() != WorkflowConstants.STATUS_INCOMPLETE)) {

            session.setAttribute(WebKeys.FACEBOOK_USER_EMAIL_ADDRESS, emailAddress);
        }
    }

    if (user != null) {
        if (user.getStatus() == WorkflowConstants.STATUS_INCOMPLETE) {
            session.setAttribute(WebKeys.FACEBOOK_INCOMPLETE_USER_ID, facebookId);

            user.setEmailAddress(jsonObject.getString("email"));
            user.setFirstName(jsonObject.getString("first_name"));
            user.setLastName(jsonObject.getString("last_name"));

            return user;
        }

        user = updateUser(user, jsonObject);
    } else {
        user = addUser(session, companyId, jsonObject);
    }

    return user;
}

From source file:com.liferay.login.web.internal.portlet.action.CreateAccountMVCActionCommand.java

License:Open Source License

protected void updateIncompleteUser(ActionRequest actionRequest, ActionResponse actionResponse)
        throws Exception {

    HttpServletRequest request = _portal
            .getOriginalServletRequest(_portal.getHttpServletRequest(actionRequest));

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

    boolean autoPassword = true;
    String password1 = null;/*from  w  w  w.j  a v a 2  s  . co m*/
    String password2 = null;
    boolean autoScreenName = false;
    String screenName = ParamUtil.getString(actionRequest, "screenName");
    String emailAddress = ParamUtil.getString(actionRequest, "emailAddress");

    HttpSession session = request.getSession();

    long facebookId = GetterUtil.getLong(session.getAttribute(WebKeys.FACEBOOK_INCOMPLETE_USER_ID));
    String googleUserId = GetterUtil.getString(session.getAttribute(WebKeys.GOOGLE_INCOMPLETE_USER_ID));

    if (Validator.isNotNull(googleUserId)) {
        autoPassword = false;
    }

    if ((facebookId > 0) || Validator.isNotNull(googleUserId)) {
        password1 = PwdGenerator.getPassword();

        password2 = password1;
    }

    String openId = ParamUtil.getString(actionRequest, "openId");
    String firstName = ParamUtil.getString(actionRequest, "firstName");
    String middleName = ParamUtil.getString(actionRequest, "middleName");
    String lastName = ParamUtil.getString(actionRequest, "lastName");
    long prefixId = ParamUtil.getInteger(actionRequest, "prefixId");
    long suffixId = ParamUtil.getInteger(actionRequest, "suffixId");
    boolean male = ParamUtil.getBoolean(actionRequest, "male", true);
    int birthdayMonth = ParamUtil.getInteger(actionRequest, "birthdayMonth");
    int birthdayDay = ParamUtil.getInteger(actionRequest, "birthdayDay");
    int birthdayYear = ParamUtil.getInteger(actionRequest, "birthdayYear");
    String jobTitle = ParamUtil.getString(actionRequest, "jobTitle");
    boolean updateUserInformation = true;

    boolean sendEmail = true;

    if (Validator.isNotNull(googleUserId)) {
        sendEmail = false;
    }

    ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest);

    User user = _userService.updateIncompleteUser(themeDisplay.getCompanyId(), autoPassword, password1,
            password2, autoScreenName, screenName, emailAddress, facebookId, openId, themeDisplay.getLocale(),
            firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear,
            jobTitle, updateUserInformation, sendEmail, serviceContext);

    if (facebookId > 0) {
        session.removeAttribute(WebKeys.FACEBOOK_INCOMPLETE_USER_ID);

        updateUserAndSendRedirect(actionRequest, actionResponse, themeDisplay, user, password1);

        return;
    }

    if (Validator.isNotNull(googleUserId)) {
        _userLocalService.updateGoogleUserId(user.getUserId(), googleUserId);

        session.removeAttribute(WebKeys.GOOGLE_INCOMPLETE_USER_ID);

        updateUserAndSendRedirect(actionRequest, actionResponse, themeDisplay, user, password1);

        return;
    }

    // Session messages

    if (user.getStatus() == WorkflowConstants.STATUS_APPROVED) {
        SessionMessages.add(request, "userAdded", user.getEmailAddress());
        SessionMessages.add(request, "userAddedPassword", user.getPasswordUnencrypted());
    } else {
        SessionMessages.add(request, "userPending", user.getEmailAddress());
    }

    // Send redirect

    sendRedirect(actionRequest, actionResponse, themeDisplay, user, user.getPasswordUnencrypted());
}