<commit_before>package org.xcolab.portlets.loginregister;

import com.ext.portlet.Activity.LoginRegisterActivityKeys;
import com.ext.portlet.NoSuchBalloonUserTrackingException;
import com.ext.portlet.community.CommunityConstants;
import com.ext.portlet.model.BalloonUserTracking;
import com.ext.portlet.service.BalloonUserTrackingLocalServiceUtil;
import com.ext.utils.authentication.service.AuthenticationServiceUtil;
import com.ext.utils.iptranslation.Location;
import com.ext.utils.iptranslation.service.IpTranslationServiceUtil;
import com.liferay.portal.NoSuchUserException;
import com.liferay.portal.kernel.captcha.CaptchaException;
import com.liferay.portal.kernel.captcha.CaptchaUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.portal.kernel.util.HttpUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.Image;
import com.liferay.portal.model.User;
import com.liferay.portal.security.permission.PermissionChecker;
import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil;
import com.liferay.portal.security.permission.PermissionThreadLocal;
import com.liferay.portal.service.ImageLocalServiceUtil;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.ServiceContextFactory;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.service.UserServiceUtil;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.PortalUtil;
import com.liferay.portlet.expando.service.ExpandoValueLocalServiceUtil;
import com.liferay.portlet.social.service.SocialActivityLocalServiceUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.validation.Validator;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.portlet.bind.annotation.ResourceMapping;
import org.xcolab.mail.ConnectorEmmaAPI;
import org.xcolab.portlets.loginregister.exception.UserLocationNotResolveableException;
import org.xcolab.portlets.loginregister.singlesignon.SSOKeys;
import org.xcolab.utils.CountryUtil;
import org.xcolab.utils.HtmlUtil;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import javax.portlet.PortletSession;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Date;

@Controller
@RequestMapping("view")
public class MainViewController {

    public static final String SSO_TARGET_KEY = "SSO_TARGET_KEY";

    public static final String SSO_TARGET_REGISTRATION = "SSO_TARGET_REGISTRATION";

    public static final String SSO_TARGET_LOGIN = "SSO_TARGET_LOGIN";

    public static final String PRE_LOGIN_REFERRER_KEY = "PRE_LOGIN_REFERRER_KEY";

    private static final long DEFAULT_COMPANY_ID = 10112L;

	@Autowired
	private Validator validator;
	
	private final static Log _log = LogFactoryUtil.getLog(MainViewController.class);

    @InitBinder("createUserBean")
	public void initBinder(WebDataBinder binder) {
		binder.setValidator(validator);
	}

