Ejemplo n.º 1
0
 public function loginAction()
 {
     try {
         $jsonData = $this->getRequest()->getContent();
         $data = $this->serializer->deserialize($jsonData, "Application\\API\\Canonicals\\Dto\\Credentials", "json");
         $username = trim(strtolower($data->getUsername()));
         $password = $data->getPassword();
         $this->authService->getAdapter()->setIdentity($username)->setCredential($password);
         $result = $this->authService->authenticate();
         $user = $this->usersRepository->find($username);
         if (!$result->isValid()) {
             $this->usersRepository->incrementTries($username);
             $response = ResponseUtils::createResponse($result->getMessages());
             return $this->jsonResponse($response);
         } else {
             if ($user->getTries() >= $this->maxLoginTries) {
                 $this->authService->clearIdentity();
                 throw new \Exception("This account has been locked");
             } else {
                 $this->usersRepository->resetTriesAndLogin($username);
                 $this->authService->getStorage()->write($username);
                 $response = ResponseUtils::createResponse();
                 return $this->jsonResponse($response);
             }
         }
     } catch (\Exception $ex) {
         $response = ResponseUtils::createExceptionResponse($ex);
         return $this->jsonResponse($response);
     }
 }
Ejemplo n.º 2
0
 public function addorupdateclientAction()
 {
     try {
         if (!$this->authService->hasIdentity()) {
             throw new \Exception("Unauthorized Access");
         }
         $jsonData = $this->getRequest()->getContent();
         $client = $this->serializer->deserialize($jsonData, "Application\\API\\Canonicals\\Entity\\Client", "json");
         $this->clientsRepository->addOrUpdateClient($client);
         $response = ResponseUtils::createWriteResponse($client);
         return $this->jsonResponse($response);
     } catch (\Exception $ex) {
         $response = ResponseUtils::createExceptionResponse($ex);
         return $this->jsonResponse($response);
     }
 }
Ejemplo n.º 3
0
 public function deleteuserAction()
 {
     try {
         $authService = $this->getServiceLocator()->get('AdminAuthService');
         $jsonData = $this->getRequest()->getContent();
         $data = $this->serializer->deserialize($jsonData, "Application\\API\\Canonicals\\Entity\\Users", "json");
         if (!$authService->hasIdentity()) {
             throw new \Exception("Unauthorized Access");
         } else {
             if ($authService->getIdentity() == $data->getUsername()) {
                 throw new \Exception("Cannot Delete Current User");
             }
         }
         $usersRepo = $this->getServiceLocator()->get('UsersRepo');
         $usersRepo->deleteUser($data->getUsername(), $data->getPassword());
         $response = ResponseUtils::createWriteResponse(array('users' => $usersRepo->findAll()));
         return $this->jsonResponse($response);
     } catch (\Exception $ex) {
         $response = ResponseUtils::createExceptionResponse($ex);
         return $this->jsonResponse($response);
     }
 }
Ejemplo n.º 4
0
 public function checkstockandinitiatedonationAction()
 {
     try {
         $jsonData = $this->getRequest()->getContent();
         $data = $this->serializer->deserialize($jsonData, "Application\\API\\Canonicals\\Entity\\Qurbani", "json");
         $qurbaniRepo = $this->getServiceLocator()->get('QurbaniRepo');
         $config = $this->getServiceLocator()->get('Config');
         $domainname = $config["DomainName"];
         $qurbaniDetails = $qurbaniRepo->getQurbaniDetails();
         $qurbanikey = $qurbaniRepo->checkStockAndAddQurbani($data);
         $shortUrl = $qurbaniDetails->shorturl;
         $amount = $data->getTotal();
         $exitUrl = "http://{$domainname}/api/QurbaniApi/confirmdonation/JUSTGIVING-DONATION-ID/{$qurbanikey}";
         $redirectUrl = "http://www.justgiving.com/{$shortUrl}/4w350m3/donate?amount={$amount}&exitUrl={$exitUrl}";
         $response = ResponseUtils::createSingleFetchResponse($redirectUrl);
         return $this->jsonResponse($response);
     } catch (\Exception $ex) {
         $response = ResponseUtils::createExceptionResponse($ex);
         return $this->jsonResponse($response);
     }
 }