php XLite-Core-Auth类(方法)实例源码

下面列出了php XLite-Core-Auth 类(方法)源码代码实例,从而了解它的用法。

作者:kings    项目:cor   
/**
  * Remove profileId from URL params if it is profileId of already logged in user
  * 
  * @param integer $profileId Profile ID
  *  
  * @return integer
  */
 protected function correctProfileIdForURLParams($profileId)
 {
     if (\XLite\Core\Auth::getInstance()->getProfile()->getProfileId() === $profileId) {
         $profileId = null;
     }
     return $profileId;
 }

作者:kings    项目:cor   
/**
  * Argument convertion: <LC> --> <DRUPAL>
  *
  * @param string $path Drupal path
  * @param array  $args LC URL arguments OPTIONAL
  *
  * @return array
  */
 public static function getPortalDrupalArgs($path, array $args = array())
 {
     $id = empty($args['profile_id']) ? \XLite\Core\Auth::getInstance()->getProfile()->getProfileId() : $args['profile_id'];
     unset($args['profile_id']);
     list($path, $args) = parent::getPortalDrupalArgs($path, $args);
     $path = preg_replace('/\\%/', static::getDrupalProfileId($id), $path, 1);
     return array($path, $args);
 }

作者:kirkbauer    项目:kirkx   
/**
  * Get user types
  *
  * @return array
  */
 protected function getUserTypes()
 {
     $types = array('C' => static::t('Registered Customers'), 'N' => static::t('Anonymous Customers'));
     if (\XLite\Core\Auth::getInstance()->isPermissionAllowed('manage admins')) {
         $types['A'] = static::t('Administrator');
     }
     return $types;
 }

作者:kings    项目:cor   
/**
  * Define widget parameters
  *
  * @return void
  */
 protected function defineWidgetParams()
 {
     parent::defineWidgetParams();
     $this->widgetParams[static::PARAM_LIST]->setValue('content');
     $this->widgetParams[static::PARAM_CLASS]->setValue('hl');
     $this->widgetParams[static::PARAM_TITLE]->setValue(static::t('Content'));
     $this->widgetParams[static::PARAM_TARGET]->setValue(\XLite\Core\Auth::getInstance()->isPermissionAllowed('manage custom pages') ? 'pages' : 'menus');
 }

作者:kirkbauer    项目:kirkx   
/**
  * Fire event 
  * 
  * @return void
  */
 protected function fireEvent()
 {
     \XLite\Core\Event::switchStorefront(array('opened' => !\XLite\Core\Auth::getInstance()->isClosedStorefront(), 'link' => $this->buildURL('storefront', '', array('action' => \XLite\Core\Auth::getInstance()->isClosedStorefront() ? 'open' : 'close')), 'privatelink' => $this->getAccessibleShopURL(false)));
     if ($this->isAJAX()) {
         $this->silent = true;
         $this->setSuppressOutput(true);
     }
 }

作者:kirkbauer    项目:kirkx   
/**
  * Check field value validity
  *
  * @return boolean
  */
 protected function checkFieldValue()
 {
     $isAllowedForCurrentUser = TRUE;
     if (!\XLite\Core\Auth::getInstance()->isPermissionAllowed('manage admins') && $this->getValue() == \XLite\Core\Auth::getInstance()->getAdminAccessLevel()) {
         $isAllowedForCurrentUser = FALSE;
     }
     return $isAllowedForCurrentUser && in_array($this->getValue(), \XLite\Core\Auth::getInstance()->getAccessLevelsList());
 }

作者:kirkbauer    项目:kirkx   
/**
  * Do action
  *
  * @return void
  */
 protected function doActionConfirmWithPassword()
 {
     $password = \XLite\Core\Request::getInstance()->password;
     $result = null !== $password && \XLite\Core\Auth::comparePassword(\XLite\Core\Auth::getInstance()->getProfile()->getPassword(), $password);
     if (!$result) {
         \XLite\Core\TopMessage::addError('Incorrect password. Please try again.');
     }
     \XLite\Core\Event::passwordConfirmed(array('result' => $result));
 }

