@param User $user

@return Customer
182191
public function registerCustomerByUser($user)
    {

        /** @var ShopContextInterface $context */
        $context = $this->context->getShopContext();
        $shop = $context->getShop();

        $customer = new Customer();

        $customer->setAttribute([strtolower($user->getType()) . 'Identity' => $user->getId()]);

        $customer->setSalutation($user->getSalutation());
        $customer->setEmail($user->getEmail());
        $customer->setFirstname($user->getFirstName());
        $customer->setLastname($user->getLastName());
        // we generate the password here, because we have no password
        // due the SSO mechanism and we will not neet it in future
        // But SW needs it :-)
        $password = uniqid();
        $customer->setPassword($password);

        $billing = new Address();
        $billing->setCompany($user->getCompany());
        $billing->setSalutation($user->getSalutation());
        $billing->setFirstname($user->getFirstName());
        $billing->setLastname($user->getLastName());
        $billing->setCity($user->getCity());
        $billing->setStreet($user->getAddress());
        $billing->setZipcode($user->getZip());

        // try to find the best matching country for the user
        $country = $this->countryService->getBestMatchingCountryForUser($user);

        // try to find the matching country by the current locale of the shop
        if ($country === null) {
            $defaultCountry = Shopware()->Config()->getByNamespace('Port1HybridAuth', 'general_default_country');
            if ($defaultCountry) {
                $country = $this->countryService->getCountryById($defaultCountry);
            }
        }

        // take germany if no country could be found
        if ($country === null) {
            $country = $this->countryService->getCountryByCountryIso('de');
        }

        $billing->setCountry($country);

        try {
            $this->register($shop, $customer, $billing);
        } catch (Exception $ex) {
            return null;
        }

        return $customer;
    }
481374
public function getActivesByUser($user)
    {
        $table = $user->permissions()->getTable();

        return $user->permissions()
            ->where($table.'.value', true)
            ->where(function ($q) use ($table) {
                $q->where($table.'.expires', '>=', Carbon::now());
                $q->orWhereNull($table.'.expires');
            })
            ->get();
    }
334002
protected function CanEdit(User $user)
    {
        return self::Guard()->Allow(BackendAction::Edit(), $user)&&
            self::Guard()->Allow(BackendAction::UseIt(), new UserForm());
    }
995844
public function save(User $user)
    {
        if ($user->getId() != null) {
            return $this->update($user);
        }
        return $this->create($user);
    }
1152162
public function setUser(User $user)
    {
        $this->user = $user;

        unset($_SESSION[self::class][$this->getConfig()->getEntityID()]['user']);

        $_SESSION[self::class][$this->getConfig()->getEntityID()]['user'] = $this->user->toArray();
        $this->setRole($this->user->getCurrentRole());
        $this->setLocalUsername($this->user->getLocalUsername());

        return $this;
    }
878843
public static function user($user = null)
    {
        if ($user !== null) {
            self::$_user = $user;
        }
        if (!self::$_user) {
            return null;
        }
        return self::$_user;
    }
276118
public function getPublisher(User $user)
    {
        foreach ($this->getPublishers() as $publisher) {
            if ($publisher->getUser()->getId() == $user->getId()) {
                return $publisher;
            }
        }

        return null;
    }
928486
public function user($user)
    {
        $this->user = $user;

        $this->content = array_merge($this->content, [
            'user' => [
                'id' => $user->getAuthIdentifier(),
                'name' => $user->name ?? null,
                'email' => $user->email ?? null,
            ],
        ]);

        $this->tags(['Auth:'.$user->getAuthIdentifier()]);

        return $this;
    }
400354
private function fetch(User $user)
    {
        return self::$cache[$user->getId()] = new \ACL($user, $this->app);
    }
104960
public function setUser(\Mvc\BlogBundle\Entity\User $user)
    {
        $this->user = $user;

        return $this;
    }
169393
public function to(User $user)
    {
        $this->user = $user;
        $this->request['touser'] = $user['wechatOpenId'];

        return $this;
    }
772484
public function getCustomer(int $gatewayId, User $user): Customer
    {
        $result = $this->_createCustomerQuery()
            ->where(['userId' => $user->id, 'gatewayId' => $gatewayId])
            ->one();

        if ($result !== null) {
            return new Customer($result);
        }

        Stripe::setApiKey(Craft::parseEnv(Commerce::getInstance()->getGateways()->getGatewayById($gatewayId)->apiKey));
        Stripe::setAppInfo(StripePlugin::getInstance()->name, StripePlugin::getInstance()->version, StripePlugin::getInstance()->documentationUrl);
        Stripe::setApiVersion(Gateway::STRIPE_API_VERSION);

        /** @var StripeCustomer $stripeCustomer */
        $stripeCustomer = StripeCustomer::create([
            'description' => Craft::t('commerce-stripe', 'Customer for Craft user with ID {id}', ['id' => $user->id]),
            'email' => $user->email
        ]);

        $customer = new Customer([
            'userId' => $user->id,
            'gatewayId' => $gatewayId,
            'reference' => $stripeCustomer->id,
            'response' => $stripeCustomer->jsonSerialize()
        ]);

        if (!$this->saveCustomer($customer)) {
            throw new CustomerException('Could not save customer: ' . implode(', ', $customer->getErrorSummary(true)));
        }

        return $customer;
    }
914801
public function user($user = null)
    {
        if ($user !== null) {
            $this->user = $user;
        }

        return $this->user;
    }
188797
public function setUser(\Claroline\CoreBundle\Entity\User $user)
    {
        $this->user = $user;

        return $this;
    }
366256
public function user($user = 0)
    {
        if (! $this->user->has($user)) {
            $data = new Collection([]);

            $this->user->put($user, $data);
        }

        return $this->user->get($user);
    }
648151
public function user(string $user): Builder
    {
        $this->claims[Claims::USER] = $user;

        return $this;
    }
456597
public function setUser($user)
    {

        // Clear cache
        $this->user = null;

        // Find element
        if (!$user = $this->findUserElement($user)) {
            // Clear property / cache
            $this->userId = $this->user = null;
        } else {
            // Set property
            $this->userId = $user->getId();

            // Set cache
            $this->user = $user;
        }

        return $this;
    }