コード例 #1
0
 public function loginpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             if (empty($datas['email']) or empty($datas['password'])) {
                 throw new Exception($this->_('Authentication failed. Please check your email and/or your password'));
             }
             $customer = new Customer_Model_Customer();
             $customer->find($datas['email'], 'email');
             $password = $datas['password'];
             if (!$customer->authenticate($password)) {
                 throw new Exception($this->_('Authentication failed. Please check your email and/or your password'));
             }
             $this->getSession()->resetInstance()->setCustomer($customer);
             $html = array('success' => 1, 'customer_id' => $customer->getId());
         } catch (Exception $e) {
             $html = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->_sendHtml($html);
     }
 }
コード例 #2
0
 public function postAction()
 {
     if ($datas = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             if (empty($datas['email']) or empty($datas['password'])) {
                 throw new Exception($this->_('Authentication failed. Please check your email and/or your password'));
             }
             $customer = new Customer_Model_Customer();
             $customer->find(array('email' => $datas['email'], 'app_id' => $this->getApplication()->getId()));
             $password = $datas['password'];
             if (!$customer->getId() or !$customer->authenticate($password)) {
                 throw new Exception($this->_('Authentication failed. Please check your email and/or your password'));
             }
             if (!$customer->getAppId()) {
                 $customer->setAppId($this->getApplication()->getId())->save();
             }
             $this->getSession()->resetInstance()->setCustomer($customer);
             $html = array('success' => 1, 'customer_id' => $customer->getId(), 'can_access_locked_features' => $customer->canAccessLockedFeatures());
         } catch (Exception $e) {
             $html = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->_sendHtml($html);
     }
 }