Пример #1
0
 /**
  * checkCookieForToken
  */
 protected function checkCookieForToken()
 {
     if (isset($_COOKIE['onxshop_token'])) {
         require_once 'models/client/client_customer_token.php';
         $Token = new client_customer_token();
         $Token->setCacheable(false);
         $customer_detail = $Token->getCustomerDetailForToken($_COOKIE['onxshop_token']);
         if ($customer_detail) {
             require_once 'models/client/client_customer.php';
             $Customer = new client_customer();
             $Customer->setCacheable(false);
             $conf = $Customer::initConfiguration();
             if ($conf['login_type'] == 'username') {
                 $username = $customer_detail['username'];
             } else {
                 $username = $customer_detail['email'];
             }
             $customer_detail = $Customer->login($username);
             if ($customer_detail) {
                 $_SESSION['client']['customer'] = $customer_detail;
                 $_SESSION['use_page_cache'] = false;
             } else {
                 msg('Autologin failed', 'error', 1);
             }
         } else {
             msg('Invalid autologin token supplied', 'error', 1);
             //delete cookie
             setcookie('onxshop_token', '', time() - 3600, '/');
         }
     }
 }
Пример #2
0
 /**
  * main action
  */
 public function mainAction()
 {
     /**
      * client
      */
     $Customer = new client_customer();
     $Customer->setCacheable(false);
     if ($_SESSION['client']['customer']['id'] > 0 && !$this->GET['client']['email']) {
         //msg('you are in');
         //onxshopGoTo($this->GET['to']);
     } else {
         /* client submitted username/password */
         if (isset($_POST['login'])) {
             $customer_detail = $Customer->login($_POST['client']['customer']['email'], md5($_POST['client']['customer']['password']));
             if ($customer_detail) {
                 $_SESSION['client']['customer'] = $customer_detail;
                 if (isset($_POST['autologin'])) {
                     // auto login (TODO allow to enable/disable this behaviour globally)
                     $Customer->generateAndSaveOnxshopToken($customer_detail['id']);
                 }
             } else {
                 $this->loginFailed();
             }
         }
         /* log in as client from backoffice */
         if (Onxshop_Bo_Authentication::getInstance()->isAuthenticated() && $this->GET['client']['email']) {
             $customer_detail = $Customer->getClientByEmail($this->GET['client']['email']);
             if ($customer_detail) {
                 $_SESSION['client']['customer'] = $customer_detail;
             } else {
                 msg('Login from backoffice failed.', 'error');
             }
         }
     }
     /**
      * check status
      */
     if ($_SESSION['client']['customer']['id'] > 0 && is_numeric($_SESSION['client']['customer']['id'])) {
         $this->actionAfterLogin();
     }
     //output
     $this->tpl->assign('CLIENT', $_POST['client']);
     $this->tpl->parse('content.login_box');
     return true;
 }
 public function authenticate($username, $password)
 {
     $Client_Customer = new client_customer();
     $Client_Customer->setCacheable(false);
     $customer_detail = $Client_Customer->login($username, md5($password));
     if ($customer_detail) {
         $Permission = new client_role_permission();
         $Permission->setCacheable(false);
         if ($Permission->isBackofficeUser($customer_detail['id'])) {
             return $customer_detail;
         }
     }
     return false;
 }