<commit_before><?php namespace Palmabit\Authentication\Classes;
/**
 * Class SentryAuthenticator
 *
 * Autenticatore che utilizza sentry
 *
 * @package Auth
 * @author <NAME> <EMAIL>
 */
use Illuminate\Support\Facades\App;
use Illuminate\Support\MessageBag;
use Palmabit\Authentication\Exceptions\UserNotFoundException;
use Palmabit\Authentication\Interfaces\AuthenticateInterface;
use Palmabit\Authentication\Models\User;

class SentryAuthenticator implements AuthenticateInterface{

    protected $errors;

    protected $sentry;

    public function __construct()
    {
        $this->sentry = \App::make('sentry');
        $this->errors = new MessageBag();
    }

    /**
     * {@inheritdoc}
     */
    public function authenticate($credentials, $remember = false)
    {
        try
        {
            $user = $this->sentry->authenticate($credentials, $remember);
        }
        catch (\Cartalyst\Sentry\Users\LoginRequiredException $e)
        {
            $this->errors->add('login','Il campo login è richiesto.');
        }
        catch (\Cartalyst\Sentry\Users\UserNotFoundException $e)
        {
            $this->errors->add('login','Login fallito.');
        }
        catch (\Cartalyst\Sentry\Users\UserNotActivatedException $e)
        {
            $this->errors->add('login','Utente non è stato attivato.');
        }
        catch(\Cartalyst\Sentry\Users\PasswordRequiredException $e)
        {
            $this->errors->add('login','Il campo password è richiesto.');
        }

        return $this->errors->isEmpty() ? $user : false;
    }

    /**
     * {@inheritdoc}
     */
    public function getErrors()
    {
        return $this->errors;
    }

    /**
     * {@inheritdoc}
     */
    public function loginById($id, $remember = false)
    {
        $user = $this->sentry->findUserById($id);

        try
        {
            $this->sentry->login($user, false);
        }
        catch (\Cartalyst\Sentry\Users\LoginRequiredException $e)
        {
            $this->errors->add('login','Login richiesto.');
        }
        catch (\Cartalyst\Sentry\Users\UserNotActivatedException $e)
        {
            $this->errors->add('login','Utente non attivo.');
        }
        catch (\Cartalyst\Sentry\Users\UserNotFoundException $e)
        {
            $this->errors->add('login','Utente non trovato.');
        }

        return $this->errors->isEmpty() ? true : false;
    }

    /**
     * {@inheritdoc}
     */
    public function logout()
    {
        $this->sentry->logout();
    }

    /**
     * {@inheritdoc}
     */
    public function getUser($email)
    {
        try
        {
            $user = $this->sentry->findUserByLogin($email);
        }
        catch(\Cartalyst\Sentry\Users\UserNotFoundException $e)
        {
            throw new UserNotFoundException($e->getMessage());
        }
        return $user;
    }

    /**
     * {@inheritdoc}
     * @throws \Palmabit\Authentication\Exceptions\UserNotFoundException
     */
    public function getToken($email)
    {
        $user = $this->getUser($email);

        return $user->getResetPasswordCode();
    }

    /**
     * {@inheritdoc}
     */
    public function check()
    {
        return $this->sentry->check();
    }

    /**
     * Obtain the current user groups
     *
     * @param $name
     * @return array
     */
    public function getGroups()
    {
        $user = $this->getLoggedUser();
        return $user ? $user->getGroups() : [];
    }

    /**
     * Check if the current user has the given group
     *
     * @param $name
     * @return mixed
     */
    public function hasGroup($name)
    {
        $group = App::make('group_repository')->findByName($name);
        $user = $this->getLoggedUser();

        if(! $user ) return false;
        return $user->inGroup($group);
    }

    public function getLoggedUser()
    {
        return $this->sentry->getUser();
    }

    public function findById($id)
    {
        return User::find($id);
    }
}<commit_msg>add metodo getloggeduserprofile<commit_after><?php namespace Palmabit\Authentication\Classes;
/**
 * Class SentryAuthenticator
 *
 * Autenticatore che utilizza sentry
 *
 * @package Auth
 * @author <NAME> <EMAIL>
 */
