Performs all needed tasks when customer is logging in during checkout
@param array $user
@param array $cart
@return array
542498
public function login(array $user, array $cart)
    {
        $result = array();
        $this->hook->attach('cart.login.before', $user, $cart, $result, $this);

        if (!empty($result)) {
            return (array) $result;
        }

        if (!$this->config->get('cart_login_merge', 0)) {
            $this->cart->delete(array('user_id' => $user['user_id']));
        }

        if (!empty($cart['items'])) {
            foreach ($cart['items'] as $item) {
                $this->cart->update($item['cart_id'], array('user_id' => $user['user_id']));
            }
        }

        $this->cart->deleteCookie();
        $result = $this->getResultLogin($user);

        $this->hook->attach('cart.login.after', $user, $cart, $result, $this);
        return (array) $result;
    }
380314
protected static function loginSucceeded( $user )
    {
        $userID = $user->attribute( 'contentobject_id' );

        // if audit is enabled logins should be logged
        eZAudit::writeAudit( 'user-login', array( 'User id' => $userID, 'User login' => $user->attribute( 'login' ) ) );

        eZUser::updateLastVisit( $userID, true );
        eZUser::setCurrentlyLoggedInUser( $user, $userID );

        // Reset number of failed login attempts
        eZUser::setFailedLoginAttempts( $userID, 0 );
    }
595478
public function getAssignments(User $user)
    {
        $assignments = [];
        foreach ($this->getInternalServices() as $service) {
            $assignments = array_merge($assignments, $service->getAssignments($user));
        }

        return $assignments;
    }
1140418
public function onCheckout($cart)
    {
        if (!isset($this->omnipay))
            throw new ShopException('Omnipay gateway not set.', 0);

        if ($this->isCreditCard && !isset($this->creditCard))
            throw new GatewayException('Credit Card not set.', 1);
        try {

            $response = $this->omnipay->authorize(array_merge([
                'amount'    => $cart->total,
                'currency'  => Config::get('shop.currency'),
                'card'      => $this->isCreditCard ? $this->creditCard : [],
                'returnUrl' => $this->callbackSuccess,
            ], $this->options))->send();

            if (!$response->isSuccessful()) {
                throw new CheckoutException($response->getMessage(), 1);
            }

        } catch (Exception $e) {

            throw new CheckoutException(
                'Exception caught while attempting authorize.' . "\n" . 
                $e->getMessage(),
                1
            );
        }
    }
1102391
public static function forUser(User $user)
    {
        if ($user->getIsGuest()) {
            return Yii::$app->session;
        }

        return Yii::createObject(['class' => RemoteCartStorage::class, 'sessionCartId' => 'yz\shoppingcart\ShoppingCart']);
    }
1055231
public function userPendingItems(Member $user)
    {
        // Don't restrict anything for ADMIN users
        $userInstances = DataList::create(WorkflowInstance::class)
            ->where('"WorkflowStatus" != \'Complete\'')
            ->sort('LastEdited DESC');

        if (Permission::checkMember($user, 'ADMIN')) {
            return $userInstances;
        }
        $instances = new ArrayList();
        foreach ($userInstances as $inst) {
            $instToArray = $inst->getAssignedMembers();
            if (!count($instToArray)>0 || !in_array($user->ID, $instToArray->column())) {
                continue;
            }
            $instances->push($inst);
        }

        return $instances;
    }
