<commit_before><?php
namespace AppBundle\UserProvider;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Bridge\Monolog\Logger;

class DeputyProvider implements UserProviderInterface
{
    /**
     * @var ContainerInterface
     */
    private $container;
    
    /**
     * @var string
     */
    private $env;
    
     /**
     * @var Logger
     */
    private $logger;
    
    /**
     * @var array 
     */
    private static $envToEndpoint = [
        'admin' => 'user/get-admin-by-email',
        'develop' => 'user/get-user-by-email',
        'staging' => 'user/get-user-by-email',
        'ci' => 'user/get-user-by-email',
        'prod' => 'user/get-user-by-email'
    ];
    
    public function __construct(ContainerInterface $container, Logger $logger, $env)
    {
        $this->container = $container;
        $this->logger = $logger;
        $this->env = $env;
    }
    
    /**
     * Finds user by email
     * 
     * @param string $email
     * @return \AppBundle\Entity\User $user
     * @throws UsernameNotFoundException
     */
    public function loadUserByUsername($email) 
    {
        $apiclient = $this->container->get('apiclient');
        
        try {
            $endpoint = isset(self::$envToEndpoint[$this->env]) 
                        ? self::$envToEndpoint[$this->env] : 'user/get-by-email';
            
            return $apiclient->getEntity('User', "{$endpoint}/{$email}");
        } catch (\Exception $e) {
            $this->logger->info(__METHOD__ . ': ' . $apiclient->getLastErrorMessage());

            throw new UsernameNotFoundException("We can't log you in at this time.");
        }
        
    }
    
    /**
     * @param UserInterface $user
     * @return  \AppBundle\Entity\User<commit_msg>dd-1130 provider uses restclient to login<commit_after><?php
namespace AppBundle\UserProvider;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Bridge\Monolog\Logger;

class DeputyProvider implements UserProviderInterface
{
    /**
     * @var ContainerInterface
     */
    private $container;
    
    /**
     * @var string
     */
    private $env;
    
     /**
     * @var Logger
     */
    private $logger;
    
    /**
     * @var array 
     */
    private static $envToEndpoint = [
        'admin' => 'user/get-admin-by-email',
        'develop' => 'user/get-user-by-email',
        'staging' => 'user/get-user-by-email',
        'ci' => 'user/get-user-by-email',
        'prod' => 'user/get-user-by-email'
    ];
    
    public function __construct(ContainerInterface $container, Logger $logger, $env)
    {
        $this->container = $container;
        $this->logger = $logger;
        $this->env = $env;
    }
    
    /**
     * 
     * @param array $credentials
     * @return type
     */
    public function login(array $credentials) 
    {
        $restclient = $this->container->get('restClient');
        
        try {
           return $restclient->login($credentials['email'], $credentials['password']);
        } catch(\Exception $e) {
            $this->logger->info(__METHOD__ . ': ' . $e);
            
            throw new UsernameNotFoundException("We can't log you in at this time.");
        }
    }
    
    /**
     * Finds user by email
     * 
     * @param string $email
     * @return \AppBundle\Entity\User $user
     * @throws UsernameNotFoundException
     */
    public function loadUserByUsername($email) 
    {
        $apiclient = $this->container->get('apiclient');
        
        try {
            $endpoint = isset(self::$envToEndpoint[$this->env]) 
                        ? self::$envToEndpoint[$this->env] : 'user/get-by-email';
            
            return $apiclient->getEntity('User', "{$endpoint}/{$email}");
        } catch (\Exception $e) {
            $this->logger->info(__METHOD__ . ': ' . $apiclient->getLastErrorMessage());

            throw new UsernameNotFoundException("We can't log you in at this time.");
        }
        
    }
    
    /**
     * @param UserInterface $user
     * @return  \AppBundle\Entity\User
{'fraction_non_alphanumeric': 0.13939917873352065, 'fraction_numerical': 0.0008644910309055544, 'mean_word_length': 2.2161223071577485, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 40, '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': '2003250', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1350, 'n_words': 241}