use Illuminate\Support\Facades\App;
use Illuminate\Support\MessageBag;
use Palmabit\Authentication\Exceptions\UserNotFoundException;
use Palmabit\Authentication\Interfaces\AuthenticateInterface;
use Palmabit\Authentication\Models\User;

class SentryAuthenticator implements AuthenticateInterface{

    protected $errors;

    protected $sentry;

    public function __construct()
    {
        $this->sentry = \App::make('sentry');
        $this->errors = new MessageBag();
    }

    /**
     * {@inheritdoc}
     */
    public function authenticate($credentials, $remember = false)
    {
        try
        {
            $user = $this->sentry->authenticate($credentials, $remember);
        }
        catch (\Cartalyst\Sentry\Users\LoginRequiredException $e)
        {
            $this->errors->add('login','Il campo login è richiesto.');
        }
        catch (\Cartalyst\Sentry\Users\UserNotFoundException $e)
        {
            $this->errors->add('login','Login fallito.');
        }
        catch (\Cartalyst\Sentry\Users\UserNotActivatedException $e)
        {
            $this->errors->add('login','Utente non è stato attivato.');
        }
        catch(\Cartalyst\Sentry\Users\PasswordRequiredException $e)
        {
            $this->errors->add('login','Il campo password è richiesto.');
        }

        return $this->errors->isEmpty() ? $user : false;
    }

    /**
     * {@inheritdoc}
     */
    public function getErrors()
    {
        return $this->errors;
    }

    /**
     * {@inheritdoc}
     */
    public function loginById($id, $remember = false)
    {
        $user = $this->sentry->findUserById($id);

        try
        {
            $this->sentry->login($user, false);
        }
        catch (\Cartalyst\Sentry\Users\LoginRequiredException $e)
        {
            $this->errors->add('login','Login richiesto.');
        }
        catch (\Cartalyst\Sentry\Users\UserNotActivatedException $e)
        {
            $this->errors->add('login','Utente non attivo.');
        }
        catch (\Cartalyst\Sentry\Users\UserNotFoundException $e)
        {
            $this->errors->add('login','Utente non trovato.');
        }

        return $this->errors->isEmpty() ? true : false;
    }

    /**
     * {@inheritdoc}
     */
    public function logout()
    {
        $this->sentry->logout();
    }

    /**
     * {@inheritdoc}
     */
    public function getUser($email)
    {
        try
        {
            $user = $this->sentry->findUserByLogin($email);
        }
        catch(\Cartalyst\Sentry\Users\UserNotFoundException $e)
        {
            throw new UserNotFoundException($e->getMessage());
        }
        return $user;
    }

    /**
     * {@inheritdoc}
     * @throws \Palmabit\Authentication\Exceptions\UserNotFoundException
     */
    public function getToken($email)
    {
        $user = $this->getUser($email);

        return $user->getResetPasswordCode();
    }

    /**
     * {@inheritdoc}
     */
    public function check()
    {
        return $this->sentry->check();
    }

    /**
     * Obtain the current user groups
     *
     * @param $name
     * @return array
     */
    public function getGroups()
    {
        $user = $this->getLoggedUser();
        return $user ? $user->getGroups() : [];
    }

    /**
     * Check if the current user has the given group
     *
     * @param $name
     * @return mixed
     */
    public function hasGroup($name)
    {
        $group = App::make('group_repository')->findByName($name);
        $user = $this->getLoggedUser();

        if(! $user ) return false;
        return $user->inGroup($group);
    }

    public function getLoggedUser()
    {
        return $this->sentry->getUser();
    }

    public function getLoggedUserProfile()
    {
        $user = $this->getLoggedUser();
        return $user->user_profile;
    }

    public function findById($id)
    {
        return User::find($id);
    }
}
{'fraction_non_alphanumeric': 0.14306712395884372, 'fraction_numerical': 0.0, 'mean_word_length': 2.0285608308605343, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 95, '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': '934995', 'n_tokens_mistral': 2420, 'n_tokens_neox': 2393, 'n_words': 425}