<commit_before><?php

class Auth {
	public $session;

	public function __construct() {
		$this->session = new \SlimSession\Helper;
	}

	public function login( $user ) {
		$this->session->set('authenticated', [
			'name' => $user->title,
			'email' => $user->email,
			'id' => $user->id
		]);
	}

	public function logout() {
		$this->session->delete('authenticated');
	}

	/**
	 * Check if logged in user has right properties
	 *
	 * @var string[] $allowed String with single id or array with allowed user id's
	 *
	 * @return boolean Returns true if logged in user id is in $allowed, false otherwise
	 */
	public function check( $allowed ) {
		if ( isset( $this->session->authenticated ) ) {
			if (
				( is_array( $allowed ) && !in_array( $app->session->authenticated['id'], $allowed ) )
				||
				$this->session->authenticated['id'] != $allowed

			) {
				throw new \Exception('You are not allowed to perform this action.');
			}
		} else {
			throw new \Exception('You need to log in to perform this action.');
		}
	}

}

?><commit_msg>Check returns logged in user array.<commit_after><?php

class Auth {
	public $session;

	public function __construct() {
		$this->session = new \SlimSession\Helper;
	}

	public function login( $user ) {
		$this->session->set('authenticated', [
			'name' => $user->title,
			'email' => $user->email,
			'id' => $user->id
		]);
	}

	public function logout() {
		$this->session->delete('authenticated');
	}

	/**
	 * Check if logged in user has right properties. Throws an exception if not.
	 *
	 * @var string[] $allowed String with single id or array with allowed user id's
	 *
	 * @return string[] Array with logged in user name, email and id.
	 */
	public function check( $allowed ) {
		if ( isset( $this->session->authenticated ) ) {
			if (
				( is_array( $allowed ) && in_array( $app->session->authenticated['id'], $allowed ) )
				||
				$this->session->authenticated['id'] == $allowed

			) {
				return $this->session->authenticated;
			} else {
				throw new \Exception('You are not allowed to perform this action.');
			}
		} else {
			throw new \Exception('You need to log in to perform this action.');
		}
	}

}

?>
{'fraction_non_alphanumeric': 0.1585984324573536, 'fraction_numerical': 0.0, 'mean_word_length': 3.2217898832684826, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '726971', 'n_tokens_mistral': 777, 'n_tokens_neox': 678, 'n_words': 206}