作者:kewaunite    项目:xcar   
/**
  * Method to access a singleton
  *
  * @param boolean $doCalculate Flag for cart recalculation OPTIONAL
  *
  * @return \XLite\Model\Cart
  */
 public static function getInstance($doCalculate = true)
 {
     $className = get_called_class();
     // Create new instance of the object (if it is not already created)
     if (!isset(static::$instances[$className])) {
         $auth = \XLite\Core\Auth::getInstance();
         if ($auth->isLogged()) {
             // Try to find cart of logged in user
             $cart = \XLite\Core\Database::getRepo('XLite\\Model\\Cart')->findOneByProfile($auth->getProfile());
         }
         if (empty($cart)) {
             // Try to get cart from session
             $orderId = \XLite\Core\Session::getInstance()->order_id;
             if ($orderId) {
                 $cart = \XLite\Core\Database::getRepo('XLite\\Model\\Cart')->findOneForCustomer($orderId);
                 // Forget cart if cart is order
                 if ($cart && !$cart->hasCartStatus()) {
                     unset(\XLite\Core\Session::getInstance()->order_id, $cart);
                 }
             }
         }
         if (!isset($cart)) {
             // Cart not found - create a new instance
             $cart = new $className();
             $cart->initializeCart();
         }
         static::$instances[$className] = $cart;
         if ($auth->isLogged() && (!$cart->getProfile() || $auth->getProfile()->getProfileId() != $cart->getProfile()->getProfileId())) {
             $cart->setProfile($auth->getProfile());
             $cart->setOrigProfile($auth->getProfile());
         }
         // Check login state
         if (\XLite\Core\Session::getInstance()->lastLoginUnique === null && $cart->getProfile() && $cart->getProfile()->getAnonymous() && $cart->getProfile()->getLogin()) {
             $tmpProfile = new \XLite\Model\Profile();
             $tmpProfile->setProfileId(0);
             $tmpProfile->setLogin($cart->getProfile()->getLogin());
             $profile2 = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findUserWithSameLogin($tmpProfile);
             if ($profile2) {
                 \XLite\Core\Database::getEM()->detach($profile2);
             }
             \XLite\Core\Session::getInstance()->lastLoginUnique = !$profile2;
         }
         if (!$doCalculate) {
             $cart->setIgnoreLongCalculations();
         }
         if (!$cart->isIgnoreLongCalculations() && ($cart instanceof \XLite\Model\Cart || \XLite\Core\Converter::time() - static::RENEW_PERIOD > $cart->getLastRenewDate())) {
             $cart->renew();
         } else {
             $cart->calculate();
         }
         $cart->renewSoft();
         \XLite\Core\Session::getInstance()->order_id = $cart->getOrderId();
     }
     return static::$instances[$className];
 }

作者:kewaunite    项目:xcar   
/**
  * Do action
  *
  * @return void
  */
 protected function doActionConfirmWithPassword()
 {
     $password = \XLite\Core\Request::getInstance()->password;
     $result = null !== $password && \XLite\Core\Auth::comparePassword(\XLite\Core\Auth::getInstance()->getProfile()->getPassword(), $password);
     if ($result) {
         echo 1;
     } else {
         \XLite\Core\TopMessage::addError('Incorrect password. Please try again.');
         echo 0;
     }
 }

作者:kings    项目:cor   
/**
  * Return URL to redirect to
  *
  * @return string
  */
 protected function getAdminAreaURLArgs()
 {
     $query = '';
     if (\XLite\Core\Auth::getInstance()->isAdmin()) {
         $query .= '?' . \XLite\Core\Session::getInstance()->getName();
         $query .= '=' . \XLite\Core\Session::getInstance()->getId();
         $query .= '&' . static::PARAM_DRUPAL_RETURN_URL;
         $query .= '=' . urlencode(\Includes\Utils\URLManager::getCurrentURL());
     }
     return $query;
 }

作者:kewaunite    项目:xcar   
/**
  * Define menu items
  *
  * @return array
  */
 protected function defineItems()
 {
     $menu = array();
     $cnd = new \XLite\Core\CommonCell();
     $cnd->type = \XLite\Module\CDev\SimpleCMS\Model\Menu::MENU_TYPE_FOOTER;
     $cnd->enabled = true;
     $cnd->visibleFor = array('AL', \XLite\Core\Auth::getInstance()->isLogged() ? 'L' : 'A');
     foreach (\XLite\Core\Database::getRepo('XLite\\Module\\CDev\\SimpleCMS\\Model\\Menu')->search($cnd) as $v) {
         $menu[] = array('url' => $v->getURL(), 'label' => $v->getName(), 'controller' => $v->getLinkController());
     }
     return $menu ?: parent::defineItems();
 }

