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); } }
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); } }
public function search($page = 0, $pageSize = 25, $purchasedOnly = true, $includeVoid = false) { $errors = array(); $total = 0; $items = null; try { $query = array(); foreach (array(QurbaniRepository::CNT, QurbaniRepository::RST) as $index) { $query[$index] = $this->qurbaniRepo->repository->createQueryBuilder("q")->where("q.qurbanimonth = :pQurbanimonth")->setParameter("pQurbanimonth", $this->details->qurbanimonth); if ($purchasedOnly) { $query[$index] = $query[$index]->andWhere("q.donationid IS NOT NULL"); } if (!$includeVoid) { $query[$index] = $query[$index]->andWhere("q.isvoid = 0"); } $query[$index] = $query[$index]->orderBy("q.createddate", "DESC"); if ($index == QurbaniRepository::CNT) { $query[$index] = $query[$index]->select("COUNT(q.qurbanikey)"); } } $total = $query[QurbaniRepository::CNT]->getQuery()->getSingleScalarResult(); $items = $query[QurbaniRepository::RST]->setFirstResult($page * $pageSize)->setMaxResults($pageSize)->getQuery()->getResult(); } catch (\Exception $ex) { array_push($errors, $ex->getMessage()); } return ResponseUtils::createSearchResponse($total, $items, $page, $pageSize, $errors); }
public function search($page = 0, $pageSize = 10, array $orderBy = null) { if ($page < 0 || $pageSize < 1) { throw new \Exception("Invalid page or pageSize: page must be >= 0 and pageSize must be > 0"); } else { $metadata = $this->em->getClassMetadata($this->repository->getClassName()); $identifiers = $metadata->getIdentifierFieldNames(); $id = $identifiers[0]; $total = $this->repository->createQueryBuilder("q")->select("COUNT(q.{$id})")->getQuery()->getSingleScalarResult(); $query = $this->repository->createQueryBuilder("q"); if ($orderBy != null) { foreach ($orderBy as $field => $direction) { $query->orderBy(new Expr\OrderBy("q.{$field}", $direction)); } } $items = $query->setFirstResult($page * $pageSize)->setMaxResults($pageSize)->getQuery()->getResult(); return ResponseUtils::createSearchResponse($total, $items, $page, $pageSize); } }
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); } }
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); } }