1311203
public function getUserCart(
        $user = null,
        $locale = null,
        $currency = null,
        $persistEmptyCart = false,
        $updatePrices = false
    ) {
        // cart by session ID
        if (!$user) {
            // TODO: get correct locale
            $locale = 'de';
            $cartsArray = $this->findCartBySessionId();
        } else {
            // TODO: check if cart for this sessionId exists and assign it to user

            // default locale from user
            $locale = $locale ?: $user->getLocale();
            // get carts
            $cartsArray = $this->findCartsByUser($user, $locale);
        }

        // cleanup cart array: remove duplicates and expired carts
        $this->cleanupCartsArray($cartArray);

        // check if cart exists
        if ($cartsArray && count($cartsArray) > 0) {
            // multiple carts found, do a cleanup
            $cart = $cartsArray[0];
        } else {
            // user has no cart - return empty one
            $cart = $this->createEmptyCart($user, $persistEmptyCart);
        }

        // check if all products are still available
        $cartNoRemovedProducts = $this->checkProductsAvailability($cart);

        // create api entity
        $apiOrder = $this->orderFactory->createApiEntity($cart, $locale);

        if (!$cartNoRemovedProducts) {
            $apiOrder->addCartErrorCode(self::CART_STATUS_PRODUCT_REMOVED);
        }

        $this->orderManager->updateApiEntity($apiOrder, $locale);

        // check if prices have changed
        if ($apiOrder->hasChangedPrices()) {
            $apiOrder->addCartErrorCode(self::CART_STATUS_PRICE_CHANGED);
        }

        if ($updatePrices) {
            $this->updateCartPrices($apiOrder->getItems());
        }

        return $apiOrder;
    }
1319775
public function getRegistrationsSummaryForUser(User $user)
    {
        $data = [];
        $rsm = $this->createResultSetMappingBuilder('d');
        $rsm->addScalarResult('sbas_id','sbas_id');
        $rsm->addScalarResult('base_id','base_id');
        $rsm->addScalarResult('dbname','dbname');
        $rsm->addScalarResult('time_limited', 'time_limited');
        $rsm->addScalarResult('limited_from', 'limited_from');
        $rsm->addScalarResult('limited_to', 'limited_to');
        $rsm->addScalarResult('actif', 'actif');

        $sql = "
        SELECT dbname, sbas.sbas_id, time_limited,
               UNIX_TIMESTAMP( limited_from ) AS limited_from,
               UNIX_TIMESTAMP( limited_to ) AS limited_to,
               bas.server_coll_id, Users.id, basusr.actif,
               bas.base_id, " . $rsm->generateSelectClause(['d' => 'd',]) . "
        FROM (Users, bas, sbas)
          LEFT JOIN basusr ON ( Users.id = basusr.usr_id AND bas.base_id = basusr.base_id )
          LEFT JOIN Registrations d ON ( d.user_id = Users.id AND bas.base_id = d.base_id )
        WHERE basusr.actif = 1 AND bas.sbas_id = sbas.sbas_id
        AND Users.id = ?";

        $query = $this->_em->createNativeQuery($sql, $rsm);
        $query->setParameter(1, $user->getId());

        foreach ($query->getResult() as $row) {
            $registrationEntity = $row[0];
            $data[$row['sbas_id']][$row['base_id']] = [
                'base-id' => $row['base_id'],
                'db-name' => $row['dbname'],
                'active' => (Boolean) $row['actif'],
                'time-limited' => (Boolean) $row['time_limited'],
                'in-time' => $row['time_limited'] && ! ($row['limited_from'] >= time() && $row['limited_to'] <= time()),
                'registration' => $registrationEntity
            ];
        }

        return $data;
    }
1306355
public function items()
    {
        $sessionId = $this->getSessionId();
        $userId = $this->auth->id();
        $items = $this->cartItem->getWithBuilder($this->instance, $this->getSessionId(), $userId)->get();

        return $items->filter(function ($item) {
            // Remove CartItem if product not exists
            if (empty($item->product)) {
                $item->delete();

                return false;
            }

            return true;
        });
    }