作者:kirkbauer    项目:kirkx   
/**
  * Define menu items
  *
  * @return array
  */
 protected function defineItems()
 {
     $menu = array();
     $cnd = new \XLite\Core\CommonCell();
     $cnd->type = \XLite\Module\CDev\SimpleCMS\Model\Menu::MENU_TYPE_PRIMARY;
     $cnd->enabled = true;
     $cnd->visibleFor = array('AL', \XLite\Core\Auth::getInstance()->isLogged() ? 'L' : 'A');
     foreach (\XLite\Core\Database::getRepo('XLite\\Module\\CDev\\SimpleCMS\\Model\\Menu')->search($cnd) as $v) {
         $menu[] = $this->defineItem($v);
     }
     return \XLite\Core\Config::getInstance()->CDev->SimpleCMS->show_default_menu ? array_merge(parent::defineItems(), $menu) : ($menu ?: parent::defineItems());
 }

作者:kewaunite    项目:xcar   
/**
  * getProfile
  *
  * @return \XLite\Model\Profile
  */
 public function getProfile()
 {
     if (!isset($this->profile)) {
         $profileId = \XLite\Core\Request::getInstance()->profile_id;
         if (isset($profileId)) {
             $this->profile = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->find($profileId);
         } else {
             $this->profile = \XLite\Core\Auth::getInstance()->getProfile();
         }
     }
     return $this->profile;
 }

作者:kings    项目:cor   
/**
  * Define menu items
  *
  * @return array
  */
 protected function defineItems()
 {
     $menu = array();
     $menu[] = array('target' => \XLite::TARGET_DEFAULT, 'url' => $this->buildURL(''), 'label' => static::t('Home'));
     $menu[] = array('target' => 'cart', 'url' => $this->buildURL('cart'), 'label' => static::t('Shopping bag'));
     if (\XLite\Core\Auth::getInstance()->isLogged()) {
         $menu[] = array('target' => 'profile', 'url' => $this->buildURL('profile'), 'label' => static::t('My account'));
     } else {
         $menu[] = array('target' => 'profile', 'url' => $this->buildURL('profile', '', array('mode' => 'register')), 'label' => static::t('Register'));
     }
     return $menu;
 }

作者:kirkbauer    项目:kirkx   
/**
  * Override constructor to add new tab
  *
  * @param array $params Handler params OPTIONAL
  *
  * @return void
  */
 public function __construct(array $params = array())
 {
     if ($this->isLogged()) {
         $cnd = new \XLite\Core\CommonCell();
         $cnd->user = \XLite\Core\Auth::getInstance()->getProfile();
         $count = \XLite\Core\Database::getRepo('XLite\\Model\\Order')->searchWithPinCodes($cnd, true);
         if ($count > 0) {
             $this->tabs['pin_codes'] = array('title' => 'PIN codes', 'template' => 'modules/CDev/PINCodes/account_pin_codes.tpl');
         }
     }
     parent::__construct($params);
 }

作者:kings    项目:cor   
/**
  * Register event to the order
  *
  * @param integer $orderId     Order identificator
  * @param string  $code        Event code
  * @param string  $description Event description
  * @param array   $data        Data for event description OPTIONAL
  * @param string  $comment     Event comment OPTIONAL
  * @param array   $details     Event details OPTIONAL
  *
  * @return void
  */
 public function registerEvent($orderId, $code, $description, array $data = array(), $comment = '', $details = array())
 {
     $event = new \XLite\Model\OrderHistoryEvents(array('date' => time(), 'code' => $code, 'description' => $description, 'data' => $data, 'comment' => $comment));
     if (!empty($details)) {
         $event->setDetails($details);
     }
     $order = \XLite\Core\Database::getRepo('XLite\\Model\\Order')->find($orderId);
     if (\XLite\Core\Auth::getInstance()->getProfile()) {
         $event->setAuthor(\XLite\Core\Auth::getInstance()->getProfile());
     }
     $event->setOrder($order);
     $order->addEvents($event);
     $this->insert($event);
 }

