/** * Returns all the available security-questions for the application * @return JsonModel */ public function getSecurityQuestionsAction() { if ($this->request->isOptions()) { return new JsonModel(); } $controllerName = $this->params('controller'); $actionName = $this->params('action'); $authenticationHelper = new AuthenticationHelper($this->getServiceLocator()); $headers = $this->request->getHeaders(); $authTokenObject = $headers->get('authToken'); $hasPermission = $authenticationHelper->checkPermissions($controllerName, $actionName, $authTokenObject); if (!$hasPermission) { $this->response->setStatusCode(401); return new JsonModel(array('error' => 1, 'message' => 'You don\'t have the necessary permissions to view this resource .')); } $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $questions = $objectManager->getRepository('Application\\Entity\\LtSecurityQuestion')->findAll(); $questionList = array(); foreach ($questions as $question) { $questionList[$question->getSecurityquestionid()] = $question->getSecurityquestion(); } return new JsonModel($questionList); }
public function indexAction() { if ($this->request->isOptions()) { return new JsonModel(); } $controllerName = $this->params('controller'); $actionName = $this->params('action'); $authenticationHelper = new AuthenticationHelper($this->getServiceLocator()); $headers = $this->request->getHeaders(); $authTokenObject = $headers->get('authToken'); $hasPermission = $authenticationHelper->checkPermissions($controllerName, $actionName, $authTokenObject); if (!$hasPermission) { $this->response->setStatusCode(401); return new JsonModel(array('error' => 1, 'message' => 'You don\'t have the necessary permissions to view this resource.')); } $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $user = $objectManager->getRepository('Application\\Entity\\LtUser')->findOneBy(array('authtoken' => $authTokenObject->getFieldValue())); $userArray = array('email' => $user->getEmail(), 'contactName' => $user->getContactname(), 'profilePicturePath' => $user->getProfilepicturepath(), 'registrationDate' => $user->getRegistrationdate()->format('Y-m-d')); if ($user->getPhone() !== '') { $userArray['phone'] = $user->getPhone(); } else { $userArray['phone'] = null; } return new JsonModel($userArray); }