<commit_before>package src.controller;

import java.sql.SQLException;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

import src.model.dao.concrete.*;
import src.model.*;

/**
*Class which implements methods about user's mainteinance
*/
public class GestioneUtenza{
	
	/**
	*Method used to login into the platform
	*
	*@param username user's username
	*@param password <PASSWORD>
	*@return Utente istance of user
	*/
	public Utente logIn(String username, String password){
		try{
			if( new UtenteDao().findUserByUsername(username) == null ){ return null; }		
			
			Utente utente = new UtenteDao().findUserByUsername(username);
			//Mysql is case insensitive
			if ( !utente.getUsername().equals(username) ){
				return null;
			}
			if( password.equals(utente.getPassword()) ){
				return utente;
			}
			return null;
		}
		catch(SQLException exc){
			exc.printStackTrace();
		}
		return null;
	} 
	
	/**
	*Method used to find a user by his username
	*
	*@param username user's username
	*@return Utente istance of user
	*/
	public Utente findUser(String username){
		try{
			return new UtenteDao().findUserByUsername(username);
		}
		catch(SQLException exc){
			exc.printStackTrace();
		}
		return null;
	} 
	
	
	/**
	*Method used to sign up into the platform
	*
	*@param name user's name
	*@param surname user's surname
	*@param username user's username
	*@param mail user's email
	*@param password <PASSWORD>
	*@param password2 <PASSWORD>
	*@return int information number about enrolment status
	*/
	public int signUp(String name, String surname, String username, String mail, String password, String password2){
		
		Pattern VALID_EMAIL_ADDRESS_REGEX = Pattern.compile("^[\\w!#$%&â€™*+/=?`{|}~^-]+(?:\\.[\\w!#$%&â€™*+/=?`{|}~^-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
		
		Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(mail);
		
		try{
			if( name.equals("") || surname.equals("") || username.equals("") || mail.equals("") || password.equals("") || password2.equals("") )
				return 1;
			if( new UtenteDao().usernameAlreadyUsed(username) )
				return 2;
			if( new UtenteDao().emailAlreadyUsed(mail) )
				return 3;
			if( !matcher.find() ) 
				return 4;
			if( password2.length() < 8 )
				return 5;
			if( !password.equals(password2) )
				return 6;
			Utente ut = new Utente(name,surname,username,mail,password);
		
			new UtenteDao().insertUser(ut);
			return 0;
		}
		catch(SQLException exc){
			exc.printStackTrace();
		}
		return -1;
	}
	
	/**
	*Method to update user's informations
	*
	*@param column value to be changed
	*@param newValue new value for the column
	*@param utente user that receives the update
	*@return String message to be displayed
	*/
	public String updateValue(String column, String newValue, Utente utente){
		
		try{
			switch( column ){
				
				case "nome":		new UtenteDao().updateUser(column, newValue, utente);
							utente.setNome(newValue);
							return "Nome aggiornato!";
								
				case "cognome":		new UtenteDao().updateUser(column, newValue, utente);
							utente.setCognome(newValue);
							return "Cognome aggiornato!";
								
				case "username":	if(new UtenteDao().usernameAlreadyUsed(newValue))
								return "Username gia' in uso!";
							new UtenteDao().updateUser(column, newValue, utente);
							utente.setUsername(newValue);
							return "Username aggiornato!";
									
				case "email":		Pattern VALID_EMAIL_ADDRESS_REGEX = Pattern.compile("^[\\w!#$%&â€™*+/=?`{|}~^-]+(?:\\.[\\w!#$%&â€™*+/=?`{|}~^-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
							Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(newValue);
									
							if( new UtenteDao().emailAlreadyUsed(newValue) )
								return "Email gia' in uso!";
							if( !matcher.find() )
								return "Email non valida!";
							new UtenteDao().updateUser(column, newValue, utente);
							utente.setEmail(newValue);
							return "Email aggiornata!";

			}
		}
		catch(SQLException e){
			e.printStackTrace();
		}
		return null;
	}
	
	//This is an example of overload.
	
	/**
	*Method to update user's password
	*
	*@param column password column
	*@param nuova_password <PASSWORD>
	*@param conferma_password password check
	*@param utente user that receives the update
	*@return String message to be displayed
	*/
	public String updateValue(String column, String nuova_password, String conferma_password, Utente utente){
		if( nuova_password.length() < 8 )
			return "La password deve essere di minimo 8 caratteri!";
		if( !nuova_password.equals(conferma_password) )
			return "Le due password non coincidono!";
		try{
			new UtenteDao().updateUser(column, nuova_password, utente);
			utente.setPassword(<PASSWORD>);
			return "Password aggiornata!";
		}
		catch(SQLException e){
			e.printStackTrace();
		}
		return null;
	}
}
<commit_msg>Update GestioneUtenza.java<commit_after>package src.controller;

import java.sql.SQLException;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

import src.model.dao.concrete.*;
import src.model.*;

/**
*Class which implements methods about user's mainteinance
*/
public class GestioneUtenza{
	
	/**
	*Method used to login into the platform
	*
	*@param username user's username
	*@param password user's password
	*@return Utente istance of user
	*/
	public Utente logIn(String username, String password){
		try{
			if( new UtenteDao().findUserByUsername(username) == null )
				return null;
			
			Utente utente = new UtenteDao().findUserByUsername(username);
			
			//Mysql is case insensitive
			if ( !utente.getUsername().equals(username) )
				return null;
			if( password.equals(utente.getPassword()) )
				return utente;
			return null;
		}
		catch(SQLException exc){
			exc.printStackTrace();
		}
		return null;
	} 
	
	/**
	*Method used to find a user by his username
	*
	*@param username user's username
	*@return Utente istance of user
	*/
	public Utente findUser(String username){
		try{
			return new UtenteDao().findUserByUsername(username);
		}
		catch(SQLException exc){
			exc.printStackTrace();
		}
		return null;
	} 
	
	
	/**
	*Method used to sign up into the platform
	*
	*@param name user's name
	*@param surname user's surname
	*@param username user's username
	*@param mail user's email
	*@param password <PASSWORD>
	*@param password2 <PASSWORD>
	*@return int information number about enrolment status
	*/
	public int signUp(String name, String surname, String username, String mail, String password, String password2){
		
		Pattern VALID_EMAIL_ADDRESS_REGEX = Pattern.compile("^[\\w!#$%&â€™*+/=?`{|}~^-]+(?:\\.[\\w!#$%&â€™*+/=?`{|}~^-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
		
		Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(mail);
		
		try{
			if( name.equals("") || surname.equals("") || username.equals("") || mail.equals("") || password.equals("") || password2.equals("") )
				return 1;
			if( new UtenteDao().usernameAlreadyUsed(username) )
				return 2;
			if( new UtenteDao().emailAlreadyUsed(mail) )
				return 3;
			if( !matcher.find() ) 
				return 4;
			if( password2.length() < 8 )
				return 5;
			if( !password.equals(password2) )
				return 6;
			Utente ut = new Utente(name,surname,username,mail,password);
		
			new UtenteDao().insertUser(ut);
			return 0;
		}
		catch(SQLException exc){
			exc.printStackTrace();
		}
		return -1;
	}
	
	/**
	*Method to update user's informations
	*
	*@param column value to be changed
	*@param newValue new value for the column
	*@param utente user that receives the update
	*@return String message to be displayed
	*/
	public String updateValue(String column, String newValue, Utente utente){
		
		try{
			switch( column ){
				
				case "nome":		new UtenteDao().updateUser(column, newValue, utente);
							utente.setNome(newValue);
							return "Nome aggiornato!";
								
				case "cognome":		new UtenteDao().updateUser(column, newValue, utente);
							utente.setCognome(newValue);
							return "Cognome aggiornato!";
								
				case "username":	if(new UtenteDao().usernameAlreadyUsed(newValue))
								return "Username gia' in uso!";
							new UtenteDao().updateUser(column, newValue, utente);
							utente.setUsername(newValue);
							return "Username aggiornato!";
									
				case "email":		Pattern VALID_EMAIL_ADDRESS_REGEX = Pattern.compile("^[\\w!#$%&â€™*+/=?`{|}~^-]+(?:\\.[\\w!#$%&â€™*+/=?`{|}~^-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
							Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(newValue);
									
							if( new UtenteDao().emailAlreadyUsed(newValue) )
								return "Email gia' in uso!";
							if( !matcher.find() )
								return "Email non valida!";
							new UtenteDao().updateUser(column, newValue, utente);
							utente.setEmail(newValue);
							return "Email aggiornata!";

			}
		}
		catch(SQLException e){
			e.printStackTrace();
		}
		return null;
	}
	
	//This is an example of overload.
	
	/**
	*Method to update user's password
	*
	*@param column password column
	*@param nuova_password <PASSWORD>
	*@param conferma_password password check
	*@param utente user that receives the update
	*@return String message to be displayed
	*/
	public String updateValue(String column, String nuova_password, String conferma_password, Utente utente){
		if( nuova_password.length() < 8 )
			return "La password deve essere di minimo 8 caratteri!";
		if( !nuova_password.equals(conferma_password) )
			return "Le due password non coincidono!";
		try{
			new UtenteDao().updateUser(column, nuova_password, utente);
			utente.setPassword(<PASSWORD>);
			return "Password aggiornata!";
		}
		catch(SQLException e){
			e.printStackTrace();
		}
		return null;
	}
}

{'fraction_non_alphanumeric': 0.1447544527952229, 'fraction_numerical': 0.004941830536394523, 'mean_word_length': 3.6634661545847336, 'pattern_counts': {'":': 8, '<': 16, '<?xml version=': 0, '>': 12, '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': '228751', 'n_tokens_mistral': 3908, 'n_tokens_neox': 3249, 'n_words': 814}