作者:kirkbauer    项目:kirkx   
/**
  * Return value of data
  *
  * @param string $field Field
  *
  * @return string
  */
 public function getValue($field)
 {
     $data = \XLite\Core\Session::getInstance()->contact_us;
     $value = $data && isset($data[$field]) ? $data[$field] : '';
     if (!$value && in_array($field, array('name', 'email'))) {
         $auth = \XLite\Core\Auth::getInstance();
         if ($auth->isLogged()) {
             if ('email' == $field) {
                 $value = $auth->getProfile()->getLogin();
             } elseif (0 < $auth->getProfile()->getAddresses()->count()) {
                 $value = $auth->getProfile()->getAddresses()->first()->getName();
             }
         }
     }
     return $value;
 }

作者:kirkbauer    项目:kirkx   
/**
  * Perform login action
  *
  * @return void
  */
 protected function doActionLogin()
 {
     $loginApi = new \XLite\Module\CDev\Paypal\Core\Login();
     $requestProcessed = false;
     $returnURL = '';
     \XLite\Module\CDev\Paypal\Main::addLog('Login return', \XLite\Core\Request::getInstance()->getData());
     if ($loginApi->checkRequest()) {
         $accessToken = $loginApi->createFromAuthorisationCode(\XLite\Core\Request::getInstance()->code);
         $profileInfo = isset($accessToken['access_token']) ? $loginApi->getUserinfo($accessToken['access_token']) : null;
         if ($profileInfo && !empty($profileInfo['user_id']) && !empty($profileInfo['email'])) {
             $profile = $this->getSocialLoginProfile($profileInfo['email'], 'PayPal', $profileInfo['user_id'], $profileInfo);
             if ($profile) {
                 if ($profile->isEnabled()) {
                     \XLite\Core\Auth::getInstance()->loginProfile($profile);
                     $accessToken['expirationTime'] = LC_START_TIME + $accessToken['expires_in'];
                     \XLite\Core\Session::getInstance()->paypalAccessToken = $accessToken;
                     // We merge the logged in cart into the session cart
                     $profileCart = $this->getCart();
                     $profileCart->login($profile);
                     \XLite\Core\Database::getEM()->flush();
                     if ($profileCart->isPersistent()) {
                         $this->updateCart();
                     }
                     $returnURL = $this->getAuthReturnURL();
                 } else {
                     \XLite\Core\TopMessage::addError('Profile is disabled');
                     $returnURL = $this->getAuthReturnURL(true);
                 }
             } else {
                 $provider = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findOneBy(array('login' => $profileInfo['email'], 'order' => null))->getSocialLoginProvider();
                 if ($provider) {
                     $signInVia = 'Please sign in with ' . $provider . '.';
                 } else {
                     $signInVia = 'Profile with the same e-mail address already registered. ' . 'Please sign in the classic way.';
                 }
                 \XLite\Core\TopMessage::addError($signInVia);
                 $returnURL = $this->getAuthReturnURL(true);
             }
             $requestProcessed = true;
         }
     }
     if (!$requestProcessed) {
         \XLite\Core\TopMessage::addError('We were unable to process this request');
         $returnURL = '';
     }
     $this->closePopup($returnURL);
 }

作者:kirkbauer    项目:kirkx   
/**
  * Check ACL permissions
  *
  * @return boolean
  */
 public function checkACL()
 {
     $result = parent::checkACL();
     if (!$result) {
         $dictionary = \XLite\Core\Request::getInstance()->dictionary;
         $permissions = $this->getDictionaryPermissions();
         if (!empty($permissions[$dictionary])) {
             foreach ($permissions[$dictionary] as $p) {
                 if (\XLite\Core\Auth::getInstance()->isPermissionAllowed($p)) {
                     $result = true;
                     break;
                 }
             }
         }
     }
     return $result;
 }

作者:kings    项目:cor   
/**
  * Get return URL
  *
  * @return string
  */
 public function getReturnURL()
 {
     if (\XLite\Core\Request::getInstance()->action) {
         $profileId = \XLite\Core\Request::getInstance()->profile_id;
         if (!isset($profileId)) {
             $profileId = $this->getAddress()->getProfile()->getProfileId();
             if (\XLite\Core\Auth::getInstance()->getProfile()->getProfileId() === $profileId) {
                 unset($profileId);
             }
         }
         $params = isset($profileId) ? array('profile_id' => $profileId) : array();
         $url = $this->buildURL('address_book', '', $params);
     } else {
         $url = parent::getReturnURL();
     }
     return $url;
 }


问题


面经


文章

微信
公众号

扫码关注公众号