Пример #1
0
 public function loginAction()
 {
     try {
         $jsonData = $this->getRequest()->getContent();
         $data = $this->serializer->deserialize($jsonData, "Application\\API\\Canonicals\\Entity\\Users", "json");
         $authService = $this->getServiceLocator()->get('AdminAuthService');
         $authService->getAdapter()->setIdentity($data->getUsername())->setCredential($data->getPassword());
         $result = $authService->authenticate();
         $usersRepo = $this->getServiceLocator()->get('UsersRepo');
         $user = $usersRepo->find($data->getUsername());
         if (!$result->isValid() && $user == null) {
             throw new \Exception("Could not find a matching Record");
         } else {
             if (!$result->isValid() && $user != null) {
                 $user->setTries($user->getTries() + 1);
                 $usersRepo->updateUser($user, $user->getPassword());
                 throw new \Exception("Could not find a matching Record");
             } else {
                 if ($user->getTries() >= 3) {
                     throw new \Exception("Sorry this account has been locked.");
                 } else {
                     $user->setTries(0);
                     $usersRepo->updateUser($user, $user->getPassword());
                     $authService->getStorage()->write($data->getUsername());
                     $response = ResponseUtils::createResponse();
                     return $this->jsonResponse($response);
                 }
             }
         }
     } catch (\Exception $ex) {
         $response = ResponseUtils::createExceptionResponse($ex);
         return $this->jsonResponse($response);
     }
 }
Пример #2
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);
     }
 }
Пример #3
0
 public function checkstockanddonateAction()
 {
     try {
         $authService = $this->getServiceLocator()->get('AdminAuthService');
         if (!$authService->hasIdentity()) {
             throw new \Exception("Unauthorized Access");
         }
         $jsonData = $this->getRequest()->getContent();
         $data = $this->serializer->deserialize($jsonData, "Application\\API\\Canonicals\\Entity\\Qurbani", "json");
         $qurbaniRepo = $this->getServiceLocator()->get('QurbaniRepo');
         $qurbanikey = $qurbaniRepo->checkStockAndAddQurbani($data, true);
         if ($data->getEmail() != null) {
             $gMailSvc = $this->getServiceLocator()->get('GMailSvc');
             $gMailSvc->qurbaniConfrimationAlert($qurbanikey);
         }
         $response = ResponseUtils::createResponse();
         return $this->jsonResponse($response);
     } catch (\Exception $ex) {
         $response = ResponseUtils::createExceptionResponse($ex);
         return $this->jsonResponse($response);
     }
 }