<commit_before><?php defined('SYSPATH') or die('No direct script access.');

/**
 * REST API to manage account
 */
class Controller_Api_V1_Account extends Controller_Api_Rest
{

	public function action_get ()
	{
		// Get account id
		$id = $this->request->param('id');

		// Get the account service
		$account_service = Service::factory('Account');

		// Get api service
		$api_service = Service::factory('Api');

		try
		{
			// Get current logged in user account
			$user = $api_service->check_token($this->request);

			// If id is null, then try to use the one found into token
			if (is_null($id))
				$id = $user->id();

			// Get the account
			$account = $account_service->get(array('id' => $id));

			// Check if we could get the account
			$api_service->check_access($account, $user);

			// Return appropriate HTTP code
			$this->response($api_service->build_response_succeed(
				'Account found',
				$account->get_data()
			), 200);
		}
		catch (Service_Exception_AuthError $e)
		{
			$this->response($api_service->build_response_failed($e->getMEssage()), 401);
		}
		catch (Service_Exception_NotFound $e)
		{
			$this->response($api_service->build_response_failed($e->getMEssage()), 404);
		}
		catch (Service_Exception_PermissionDenied $e)
		{
			$this->response($api_service->build_response_failed($e->getMEssage()), 403);
		}
		catch (Exception $e)
		{
			Kohana_Exception::log($e, Log::ERROR);
			$this->response($api_service->build_response_failed($e->getMessage()), 400);
		}
	}

	public function action_update ()
	{
		// Get data from the body sent by backbone
		$body = $this->request->body();

		// Build request data
		$data = array();
		if (isset($body->email)) $data['email'] = $body->email;
		if (isset($body->firstname)) $data['firstname'] = $body->firstname;
		if (isset($body->lastname)) $data['lastname'] = $body->lastname;
		if (isset($body->password)) $data['password'] = $body->password;

		// Get the account service
		$account_service = Service::factory('Account');

		// Get the api service
		$api_service = Service::factory('Api');

		try
		{
			// Get current logged in user account<commit_msg>allow to update gravatar url<commit_after><?php defined('SYSPATH') or die('No direct script access.');

/**
 * REST API to manage account
 */
class Controller_Api_V1_Account extends Controller_Api_Rest
{

	public function action_get ()
	{
		// Get account id
		$id = $this->request->param('id');

		// Get the account service
		$account_service = Service::factory('Account');

		// Get api service
		$api_service = Service::factory('Api');

		try
		{
			// Get current logged in user account
			$user = $api_service->check_token($this->request);

			// If id is null, then try to use the one found into token
			if (is_null($id))
				$id = $user->id();

			// Get the account
			$account = $account_service->get(array('id' => $id));

			// Check if we could get the account
			$api_service->check_access($account, $user);

			// Return appropriate HTTP code
			$this->response($api_service->build_response_succeed(
				'Account found',
				$account->get_data()
			), 200);
		}
		catch (Service_Exception_AuthError $e)
		{
			$this->response($api_service->build_response_failed($e->getMEssage()), 401);
		}
		catch (Service_Exception_NotFound $e)
		{
			$this->response($api_service->build_response_failed($e->getMEssage()), 404);
		}
		catch (Service_Exception_PermissionDenied $e)
		{
			$this->response($api_service->build_response_failed($e->getMEssage()), 403);
		}
		catch (Exception $e)
		{
			Kohana_Exception::log($e, Log::ERROR);
			$this->response($api_service->build_response_failed($e->getMessage()), 400);
		}
	}

	public function action_update ()
	{
		// Get data from the body sent by backbone
		$body = $this->request->body();

		// Build request data
		$data = array();
		if (isset($body->email)) $data['email'] = $body->email;
		if (isset($body->firstname)) $data['firstname'] = $body->firstname;
		if (isset($body->gravatar_email)) $data['gravatar_email'] = $body->gravatar_email;
		if (isset($body->lastname)) $data['lastname'] = $body->lastname;
		if (isset($body->password)) $data['password'] = $<PASSWORD>;

		// Get the account service
		$account_service = Service::factory('Account');

		// Get the api service
		$api_service = Service::factory('Api');

		try
		{
			// Get current logged in user account
{'fraction_non_alphanumeric': 0.16666666666666666, 'fraction_numerical': 0.007336084364970197, 'mean_word_length': 4.079161816065192, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 71, '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': '5824', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1392, 'n_words': 327}