コード例 #1
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);
     }
 }
コード例 #2
0
 public function deleteAction()
 {
     if ($customer_id = $this->getRequest()->getPost('customer_id')) {
         try {
             $customer = new Customer_Model_Customer();
             $customer->find($customer_id);
             if (!$customer->getId() || $customer->getAppId() != $this->getApplication()->getId()) {
                 throw new Exception($this->_("An error occurred while saving. Please try again later."));
             }
             $customer_id = $customer->getId();
             $customer->delete();
             $html = array("success" => 1, "customer_id" => $customer_id);
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getResponse()->setBody(Zend_Json::encode($html))->sendResponse();
         die;
     }
 }