<commit_before><?php

/*
 * This file is part of the Vandpibe package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Vandpibe\AutoLogin\Security;

use Jmikola\AutoLogin\Exception\AutoLoginTokenNotFoundException;
use Jmikola\AutoLogin\User\AutoLoginUserProviderInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Vandpibe\AutoLogin\HasherInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
class UserProvider implements AutoLoginUserProviderInterface
{
    /**
     * @var UserProviderInterface
     */
    protected $provider;

    /**
     * @var HasherInterface
     */
    protected $hasher;

    /**
     * @param UserProviderInterface $provider
     */
    public function __construct(UserProviderInterface $provider, HasherInterface $hasher)
    {
        $this->provider = $provider;
        $this->hasher = $hasher;
    }

    /**
     * {@inheritdoc}
     */
    public function loadUserByAutoLoginToken($key)
    {
        $hash = null;
        $expireAt = null;
        $username = null;

        // Parse the query string
        parse_str(base64_decode($key));

        if (time() < $expireAt && $hash == $this->hasher->hash(compact('username', 'expireAt'))) {
            return $this->provider->loadUserByUsername($username);
        }

        throw new AutoLoginTokenNotFoundException('"$key" contains invalid information.');
    }
}
<commit_msg>Make UserProvider implement the normal UserProviderInterface aswell<commit_after><?php

/*
 * This file is part of the Vandpibe package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Vandpibe\AutoLogin\Security;

use Jmikola\AutoLogin\Exception\AutoLoginTokenNotFoundException;
use Jmikola\AutoLogin\User\AutoLoginUserProviderInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Vandpibe\AutoLogin\HasherInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
class UserProvider implements AutoLoginUserProviderInterface, UserProviderInterface
{
    /**
     * @var UserProviderInterface
     */
    protected $provider;

    /**
     * @var HasherInterface
     */
    protected $hasher;

    /**
     * @param UserProviderInterface $provider
     */
    public function __construct(UserProviderInterface $provider, HasherInterface $hasher)
    {
        $this->provider = $provider;
        $this->hasher = $hasher;
    }

    public function loadUserByUsername($username)
    {
        return $this->provider->loadUserByUsername($username);
    }

    public function refreshUser(UserInterface $user)
    {
        $this->provider->refreshUser($user);
    }

    public function supportsClass($class)
    {
        return $this->provider->supportsClass($class);
    }

    /**
     * {@inheritdoc}
     */
    public function loadUserByAutoLoginToken($key)
    {
        $hash = null;
        $expireAt = null;
        $username = null;

        // Parse the query string
        parse_str(base64_decode($key));

        if (time() < $expireAt && $hash == $this->hasher->hash(compact('username', 'expireAt'))) {
            return $this->loadUserByUsername($username);
        }

        throw new AutoLoginTokenNotFoundException('"$key" contains invalid information.');
    }
}

{'fraction_non_alphanumeric': 0.11763022323983972, 'fraction_numerical': 0.0011448196908986834, 'mean_word_length': 3.0925058548009368, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 32, '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': '3393835', 'n_tokens_mistral': 1001, 'n_tokens_neox': 985, 'n_words': 220}