Пример #1
0
 public function createRecordAction()
 {
     $resultModel = new JsonResultModel();
     if ($this->getRequest()->isPost()) {
         $jsonData = $this->getRequest()->getPost('saleRecord');
         $saleRecord = Json::decode($jsonData);
         try {
             $this->saleRecordService->create($saleRecord);
         } catch (ValidationException $e) {
             $resultModel->setErrors($e->getValidationError());
             return $resultModel;
         }
         return $resultModel;
     }
 }
Пример #2
0
 public function createCustomerAction()
 {
     $resultModel = new JsonResultModel();
     if ($this->getRequest()->isPost()) {
         try {
             $jsonData = $this->params()->fromPost('customer');
             $customer = new Customer(Json::decode($jsonData, Json::TYPE_ARRAY));
             $customer->setCreateTime(new \DateTime());
             //@todo 这一行抛出异常被捕获处理后,会不会执行下一行??
             $this->customerService->create($customer);
         } catch (ValidationException $e) {
             $resultModel->setErrors($e->getValidationError());
             return $resultModel;
         } catch (\Exception $e) {
             $resultModel->addErrors('undefined', $e->getMessage());
             return $resultModel;
         }
         return $resultModel;
     }
 }
Пример #3
0
 public function loginAction()
 {
     if ($this->authenticationService->hasIdentity()) {
         return $this->redirect()->toRoute('home');
     }
     $this->layout('layout/layout-blank');
     $resultModel = new JsonResultModel();
     if ($this->getRequest()->isPost()) {
         $jsonData = $this->getRequest()->getPost('login');
         $data = Json::decode($jsonData, Json::TYPE_ARRAY);
         // If you used another name for the authentication service, change it here
         $adapter = $this->authenticationService->getAdapter();
         $adapter->setIdentityValue($data['username']);
         $adapter->setCredentialValue($data['password']);
         $authResult = $this->authenticationService->authenticate();
         //@todo remember me
         if ($authResult->isValid()) {
             if ($data['rememberMe']) {
                 $this->authenticationService->getStorage()->getManager()->rememberMe(36000);
             }
             return $resultModel;
         } else {
             $resultModel->addErrors('password', '登录名或密码错误');
             return $resultModel;
         }
     }
 }