src/Biz/User/UserProvider.php

(开头部分) 2KB

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

<?php

namespace Biz\User;

use Biz\User\Service\UserService;
use Biz\Role\Util\PermissionBuilder;
use Topxia\Service\Common\ServiceKernel;
use AppBundle\Handler\AuthenticationHelper;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;

class UserProvider implements UserProviderInterface
{
    private $container;

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

    public function loadUserByUsername($username)
    {
        $user = $this->getUserService()->getUserByLoginField($username);

        if (empty($user)) {
            throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
        } elseif (isset($user['type']) && 'system' == $user['type']) {
            throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
        }

        $request = $this->container->get('request');

        $forbidden = AuthenticationHelper::checkLoginForbidden($request);
        if ('error' == $forbidden['status']) {
            throw new AuthenticationException($forbidden['message']);
        }

        $user['currentIp'] = $request->getClientIp();
        $user['org'] = $this->loadOrg($request, $user);
        $currentUser = new CurrentUser();
        $currentUser->fromArray($user);
        $currentUser->setPermissions(PermissionBuilder::instance()->getPermissionsByRoles($currentUser->getRoles()));
        $currentUser['isSecure'] = $request->isSecure();
        $biz = $this->container->get('biz');
        $biz['user'] = $currentUser;
        ServiceKernel::instance()->setCurrentUser($currentUser);

        return $currentUser;
    }

    protected function loadOrg($request, $user)
    {
        $org = $request->getSession()->get('currentUserOrg', array());
        if (empty($org) || $org['orgCode'] != $user['orgCode']) {
            $org = $this->getOrgService()->getOrgByOrgCode($user['orgCode']);
            $request->getSession()->set('currentUserOrg', $org);

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

AI 解读 AI

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

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