<commit_before><?php namespace Bkwld\Decoy\Auth;

/**
 * This class abstracts the Sentry methods that are used globally
 * in Decoy, like for checking if a user is logged in and an admin.
 * It also allows developers to use a different authentication system
 * by setting their own Auth handler class in the Decoy config
 */
class Sentry implements AuthInterface {
	
	// ---------------------------------------------------------------
	// Methods for inspecting properties of the user
	// ---------------------------------------------------------------
	
	// Boolean for whether the user is logged in and an admin
	static public function check() {
		return false;
		// return \Sentry::check() && \Sentry::user()->in_group('admins');
	}
	
	// The logged in user's permissions role
	static public function role() {
		return \Sentry::user()->groups();
	}

	// Boolean as to whether the user has developer entitlements
	static public function developer() {
		return strpos(\Sentry::user()->get('email'), '@bkwld.com') !== false;
	}
	
	// ---------------------------------------------------------------
	// Urls related to the login process
	// ---------------------------------------------------------------
	
	// Controller action that renders the login form
	static public function login_action() {
		return 'Bkwld\Decoy\Controllers\Account@getLogin';
	}
	
	// URL to go to that will process their logout
	static public function logout_url() {
		return action('admin.account@logout');
	}
	
	// The URL to if they don't have access
	static public function denied_url() {
		return action('decoy::account@login');
	}
	
	// ---------------------------------------------------------------
	// These return properites of the logged in user
	// ---------------------------------------------------------------
	
	// Get their photo
	static public function user_photo() {
		return \Laravel\HTML::gravatar(\Sentry::user()->get('email'));
	}
	
	// Get their name
	static public function user_name() {
		return \Sentry::user()->get('metadata.first_name');
	}
	
	// Get the URL to their profile
	static public function user_url() {
		return action('decoy::admins', array(self::user_id()));
	}
	
	// Get their id
	static public function user_id() {
		return \Sentry::user()->get('id');
	}<commit_msg>Updating Auth/Sentry #66<commit_after><?php namespace Bkwld\Decoy\Auth;

// Dependencies
use \Html;

/**
 * This class abstracts the Sentry methods that are used globally
 * in Decoy, like for checking if a user is logged in and an admin.
 * It also allows developers to use a different authentication system
 * by setting their own Auth handler class in the Decoy config
 */
class Sentry implements AuthInterface {
	
	// Get the logged in user
	static public function user() {
		if (!\Sentry::check()) return false; // Are they logged in
		try {
			return \Sentry::getUser(); // Return the user
		} catch (\Cartalyst\Sentry\Users\UserNotFoundException $e) {
			return false; // The logged in user couldn't be found in DB
		}
	}
	
	// ---------------------------------------------------------------
	// Methods for inspecting properties of the user
	// ---------------------------------------------------------------
	
	// Boolean for whether the user is logged in and an admin
	static public function check() {
		
		// Get the logged in user
		if (!($user = self::user())) return false;
		
		// Make sure they have admin privledges.  This may be granted even if
		// they aren't in the "admins" group, though it is the most common way
		return $user->hasAccess('admin');
	}
	
	// The logged in user's permissions role
	static public function role() {
		if (!($user = self::user())) return null;
		return $user->getGroups();
	}

	// Boolean as to whether the user has developer entitlements
	static public function developer() {
		if (!($user = self::user())) return false; // They must be logged in
		if ($user->hasAccess('developer')) return true; // They must be a developer
		return strpos($user->email, '@<EMAIL>') !== false; // ... or have bkwld in their email
	}
	
	// ---------------------------------------------------------------
	// Urls related to the login process
	// ---------------------------------------------------------------
	
	// Controller action that renders the login form
	static public function login_action() {
		return 'Bkwld\Decoy\Controllers\Account@getLogin';
	}
	
	// URL to go to that will process their logout
	static public function logout_url() {
		return action('Bkwld\Decoy\Controllers\Account@getLogout');
	}
	
	// The URL to if they don't have access
	static public function denied_url() {
		return action(self::login_action());
	}
	
	// ---------------------------------------------------------------
	// These return properites of the logged in user
	// ---------------------------------------------------------------
	
	// Get their photo
	static public function user_photo() {
		if (!($user = self::user())) return null;
		return Html::gravatar($user->email);
	}
	
	// Get their name
	static public function user_name() {
		if (!($user = self::user())) return null;
		return $user->first_name;
	}
	
	// Get the URL to their profile
	static public function user_url() {
		return action('Bkwld\Decoy\Controllers\Admins@getShow', self::user_id());
	}
	
	// Get their id
	static public function user_id() {
		if (!($user = self::user())) return null;
		return $user->id;
	}
{'fraction_non_alphanumeric': 0.244349759170063, 'fraction_numerical': 0.0003705075954057058, 'mean_word_length': 1.9961154273029966, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 17, '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': '6696050', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1358, 'n_words': 527}