<commit_before>/*
 * oxTrust is available under the MIT License (2008). 
 * See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */

package org.gluu.oxtrust.action;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.faces.context.ExternalContext;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import net.tanesha.recaptcha.ReCaptchaResponse;

import org.gluu.oxtrust.ldap.service.AttributeService;
import org.gluu.oxtrust.ldap.service.IPersonService;
import org.gluu.oxtrust.ldap.service.OrganizationService;
import org.gluu.oxtrust.model.GluuCustomAttribute;
import org.gluu.oxtrust.model.GluuCustomPerson;
import org.gluu.oxtrust.model.GluuOrganization;
import org.gluu.oxtrust.model.RegistrationConfiguration;
import org.gluu.oxtrust.service.custom.CustomScriptService;
import org.gluu.oxtrust.service.external.ExternalUserRegistrationService;
import org.gluu.oxtrust.util.OxTrustConstants;
import org.gluu.oxtrust.util.RecaptchaUtils;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.core.Events;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.faces.Redirect;
import org.jboss.seam.international.StatusMessage;
import org.jboss.seam.log.Log;
import org.xdi.config.oxtrust.ApplicationConfiguration;
import org.xdi.ldap.model.GluuStatus;
import org.xdi.model.GluuAttribute;
import org.xdi.model.GluuUserRole;
import org.xdi.model.custom.script.model.CustomScript;

/**
 * @author <NAME>
 * @author <NAME> Date: 08.14.2015
 */
@Scope(ScopeType.CONVERSATION)
@Name("registerPersonAction")
public class RegisterPersonAction implements Serializable {

	private static final long serialVersionUID = 6002737004324917338L;

	@Logger
	private Log log;

	@In(value = "#{facesContext.externalContext}")
	private ExternalContext externalContext;

	@In
	private AttributeService attributeService;

	@In
	private OrganizationService organizationService;
	
	@In
	Redirect redirect;

	@In(create = true)
	@Out(scope = ScopeType.CONVERSATION)
	private CustomAttributeAction customAttributeAction;

	@In
	private FacesMessages facesMessages;

	@In
	private ExternalUserRegistrationService externalUserRegistrationService;

	private GluuCustomPerson person;

	@In
	private IPersonService personService;

	@NotNull
	@Size(min = 2, max = 30, message = "Length of password should be between 2 and 30")
	private String password;

	@NotNull
	@Size(min = 2, max = 30, message = "Length of password should be between 2 and 30")
	private String repeatPassword;

	@In(value = "#{oxTrustConfiguration.applicationConfiguration}")
	private ApplicationConfiguration applicationConfiguration;

	private List<String> hiddenAttributes;

	private String inum;

	private Map<String, String[]> requestParameters = new HashMap<String, String[]>();

	private boolean captchaDisabled = false;

    private String postRegistrationInformation;

	/**
	 * Initializes attributes for registering new person
	 *
	 * @return String describing success of the operation
	 * @throws Exception
	 */
	public String initPerson() {
		String result = sanityCheck();
		if (result.equals(OxTrustConstants.RESULT_SUCCESS)) {
					
			if(!externalUserRegistrationService.isEnabled()){
				redirect.setViewId("/login.xhtml");
				redirect.execute();
			}  
				
			this.person = (inum == null) ? new GluuCustomPerson() : personService.getPersonByInum(inum);

			boolean isPersonActiveOrDisabled = GluuStatus.ACTIVE.equals(person.getStatus()) || GluuStatus.INACTIVE.equals(person.getStatus());<commit_msg>Use more acurate method to redict user to log in page if registration not enabled<commit_after>/*
 * oxTrust is available under the MIT License (2008). 
 * See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */

package org.gluu.oxtrust.action;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.faces.context.ExternalContext;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import net.tanesha.recaptcha.ReCaptchaResponse;

import org.gluu.oxtrust.ldap.service.AttributeService;
import org.gluu.oxtrust.ldap.service.IPersonService;
import org.gluu.oxtrust.ldap.service.OrganizationService;
import org.gluu.oxtrust.model.GluuCustomAttribute;
import org.gluu.oxtrust.model.GluuCustomPerson;
import org.gluu.oxtrust.model.GluuOrganization;
import org.gluu.oxtrust.model.RegistrationConfiguration;
import org.gluu.oxtrust.service.custom.CustomScriptService;
import org.gluu.oxtrust.service.external.ExternalUserRegistrationService;
import org.gluu.oxtrust.util.OxTrustConstants;
import org.gluu.oxtrust.util.RecaptchaUtils;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.core.Events;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.faces.Redirect;
import org.jboss.seam.international.StatusMessage;
import org.jboss.seam.log.Log;
import org.xdi.config.oxtrust.ApplicationConfiguration;
import org.xdi.ldap.model.GluuStatus;
import org.xdi.model.GluuAttribute;
import org.xdi.model.GluuUserRole;
import org.xdi.model.custom.script.model.CustomScript;

/**
 * @author <NAME>
 * @author <NAME> Date: 08.14.2015
 */
@Scope(ScopeType.CONVERSATION)
@Name("registerPersonAction")
public class RegisterPersonAction implements Serializable {

	private static final long serialVersionUID = 6002737004324917338L;

	@Logger
	private Log log;

	@In(value = "#{facesContext.externalContext}")
	private ExternalContext externalContext;

	@In
	private AttributeService attributeService;

	@In
	private OrganizationService organizationService;
	
	@In
	Redirect redirect;

	@In(create = true)
	@Out(scope = ScopeType.CONVERSATION)
	private CustomAttributeAction customAttributeAction;

	@In
	private FacesMessages facesMessages;

	@In
	private ExternalUserRegistrationService externalUserRegistrationService;

	private GluuCustomPerson person;

	@In
	private IPersonService personService;

	@NotNull
	@Size(min = 2, max = 30, message = "Length of password should be between 2 and 30")
	private String password;

	@NotNull
	@Size(min = 2, max = 30, message = "Length of password should be between 2 and 30")
	private String repeatPassword;

	@In(value = "#{oxTrustConfiguration.applicationConfiguration}")
	private ApplicationConfiguration applicationConfiguration;

	private List<String> hiddenAttributes;

	private String inum;

	private Map<String, String[]> requestParameters = new HashMap<String, String[]>();

	private boolean captchaDisabled = false;

    private String postRegistrationInformation;

	/**
	 * Initializes attributes for registering new person
	 *
	 * @return String describing success of the operation
	 * @throws Exception
	 */
	public String initPerson() {
		String result = sanityCheck();
		if (result.equals(OxTrustConstants.RESULT_SUCCESS)) {

			if(!externalUserRegistrationService.isEnabled()){
				return OxTrustConstants.RESULT_NO_PERMISSIONS;
			}  
				
			this.person = (inum == null) ? new GluuCustomPerson() : personService.getPersonByInum(inum);

			boolean isPersonActiveOrDisabled = GluuStatus.ACTIVE.equals(person.getStatus()) || GluuStatus.INACTIVE.equals(person.getStatus());
{'fraction_non_alphanumeric': 0.10115830115830116, 'fraction_numerical': 0.012097812097812098, 'mean_word_length': 5.613617021276596, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '1794016', 'n_tokens_mistral': 2548, 'n_tokens_neox': 2332, 'n_words': 517}