<commit_before><?php
/**
 * Documentation, License etc.
 *
 * @package Webserver
 */
include_once('User.php');
include_once('Log.php');
include_once('LocationsService.php');
include_once('LoginService.php');

$index = new Index();
$index->getIndex();


class Index {const LOGIN_REQUEST = "login";
	const UPDATE_REQUEST = "update";
	const ADD_REQUEST = "addNew";
	const DELETE_REQUEST = "delete";
	const REGISTER_REQUEST = "register";
	const CHANGE_PASSWORD_REQUEST = "changePassword";
	const RECOVER_PASSWORD_REQUEST = "recoverPassword";
	const REQUEST_TYPE = "q";
	const NAME = "name";
	const SURNAME = "surname";
	const PASSWORD = "password";
	const CONFIRM_PASS = "<PASSWORD>";
	const OLD_PASSWORD = "<PASSWORD>";
	const EMAIL = "email";
	const ROLES = "roles";
	const TOKEN = "token";

	const COOKIE_NAME = "accessToken";

	public function getIndex(){
		//Special case
		if(isset($_GET[self::REQUEST_TYPE]) && $_GET[self::REQUEST_TYPE] == self::RECOVER_PASSWORD_REQUEST){
			$this->handlePasswordRecoveryRequest();
		} else {
			$user = $this->getUserDetails();
				
			if($user && isset($_GET[self::REQUEST_TYPE])){
				Log::write($user, $_GET[self::REQUEST_TYPE]);
				$requestType = explode("/", $_GET[self::REQUEST_TYPE]);
				switch($requestType[0]){
					case self::LOGIN_REQUEST:
						$this->handleLoginRequest($user);
						break;
					case self::ADD_REQUEST:
						$this->handleAddRequest($user);
						break;
					case self::DELETE_REQUEST:
						$this->handleDeleteRequest($user, $requestType[1]);
						break;
					case self::UPDATE_REQUEST:
						$this->handleUpdateRequest($user, $requestType[1]);
						break;
					case self::REGISTER_REQUEST:
						$this->handleRegisterRequest($user);
						break;
					case self::CHANGE_PASSWORD_REQUEST:
						$this->handlePasswordChangeRequest($user);
						break;
					default:
						$this->showLoginForm();
						break;
				}
			} else if ($user) {
				Log::write($user, "map");
				$this->showMap($user);
			} else {
				if(isset($_POST[self::EMAIL])) {
					Log::failWrite(null, "login for " . $_POST[self::EMAIL]);
					$this->showLoginForm("Correu o contrasenya incorrecta");
				} else {
					Log::write(null, "view login");
					$this->showLoginForm();
				}
				
			}
		}
	}

	function handleLoginRequest(User $user = null){
		setcookie(self::COOKIE_NAME, $user->accessToken->accessTokenString);
		if($user) {
			if ($user->role == UsersContract::ROLE_TECHNICIAN){
				$this->showRegister();
			} else {
				$this->showMap($user);
			}
		} else {
			$this->showLoginForm();
		}
	}

	function handleAddRequest($user){
		if($user && $user->role == UsersContract::ROLE_ADMIN){<commit_msg>All users see only the map<commit_after><?php
/**
 * Documentation, License etc.
 *
 * @package Webserver
 */
include_once('User.php');
include_once('Log.php');
include_once('LocationsService.php');
include_once('LoginService.php');

$index = new Index();
$index->getIndex();


class Index {const LOGIN_REQUEST = "login";
	const UPDATE_REQUEST = "update";
	const ADD_REQUEST = "addNew";
	const DELETE_REQUEST = "delete";
	const REGISTER_REQUEST = "register";
	const CHANGE_PASSWORD_REQUEST = "changePassword";
	const RECOVER_PASSWORD_REQUEST = "recoverPassword";
	const REQUEST_TYPE = "q";
	const NAME = "name";
	const SURNAME = "surname";
	const PASSWORD = "password";
	const CONFIRM_PASS = "<PASSWORD>";
	const OLD_PASSWORD = "<PASSWORD>";
	const EMAIL = "email";
	const ROLES = "roles";
	const TOKEN = "token";

	const COOKIE_NAME = "accessToken";

	public function getIndex(){
		//Special case
		if(isset($_GET[self::REQUEST_TYPE]) && $_GET[self::REQUEST_TYPE] == self::RECOVER_PASSWORD_REQUEST){
			$this->handlePasswordRecoveryRequest();
		} else {
			$user = $this->getUserDetails();
				
			if($user && isset($_GET[self::REQUEST_TYPE])){
				Log::write($user, $_GET[self::REQUEST_TYPE]);
				$requestType = explode("/", $_GET[self::REQUEST_TYPE]);
				switch($requestType[0]){
					case self::LOGIN_REQUEST:
						$this->handleLoginRequest($user);
						break;
					case self::ADD_REQUEST:
						$this->handleAddRequest($user);
						break;
					case self::DELETE_REQUEST:
						$this->handleDeleteRequest($user, $requestType[1]);
						break;
					case self::UPDATE_REQUEST:
						$this->handleUpdateRequest($user, $requestType[1]);
						break;
					case self::REGISTER_REQUEST:
						$this->handleRegisterRequest($user);
						break;
					case self::CHANGE_PASSWORD_REQUEST:
						$this->handlePasswordChangeRequest($user);
						break;
					default:
						$this->showLoginForm();
						break;
				}
			} else if ($user) {
				Log::write($user, "map");
				$this->showMap($user);
			} else {
				if(isset($_POST[self::EMAIL])) {
					Log::failWrite(null, "login for " . $_POST[self::EMAIL]);
					$this->showLoginForm("Correu o contrasenya incorrecta");
				} else {
					Log::write(null, "view login");
					$this->showLoginForm();
				}
				
			}
		}
	}

	function handleLoginRequest(User $user = null){
		setcookie(self::COOKIE_NAME, $user->accessToken->accessTokenString);
		if($user) {
			$this->showMap($user);
		} else {
			$this->showLoginForm();
		}
	}

	function handleAddRequest($user){
		if($user && $user->role == UsersContract::ROLE_ADMIN){
{'fraction_non_alphanumeric': 0.16580410197431475, 'fraction_numerical': 0.0011500862564692352, 'mean_word_length': 4.151036525172755, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 45, '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': '848699', 'n_tokens_mistral': 2089, 'n_tokens_neox': 1711, 'n_words': 313}