	/**
	 * Main view displayed for contact form
	 *
	 */
    @RequestMapping
    public String register(PortletRequest request, PortletResponse response, Model model) {
		
		ThemeDisplay themeDisplay = (ThemeDisplay) request
				.getAttribute(WebKeys.THEME_DISPLAY);

		HttpServletRequest httpRequest = PortalUtil
				.getHttpServletRequest(request);

		while (httpRequest instanceof HttpServletRequestWrapper) {
			httpRequest = (HttpServletRequest) ((HttpServletRequestWrapper) httpRequest)
					.getRequest();
		}

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

		if (redirect == null || redirect.trim().isEmpty()) {
			redirect = httpRequest.getParameter("redirect");
			if (redirect == null) {
				redirect = PortalUtil.getHttpServletRequest(request).getHeader(
						"referer");
			}
		}
		if (themeDisplay.isSignedIn()) {
            HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(response);
            try {
                httpServletResponse.sendRedirect("/");
                return "";
            } catch (IOException e) {
            }
		}

        if (com.liferay.portal.kernel.util.Validator.isNotNull(redirect)) {
            model.addAttribute("redirect", com.liferay.portal.kernel.util.HtmlUtil.escape(redirect));
        }

        // append SSO attributes
        CreateUserBean userBean = new CreateUserBean();
        getSSOUserInfo(request.getPortletSession(),userBean);
        model.addAttribute("createUserBean", userBean);

        // Get country location
        if (com.liferay.portal.kernel.util.Validator.isNull(userBean.getCountry())) {
            try {<commit_msg>Changing exception name to match codes standards<commit_after>package org.xcolab.portlets.loginregister;

import com.ext.portlet.Activity.LoginRegisterActivityKeys;
import com.ext.portlet.NoSuchBalloonUserTrackingException;
import com.ext.portlet.community.CommunityConstants;
import com.ext.portlet.model.BalloonUserTracking;
import com.ext.portlet.service.BalloonUserTrackingLocalServiceUtil;
import com.ext.utils.authentication.service.AuthenticationServiceUtil;
import com.ext.utils.iptranslation.Location;
import com.ext.utils.iptranslation.service.IpTranslationServiceUtil;
import com.liferay.portal.NoSuchUserException;
import com.liferay.portal.kernel.captcha.CaptchaException;
import com.liferay.portal.kernel.captcha.CaptchaUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.portal.kernel.util.HttpUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.Image;
import com.liferay.portal.model.User;
import com.liferay.portal.security.permission.PermissionChecker;
import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil;
import com.liferay.portal.security.permission.PermissionThreadLocal;
import com.liferay.portal.service.ImageLocalServiceUtil;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.ServiceContextFactory;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.service.UserServiceUtil;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.PortalUtil;
import com.liferay.portlet.expando.service.ExpandoValueLocalServiceUtil;
import com.liferay.portlet.social.service.SocialActivityLocalServiceUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.validation.Validator;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.portlet.bind.annotation.ResourceMapping;
import org.xcolab.mail.ConnectorEmmaAPI;
import org.xcolab.portlets.loginregister.exception.UserLocationNotResolveableException;
import org.xcolab.portlets.loginregister.singlesignon.SSOKeys;
import org.xcolab.utils.CountryUtil;
import org.xcolab.utils.HtmlUtil;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import javax.portlet.PortletSession;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Date;

@Controller
@RequestMapping("view")
public class MainViewController {

    public static final String SSO_TARGET_KEY = "SSO_TARGET_KEY";

    public static final String SSO_TARGET_REGISTRATION = "SSO_TARGET_REGISTRATION";

    public static final String SSO_TARGET_LOGIN = "SSO_TARGET_LOGIN";

    public static final String PRE_LOGIN_REFERRER_KEY = "PRE_LOGIN_REFERRER_KEY";

    private static final long DEFAULT_COMPANY_ID = 10112L;

	@Autowired
	private Validator validator;
	
	private final static Log _log = LogFactoryUtil.getLog(MainViewController.class);

    @InitBinder("createUserBean")
	public void initBinder(WebDataBinder binder) {
		binder.setValidator(validator);
	}

	/**
	 * Main view displayed for contact form
	 *
	 */
    @RequestMapping
    public String register(PortletRequest request, PortletResponse response, Model model) {
		
		ThemeDisplay themeDisplay = (ThemeDisplay) request
				.getAttribute(WebKeys.THEME_DISPLAY);

		HttpServletRequest httpRequest = PortalUtil
				.getHttpServletRequest(request);

		while (httpRequest instanceof HttpServletRequestWrapper) {
			httpRequest = (HttpServletRequest) ((HttpServletRequestWrapper) httpRequest)
					.getRequest();
		}

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

		if (redirect == null || redirect.trim().isEmpty()) {
			redirect = httpRequest.getParameter("redirect");
			if (redirect == null) {
				redirect = PortalUtil.getHttpServletRequest(request).getHeader(
						"referer");
			}
		}
		if (themeDisplay.isSignedIn()) {
            HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(response);
            try {
                httpServletResponse.sendRedirect("/");
                return "";
            } catch (IOException ignored) {
            }
		}

        if (com.liferay.portal.kernel.util.Validator.isNotNull(redirect)) {
            model.addAttribute("redirect", com.liferay.portal.kernel.util.HtmlUtil.escape(redirect));
        }

        // append SSO attributes
        CreateUserBean userBean = new CreateUserBean();
        getSSOUserInfo(request.getPortletSession(),userBean);
        model.addAttribute("createUserBean", userBean);

        // Get country location
        if (com.liferay.portal.kernel.util.Validator.isNull(userBean.getCountry())) {
            try {
{'fraction_non_alphanumeric': 0.09550803057631195, 'fraction_numerical': 0.001030662200463798, 'mean_word_length': 5.408365437534397, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2567560', 'n_tokens_mistral': 3304, 'n_tokens_neox': 3377, 'n_words': 536}