<commit_before><?php
	/**
	 * GroupMeAuth.php
	 * Contains the Class for the GroupMeAuth Controller
	 *
	 * @author <NAME>
	 */

namespace GroupMeBot;

class GroupMeAuth extends \Thinker\Framework\Controller
{
	/**
	 * receiveToken()
	 * Receives an API token from GroupMe's OAuth Service
	 *
	 * @access public
	 */
	public function receiveToken()
	{
		// Get token from URL
		$token = \Thinker\Http\Request::get("access_token");

		if($token)
		{
			// Process token
			if($this->process_token($token))
			{
				// Redirect to sunshine portal
				\Thinker\Http\Redirect::go("Sunshines", "add");
			}
			else
			{
				// 403 User Not Found
				\Thinker\Http\Redirect::error(403);
			}
		}
		else
		{
			// Throw an error since we didn't get a proper request
			\Thinker\Http\Redirect::error(404);
		}

		return true;
	}

	/**
	 * redirect()
	 * Passes data back for the 'redirect' subsection
	 *
	 * @access public
	 */
	public function redirect()
	{
		global $_DB;

		// Get GroupMe API url
		$query = "SELECT value
				  FROM globals 
				  WHERE name = 'OAUTH_CALLBACK' 
				  LIMIT 1";

		$url = $_DB['botstore']->doQueryAns($query, $params);

		if($url)
		{
			// Push user to GroupMe website for authentication
			header('Location: ' . $url);
			die();
		}
		else
		{
			// No URL? That's bad.
			\Thinker\Http\Redirect::error(500);
		}
	}

	/**
	 * process_token()
	 * Processes an OAuth Token from GroupMe
	 *
	 * @access private
	 * @param token Token value
	 * @return True on Success, False on Failure
	 */
	private function process_token($token)
	{
		global $_DB;

		if($token)
		{
			// Log in as the user with this token
			$query = "SELECT user_id, name 
					  FROM users 
					  WHERE token = :token 
					  LIMIT 1";
			$params = array(':token' => $token);

			$user = $_DB['botstore']->doQueryAns($query, $params);

			if($user)<commit_msg>Fix token lookup query<commit_after><?php
	/**
	 * GroupMeAuth.php
	 * Contains the Class for the GroupMeAuth Controller
	 *
	 * @author <NAME>
	 */

namespace GroupMeBot;

class GroupMeAuth extends \Thinker\Framework\Controller
{
	/**
	 * receiveToken()
	 * Receives an API token from GroupMe's OAuth Service
	 *
	 * @access public
	 */
	public function receiveToken()
	{
		// Get token from URL
		$token = \Thinker\Http\Request::get("access_token");

		if($token)
		{
			// Process token
			if($this->process_token($token))
			{
				// Redirect to sunshine portal
				\Thinker\Http\Redirect::go("Sunshines", "add");
			}
			else
			{
				// 403 User Not Found
				\Thinker\Http\Redirect::error(403);
			}
		}
		else
		{
			// Throw an error since we didn't get a proper request
			\Thinker\Http\Redirect::error(404);
		}

		return true;
	}

	/**
	 * redirect()
	 * Passes data back for the 'redirect' subsection
	 *
	 * @access public
	 */
	public function redirect()
	{
		global $_DB;

		// Get GroupMe API url
		$query = "SELECT value
				  FROM globals 
				  WHERE name = 'OAUTH_CALLBACK' 
				  LIMIT 1";

		$url = $_DB['botstore']->doQueryAns($query, $params);

		if($url)
		{
			// Push user to GroupMe website for authentication
			header('Location: ' . $url);
			die();
		}
		else
		{
			// No URL? That's bad.
			\Thinker\Http\Redirect::error(500);
		}
	}

	/**
	 * process_token()
	 * Processes an OAuth Token from GroupMe
	 *
	 * @access private
	 * @param token Token value
	 * @return True on Success, False on Failure
	 */
	private function process_token($token)
	{
		global $_DB;

		if($token)
		{
			// Log in as the user with this token
			$query = "SELECT user_id, name 
					  FROM users 
					  WHERE access_token = :token 
					  LIMIT 1";
			$params = array(':token' => $token);

			$user = $_DB['botstore']->doQueryAns($query, $params);

			if($user)
{'fraction_non_alphanumeric': 0.13704496788008566, 'fraction_numerical': 0.007494646680942184, 'mean_word_length': 2.642300194931774, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '2885495', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1226, 'n_words': 338}