<commit_before><?php
namespace App\Controller;

use Cake\Network\Exception\UnauthorizedException;
use Cake\Utility\Security;
use Firebase\JWT\JWT;

class AuthController
	extends AppController
{

	public function initialize()
	{
		parent::initialize();

		$this->Auth->allow(['login', 'logout']);
	}

	public function login()
	{
		$user = $this->Auth->identify();
		if (!$user) {
			$this->request->data('id', (string)$this->request->data('id'));
			if($this->request->is('put') || $this->request->is('post'))
				$user = $this->Auth->identify();
		}
		if (!$user)
			throw new UnauthorizedException('Invalid username or password');

		$this->set(
			[ '_serialize' =>
				[ 'class' => 'Auth'
				, 'token' => JWT::encode(
					[ 'sub' => $user['id']
					, 'exp' =>  time() + 60*60*24*7
					], Security::salt())
				, 'player' => '/players/'.$user['id']
				, 'name' => $user['full_name']
				, 'role' => $user['role']
				]
			]);
	}

	public function logout()
	{
		return $this->redirect($this->Auth->logout());
	}

}<commit_msg>add extra player info to token payload<commit_after><?php
namespace App\Controller;

use Cake\Network\Exception\UnauthorizedException;
use Cake\Utility\Security;
use Firebase\JWT\JWT;

class AuthController
	extends AppController
{

	public function initialize()
	{
		parent::initialize();

		$this->Auth->allow(['login', 'logout']);
	}

	public function login()
	{
		$user = $this->Auth->identify();
		if (!$user) {
			$this->request->data('id', (string)$this->request->data('id'));
			if($this->request->is('put') || $this->request->is('post'))
				$user = $this->Auth->identify();
		}
		if (!$user)
			throw new UnauthorizedException('Invalid username or password');

		$this->set(
			[ '_serialize' =>
				[ 'class' => 'Auth'
				, 'token' => JWT::encode(
					[ 'sub' => $user['id']
					, 'exp' =>  time() + 60*60*24*7
					, 'name' => $user['full_name']
					, 'role' => $user['role']
					], Security::salt())
				, 'player' => '/players/'.$user['id']
				]
			]);
	}

	public function logout()
	{
		return $this->redirect($this->Auth->logout());
	}

}
{'fraction_non_alphanumeric': 0.22381635581061693, 'fraction_numerical': 0.006695361071257772, 'mean_word_length': 3.7223476297968396, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 55, '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': '6939534', 'n_tokens_mistral': 847, 'n_tokens_neox': 727, 'n_words': 132}