src/AppBundle/Component/OAuthServer/Storage/UserCredentials.php

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php

namespace AppBundle\Component\OAuthServer\Storage;

use Biz\User\Service\UserService;
use Codeages\Biz\Framework\Context\Biz;
use OAuth2\Storage\UserCredentialsInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class UserCredentials implements UserCredentialsInterface
{
    /**
     * @var ContainerInterface
     */
    private $container;

    /**
     * @var Biz
     */
    private $biz;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
        $this->biz = $this->container->get('biz');
    }

    public function checkUserCredentials($username, $password)
    {
        // Load user by username
        try {
            $user = $this->getUserService()->getUserByLoginField($username);
        } catch (\Symfony\Component\Security\Core\Exception\UsernameNotFoundException $e) {
            return false;
        }

        return $this->getUserService()->verifyPassword($user['id'], $password);
    }

    public function getUserDetails($username)
    {
        // Load user by username
        try {
            $user = $this->getUserService()->getUserByLoginField($username);
        } catch (\Symfony\Component\Security\Core\Exception\UsernameNotFoundException $e) {
            return false;
        }

        return array(
            'user_id' => $user['id'],
            'scope' => 'default',
        );
    }

    /**
     * @return UserService
     */
    private function getUserService()
    {
        return $this->biz->service('User:UserService');

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。