<commit_before><?php
namespace NyroDev\UtilityBundle\Services;

use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken,
	Symfony\Component\Security\Core\AuthenticationEvents,
	Symfony\Component\Security\Core\Event\AuthenticationEvent;

class MemberService extends AbstractService {

	
	/**
	 * Get the logged user. Will retrun anon. If user not logged
	 *
	 * @return string|Entity
	 */
	public function getUser() {
		return $this->get('security.context')->getToken()->getUser();
	}
	
	/**
	 * Indicates if the user is logged or not
	 *
	 * @return boolean
	 */
	public function isLogged() {
		return $this->get('security.context')->getToken() && $this->get('security.context')->getToken()->isAuthenticated() && is_object($this->getUser());
	}
	
	/**
	 * Indicates if the logged user is impersonated
	 *
	 * @return boolean
	 */
	public function isImpersonated() {
		return $this->isLogged() && $this->get('security.context')->isGranted('ROLE_PREVIOUS_ADMIN');
	}
	
	public function logUser(\Symfony\Component\Security\Core\User\UserInterface $user) {
		// Here, "main" is the name of the firewall in your security.yml
		$token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
		$this->get('security.context')->setToken($token);

		// Fire the login event
		$this->get('event_dispatcher')->dispatch(AuthenticationEvents::AUTHENTICATION_SUCCESS, new AuthenticationEvent($token));
	}

}<commit_msg>Add isGranted function for nyrodev_member service<commit_after><?php
namespace NyroDev\UtilityBundle\Services;

use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken,
	Symfony\Component\Security\Core\AuthenticationEvents,
	Symfony\Component\Security\Core\Event\AuthenticationEvent;

class MemberService extends AbstractService {

	
	/**
	 * Get the logged user. Will retrun anon. If user not logged
	 *
	 * @return string|Entity
	 */
	public function getUser() {
		return $this->get('security.context')->getToken()->getUser();
	}
	
	/**
	 * Indicates if the user is logged or not
	 *
	 * @return boolean
	 */
	public function isLogged() {
		return $this->get('security.context')->getToken() && $this->get('security.context')->getToken()->isAuthenticated() && is_object($this->getUser());
	}
	
	/**
	 * Check if the user is logged and granted with the given role
	 *
	 * @param string $role Role name
	 * @return boolean
	 */
	public function isGranted($role) {
		return $this->isLogged() && $this->get('security.context')->isGranted($role);
	}
	
	/**
	 * Indicates if the logged user is impersonated
	 *
	 * @return boolean
	 */
	public function isImpersonated() {
		return $this->isGranted('ROLE_PREVIOUS_ADMIN');
	}
	
	/**
	 * Log user correctly
	 *
	 * @param \Symfony\Component\Security\Core\User\UserInterface $user
	 */
	public function logUser(\Symfony\Component\Security\Core\User\UserInterface $user) {
		// Here, "main" is the name of the firewall in your security.yml
		$token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
		$this->get('security.context')->setToken($token);

		// Fire the login event
		$this->get('event_dispatcher')->dispatch(AuthenticationEvents::AUTHENTICATION_SUCCESS, new AuthenticationEvent($token));
	}

}
{'fraction_non_alphanumeric': 0.14617528646639827, 'fraction_numerical': 0.0, 'mean_word_length': 4.627177700348432, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 38, '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': '89168', 'n_tokens_mistral': 1018, 'n_tokens_neox': 939, 'n_words': 215}