<commit_before><?php

class Token extends CI_Controller 
{

	function __construct ()
	{
		parent::__construct();

		// Autoloading
		require_once(APPPATH.'third_party/oauth2-server-php/src/OAuth2/Autoloader.php');
		OAuth2\Autoloader::register();

		$config = array(
            'client_table' 			=> 'EASOL.oauth_clients',
            'access_token_table' 	=> 'EASOL.oauth_access_tokens',
            'refresh_token_table' 	=> 'EASOL.oauth_refresh_tokens',
            'code_table' 			=> 'EASOL.oauth_authorization_codes',
            'user_table' 			=> 'EASOL.oauth_users',
            'jwt_table'  			=> 'EASOL.oauth_jwt',
            'jti_table'  			=> 'EASOL.oauth_jti',
            'scope_table'  			=> 'EASOL.oauth_scopes',
            'public_key_table'  	=> 'EASOL.oauth_public_keys',
        );

		// $dsn is the Data Source Name for your database, for exmaple "mysql:dbname=my_oauth2_db;host=localhost"
		$storage = new OAuth2\Storage\Pdo(array('dsn' => 'sqlsrv:Server=oqc2uoyejf.database.windows.net,1433;Database=easol_dev', 'username' => 'easol_dev_dba@oqc2uoyejf', 'password' => <PASSWORD>'), $config);

		// Pass a storage object or array of storage objects to the OAuth2 server class
		$this->server = new OAuth2\Server($storage);

		// Add the "Client Credentials" grant type (it is the simplest of the grant types)
		$this->server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage));	
	}

	function index ()
	{
		$email 		= $this->input->post('email');
		$password 	= $this->input->post('password');

		// client collects login credentials and posts them here along with the client details.

		if (!empty($email) and !empty($password)) {

			// Verify the user's username and password
	        if($this->_login(array('email' => $email, 'password' => $password))) {
				// Handle a request for an OAuth2.0 Access Token and send the response to the client
				return $this->server->handleTokenRequest(OAuth2\Request::createFromGlobals())->send();
	        }
	    }

		exit(json_encode(array( 'error' 				=> 'login invalid',
								'error_description'		=> 'The email and/or password is invalid.'
						))
		);

		// verification: if the client wants to verify that the code is not an arbitrary code as a forgery then they can simply
		// test the code for verification at the resource server Resource.php
		// This can also be used to check if the code has expired in case the client cares.
	}

    private function _login ($data = array())
    {
        $this->load->model('Usermanagement_M');
        $user = $this->Usermanagement_M->getEasolUsers($data['email'], "SEM.ElectronicMailAddress");
        if(is_array($user) and !empty($user)) {
            $this->load->model('entities/easol/Easol_StaffAuthentication');<commit_msg>Small testing<commit_after><?php

class Token extends CI_Controller 
{

	function __construct ()
	{
		parent::__construct();

		// Autoloading
		require_once(APPPATH.'third_party/oauth2-server-php/src/OAuth2/Autoloader.php');
		OAuth2\Autoloader::register();

		$config = array(
            'client_table' 			=> 'EASOL.oauth_clients',
            'access_token_table' 	=> 'EASOL.oauth_access_tokens',
            'refresh_token_table' 	=> 'EASOL.oauth_refresh_tokens',
            'code_table' 			=> 'EASOL.oauth_authorization_codes',
            'user_table' 			=> 'EASOL.oauth_users',
            'jwt_table'  			=> 'EASOL.oauth_jwt',
            'jti_table'  			=> 'EASOL.oauth_jti',
            'scope_table'  			=> 'EASOL.oauth_scopes',
            'public_key_table'  	=> 'EASOL.oauth_public_keys',
        );

		// $dsn is the Data Source Name for your database, for exmaple "mysql:dbname=my_oauth2_db;host=localhost"
		$storage = new OAuth2\Storage\Pdo(array('dsn' => 'sqlsrv:Server=oqc2uoyejf.database.windows.net,1433;Database=easol_dev', 'username' => 'easol_dev_dba@<EMAIL>jf', 'password' => <PASSWORD>'), $config);

		// Pass a storage object or array of storage objects to the OAuth2 server class
		$this->server = new OAuth2\Server($storage);

		// Add the "Client Credentials" grant type (it is the simplest of the grant types)
		$this->server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage));	
	}

	function index ()
	{
		$email 		= $this->input->post('email');
		$password 	= $this->input->post('password');

		// client collects login credentials and posts them here along with the client details.

		if (!empty($email) and !empty($password)) {
			echo $email."|".$password."|";
			// Verify the user's username and password
	        if($this->_login(array('email' => $email, 'password' => $password))) {
				// Handle a request for an OAuth2.0 Access Token and send the response to the client
				return $this->server->handleTokenRequest(OAuth2\Request::createFromGlobals())->send();
	        }
	    }

		exit(json_encode(array( 'error' 				=> 'login invalid',
								'error_description'		=> 'The email and/or password is invalid.'
						))
		);

		// verification: if the client wants to verify that the code is not an arbitrary code as a forgery then they can simply
		// test the code for verification at the resource server Resource.php
		// This can also be used to check if the code has expired in case the client cares.
	}

    private function _login ($data = array())
    {
        $this->load->model('Usermanagement_M');
        $user = $this->Usermanagement_M->getEasolUsers($data['email'], "SEM.ElectronicMailAddress");
        var_dump($user);
        if(is_array($user) and !empty($user)) {
            $this->load->model('entities/easol/Easol_StaffAuthentication');
{'fraction_non_alphanumeric': 0.13632286995515694, 'fraction_numerical': 0.005919282511210763, 'mean_word_length': 3.349453978159126, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 72, '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': '3002099', 'n_tokens_mistral': 1960, 'n_tokens_neox': 1805, 'n_words': 419}