63994
private function isTransactionUpdated(Cart $cart)
    {
        if (false === $this->session->has('transaction-id')) {
            return false;
        }

        /** @var TransactionRepository $transactionRepository */
        $transactionRepository = $this->manager->getRepository('EcommerceBundle:Transaction');

        /** @var Order $order */
        $transaction = $transactionRepository->find($this->session->get('transaction-id'));

        /** @var ArrayCollection $cartItems */
        $cartItems = $cart->getItems();
        /** @var ArrayCollection $orderItems */
        $productPurchases = $transaction->getItems();

        if ($cartItems->count() !== $productPurchases->count()) {
            return false;
        }

        for ($i=0; $i<$cartItems->count(); $i++) {
            /** @var CartItem $cartItem */
            $cartItem = $cartItems[$i];
            /** @var OrderItem $orderItem */
            $productPurchase = $productPurchases[$i];

            if ($cartItem->getProduct()->getId() !== $productPurchase->getProduct()->getId() ||
                $cartItem->getQuantity() !== $productPurchase->getQuantity()) {
                return false;
            }
        }

        return true;
    }
1323635
public function loginLog(User $user, array $geoIp)
    {
        $geoIp['date'] = date('Y-m-d H:i:s');
        $loginIps = $user->getAttribute('lastLoginIps');

        if (!$loginIps) {
            $loginIps = [];
        }

        array_unshift($loginIps, $geoIp);
        $loginIps = array_slice($loginIps, 0, 3);

        $user->setAttribute('lastLoginIps', $loginIps);
        $this->dm->persist($user);
        $this->dm->flush();

        return $this;
    }
1244385
public function login($user, $password)
    {
        /* @var $session \Mage_Customer_Model_Session */
        $session = Mage::getSingleton('customer/session');
        return $session->login($user, $password);
    }
1262127
protected function tryLoginCustomer($customer = null)
    {
        $result = false;

        if ($customer !== null) {
            $checkUser = $this->accountService->loginUser($customer);
            if (empty($checkUser['sErrorMessages'])) {
                $result = true;
            }
        } else {
            /**
             * this could happen because we do not get all the data from the SSO Provider
             * and cannot create a valid user via RegisterService
             */
            $result = false;
        }

        return $result;
    }
1171785
public function get()
    {
        $customer = null;
        $user = null;

        if (true === $this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
            // user is authenticated
            $user = $this->securityContext->getToken()->getUser();

            if (!$user instanceof UserInterface) {
                throw new \RuntimeException('User must be an instance of Symfony\Component\Security\Core\User\UserInterface');
            }

            $customer = $this->customerManager->findOneBy([
                'user' => $user->getId(),
            ]);
        }

        if (!$customer) {
            $basket = $this->getBasket();

            if ($basket && $basket->getCustomer()) {
                $customer = $basket->getCustomer();
            }
        }

        if (!$customer) {
            $customer = $this->customerManager->create();
        }

        if (!$customer->getLocale()) {
            $customer->setLocale($this->locale);
        }

        if ($user && $customer) {
            $customer->setUser($user);
        }

        return $customer;
    }
610542
private function getManagerForUser($user)
    {
        $tries = [];

        foreach ($this->managers as $manager) {
            if ($manager->supportsUser($user)) {
                return $manager;
            }

            $tries[] = get_class($manager);
        }

        throw new \RuntimeException(
            sprintf(
                'User "%s" is not supported by any UserManager. Tried "%s".',
                $user,
                implode('", "', $tries)
            )
        );
    }
787610
protected function formUserCookieQuery($user, $shopId)
    {
        $query = 'select oxid, oxpassword, oxpasssalt from oxuser '
                 . 'where oxuser.oxpassword != "" and  oxuser.oxactive = 1 and oxuser.oxusername = '
                 . \OxidEsales\Eshop\Core\DatabaseProvider::getDb()->quote($user);

        return $query;
    }
70935
public function toWishlist($cart_id)
    {
        $result = null;
        $this->hook->attach('cart.move.wishlist.before', $cart_id, $result, $this);

        if (isset($result)) {
            return (array) $result;
        }

        $cart = $this->cart->get($cart_id);

        if (empty($cart) || !$this->cart->delete($cart_id)) {
            return $this->getResultError();
        }

        $result = $this->addToWishlist($cart);

        gplcart_static_clear();

        $this->hook->attach('cart.move.wishlist.after', $data, $result, $this);
        return (array) $result;
    }