/** * @return void * @throws \TYPO3\Flow\Security\Exception\AuthenticationRequiredException */ public function initializeAction() { $this->authenticationManager->authenticate(); if ($this->session->getLocation() == null && $this->request->getControllerName() != 'Login' && !$this->authenticationManager->getSecurityContext()->hasRole('DLigo.Animaltool:Admin') && $this->request->getControllerActionName() != 'select' && $this->request->getControllerName() != 'Location') { $this->redirect('select', 'location'); } if ($this->request->hasArgument('cancel')) { if (!($this->request->getControllerActionName() == 'merge' && $this->request->getControllerName() == 'Animal')) { $this->redirect('index', 'animal'); } } $msgs = $this->flashMessageContainer->getMessagesAndFlush(); foreach ($msgs as $msg) { if ($msg->getSeverity() == 'Error' && $msg->getTitle() == '' && $msg->getCode() === null) { continue; } $this->flashMessageContainer->addMessage($msg); } if (isset($this->arguments['animal'])) { $this->arguments['animal']->getPropertyMappingConfiguration()->forProperty('birthday')->setTypeConverterOption('TYPO3\\Flow\\Property\\TypeConverter\\DateTimeConverter', \TYPO3\Flow\Property\TypeConverter\DateTimeConverter::CONFIGURATION_DATE_FORMAT, 'Y-m-d'); } if (isset($this->arguments['newAnimal'])) { $this->arguments['newAnimal']->getPropertyMappingConfiguration()->forProperty('birthday')->setTypeConverterOption('TYPO3\\Flow\\Property\\TypeConverter\\DateTimeConverter', \TYPO3\Flow\Property\TypeConverter\DateTimeConverter::CONFIGURATION_DATE_FORMAT, 'Y-m-d'); } }
/** * Adds a NotEmptyValidator to the current element if the "trigger" value is not empty. * The trigger can be configured with $this->properties['triggerPropertyPath'] * * @param \TYPO3\Form\Core\Runtime\FormRuntime $formRuntime * @return void */ protected function requireIfTriggerIsSet(\TYPO3\Form\Core\Runtime\FormRuntime $formRuntime) { if ($formRuntime->getRequest()->getParentRequest()->getControllerActionName() == 'newDataSheet') { if ($this->authenticationManager->isAuthenticated() && $this->authenticationManager->getSecurityContext()->hasRole('GIB.GradingTool:Administrator')) { $this->addValidator(new \TYPO3\Flow\Validation\Validator\NotEmptyValidator()); } elseif (!$this->authenticationManager->isAuthenticated()) { $this->addValidator(new \TYPO3\Flow\Validation\Validator\NotEmptyValidator()); } else { return; } } elseif ($formRuntime->getRequest()->getParentRequest()->getControllerActionName() == 'editDataSheet') { return; } }
/** * Authenticates an account by invoking the Provider based Authentication Manager. * * On successful authentication redirects to the list of posts, otherwise returns * to the login screen. * * @return void * @throws \TYPO3\Flow\Security\Exception\AuthenticationRequiredException */ public function authenticateAction() { try { $this->authenticationManager->authenticate(); $this->session->start(); if ($this->authenticationManager->getSecurityContext()->hasRole('DLigo.Animaltool:Admin')) { $this->redirect('index', 'Animal'); } else { $this->redirect('select', 'location'); } } catch (\TYPO3\Flow\Security\Exception\AuthenticationRequiredException $exception) { $this->addFlashMessage('Wrong username or password.', '', \TYPO3\Flow\Error\Message::SEVERITY_ERROR, array(), 'flash.password'); throw $exception; } }
/** * @return \DLigo\Animaltool\Domain\Model\User */ public function getUser() { if (!$this->user) { $this->user = $this->authenticationManager->getSecurityContext()->getAccount()->getParty(); } return $this->user; }
/** * @param string $username */ public function setUsername($username = NULL) { $this->username = $username; $securityContext = $this->authenticationManager->getSecurityContext(); if ($securityContext->isInitialized() && $securityContext->getAccount()) { $this->username = $this->authenticationManager->getSecurityContext()->getAccount()->getAccountIdentifier(); } }
/** * Check if user is already registered for an event. * * @param NodeInterface $event * @param NodeInterface $person * * @return string */ public function render(NodeInterface $event, NodeInterface $person = null) { $authenticationProviderName = $this->authenticationManagerInterface->getSecurityContext()->getAccount()->getAuthenticationProviderName(); if ($authenticationProviderName === 'Typo3BackendProvider') { return $this->renderElseChild(); } if ($person === null) { $person = $this->profileService->getCurrentPartyProfile(); } $eventAttendees = $event->getProperty('attendees') ? $event->getProperty('attendees') : []; $eventAttendeesIdentifiers = []; foreach ($eventAttendees as $eventAttendee) { /* @var NodeInterface $eventAttendee */ $eventAttendeesIdentifiers[] = $eventAttendee->getIdentifier(); } if (in_array($person->getIdentifier(), $eventAttendeesIdentifiers, true)) { return $this->renderThenChild(); } return $this->renderElseChild(); }
/** * Dashboard for project manager */ public function dashboardAction() { /** @var \GIB\GradingTool\Domain\Model\ProjectManager $projectManager */ $projectManager = $this->authenticationManager->getSecurityContext()->getParty(); $this->view->assignMultiple(array('projects' => $projectManager->getProjects())); }
public function addAction() { $currentUser = $this->authenticationManager->getSecurityContext()->getAccount()->getParty(); $photoInfo = $this->request->getArgument("photo"); $actionData = $this->request->getArgument("action"); $actionData = json_decode($actionData, true); $animalData = $this->request->getArgument("animal"); $animalData = json_decode($animalData, true); $ownerData = $this->request->getArgument("owner"); $ownerData = json_decode($ownerData, true); $photoData = $this->request->getArgument("photo"); $action = $this->propertyMapper->convert($actionData, 'DLigo\\Animaltool\\Domain\\Model\\Action'); $action->setDate(new \DateTime('now')); $user = $this->propertyMapper->convert($actionData['team'], 'DLigo\\Animaltool\\Domain\\Model\\User'); $lastId = $user->getLastBoxID(); $action->setTeam($user); $box = explode('-', $actionData['boxID']); if ($lastId > $box[1]) { $action->setBoxID($user->getTeamID() . '-' . ($lastId + 1)); } $animal = $this->propertyMapper->convert($animalData, 'DLigo\\Animaltool\\Domain\\Model\\Animal'); $birthday = \DateTime::createFromFormat("U", $animalData["birthday"]); if (!empty($animalData["birthday"])) { $birthday = \DateTime::createFromFormat("U", $animalData["birthday"]); $birthday->setTime(0, 0, 0); $animal->setBirthday($birthday); } $action->setAnimal($animal); $owner = null; if (isset($animalData["isPrivate"]) && $animalData["isPrivate"]) { $owner = $this->propertyMapper->convert($ownerData, 'DLigo\\Animaltool\\Domain\\Model\\Owner'); $animal->setOwner($owner); $animal->setEarTag(null); if (!empty($animalData["earTag"])) { $rfid = $animalData["earTag"]; $oldAnimal = $this->animalRepository->findOneByRFID($rfid); if ($oldAnimal == null) { $animal->setRFID($rfid); } } } else { if (!empty($animalData["earTag"])) { $eartag = $animalData["earTag"]; $oldAnimal = $this->animalRepository->findOneByEarTag($eartag); if ($oldAnimal != null) { $animal->setEarTag(null); } } } $photo = $this->resourceManager->importUploadedResource($photoInfo); //$this->systemLogger->log(\TYPO3\Flow\var_dump($photo,"Photo",true,true),LOG_INFO); $animal->setPhoto($photo); if ($owner) { $this->ownerRepository->add($owner); } $this->animalRepository->add($animal); $this->actionRepository->add($action); $this->userRepository->update($user); $this->persistenceManager->persistAll(); $this->response->setStatus(201); echo "{" . '"lastID": ' . $currentUser->getLastBoxID() . "}"; flush(); ob_flush(); }
/** * Executes this finisher * @see AbstractFinisher::execute() * * @return void * @throws \TYPO3\Flow\Mvc\Exception\StopActionException(); */ protected function executeInternal() { /** @var \TYPO3\Form\Core\Runtime\FormRuntime $formRuntime */ $formRuntime = $this->finisherContext->getFormRuntime(); $formValueArray = $formRuntime->getFormState()->getFormValues(); if ($formRuntime->getRequest()->getParentRequest()->getControllerActionName() == 'editDataSheet') { // we need to update the data sheet, we assume that the person is authenticated because a data sheet can only be edited by a authenticated user /** @var \GIB\GradingTool\Domain\Model\Project $project */ $project = $this->projectRepository->findByIdentifier($formRuntime->getRequest()->getParentRequest()->getArgument('project')); // make a HTML representation of a diff of the old and new data $diffContent = DiffUtility::arrayDiffRecursive($project->getDataSheetContentArray(), $formValueArray); // store changes to project $project->setDataSheetContent($formValueArray); $project->setLastUpdated(new \TYPO3\Flow\Utility\Now()); // update e-mail address (could have changed in the data sheet) $projectManagerElectronicAddress = new \TYPO3\Party\Domain\Model\ElectronicAddress(); $projectManagerElectronicAddress->setIdentifier($formValueArray['projectManagerEmail']); $projectManagerElectronicAddress->setType(\TYPO3\Party\Domain\Model\ElectronicAddress::TYPE_EMAIL); $project->getProjectManager()->setPrimaryElectronicAddress($projectManagerElectronicAddress); $this->partyRepository->update($project->getProjectManager()); $this->projectRepository->update($project); $this->persistenceManager->persistAll(); // send a notification mail to the Administrator containing the changes $templateIdentifierOverlay = $this->templateService->getTemplateIdentifierOverlay('editDataSheetNotification', $project); $this->notificationMailService->sendNotificationMail($templateIdentifierOverlay, $project, NULL, '', '', $diffContent); // add a flash message $message = new \TYPO3\Flow\Error\Message('Your data sheet for project "%s" was successfully edited.', \TYPO3\Flow\Error\Message::SEVERITY_OK, array($project->getProjectTitle())); $this->flashMessageContainer->addMessage($message); } else { // we need to add a new data sheet /** @var \GIB\GradingTool\Domain\Model\Project $project */ $project = new \GIB\GradingTool\Domain\Model\Project(); $project->setProjectTitle($formValueArray['projectTitle']); $project->setDataSheetFormIdentifier($this->settings['forms']['dataSheet']['default']); $project->setSubmissionFormIdentifier($this->settings['forms']['submission']['default']); // store identifier=userName and password for later usage $identifier = $formValueArray['userName']; $password = $formValueArray['password']; // remove userName and password from data array so it doesn't get saved unencrypted unset($formValueArray['userName']); unset($formValueArray['password']); $project->setDataSheetContent($formValueArray); $project->setCreated(new \TYPO3\Flow\Utility\Now()); $this->projectRepository->add($project); // add a flash message $message = new \TYPO3\Flow\Error\Message('Your data sheet for project "%s" was successfully submitted.', \TYPO3\Flow\Error\Message::SEVERITY_OK, array($formValueArray['projectTitle'])); $this->flashMessageContainer->addMessage($message); if (!$this->authenticationManager->isAuthenticated() || $this->authenticationManager->isAuthenticated() && $this->authenticationManager->getSecurityContext()->hasRole('GIB.GradingTool:Administrator')) { // the product manager (supposedly) doesn't have an account yet, so we create one $projectManager = new \GIB\GradingTool\Domain\Model\ProjectManager(); $projectManagerName = new \TYPO3\Party\Domain\Model\PersonName('', $formValueArray['projectManagerFirstName'], '', $formValueArray['projectManagerLastName']); $projectManager->setName($projectManagerName); $projectManagerElectronicAddress = new \TYPO3\Party\Domain\Model\ElectronicAddress(); $projectManagerElectronicAddress->setIdentifier($formValueArray['projectManagerEmail']); $projectManagerElectronicAddress->setType(\TYPO3\Party\Domain\Model\ElectronicAddress::TYPE_EMAIL); $projectManager->addElectronicAddress($projectManagerElectronicAddress); $projectManager->setPrimaryElectronicAddress($projectManagerElectronicAddress); // add account $roles = array('GIB.GradingTool:ProjectManager'); $authenticationProviderName = 'DefaultProvider'; $account = $this->accountFactory->createAccountWithPassword($identifier, $password, $roles, $authenticationProviderName); $this->accountRepository->add($account); // add account to ProjectManager $projectManager->addAccount($account); // add project to ProjectManager $projectManager->addProject($project); // finally add the complete ProjectManager $this->partyRepository->add($projectManager); if (!$this->authenticationManager->getSecurityContext()->hasRole('GIB.GradingTool:Administrator')) { // authenticate user if no Administrator is authenticated $authenticationTokens = $this->securityContext->getAuthenticationTokensOfType('TYPO3\\Flow\\Security\\Authentication\\Token\\UsernamePassword'); if (count($authenticationTokens) === 1) { $authenticationTokens[0]->setAccount($account); $authenticationTokens[0]->setAuthenticationStatus(\TYPO3\Flow\Security\Authentication\TokenInterface::AUTHENTICATION_SUCCESSFUL); } // add a flash message $message = new \TYPO3\Flow\Error\Message('The account "%s" was created and you were successfully logged in.', \TYPO3\Flow\Error\Message::SEVERITY_OK, array($identifier)); $this->flashMessageContainer->addMessage($message); } } elseif ($this->authenticationManager->isAuthenticated() && $this->authenticationManager->getSecurityContext()->hasRole('GIB.GradingTool:ProjectManager')) { // a productManager is adding a new project to his account /** @var \GIB\GradingTool\Domain\Model\ProjectManager $projectManager */ $projectManager = $this->authenticationManager->getSecurityContext()->getParty(); $projectManager->addProject($project); $this->partyRepository->update($projectManager); } $this->persistenceManager->persistAll(); // send notification mail to project manager (bcc to team) $templateIdentifierOverlay = $this->templateService->getTemplateIdentifierOverlay('newDataSheetProjectManagerNotification', $project); $this->notificationMailService->sendNotificationMail($templateIdentifierOverlay, $project, $projectManager, $formValueArray['projectManagerFirstName'] . ' ' . $formValueArray['projectManagerLastName'], $formValueArray['projectManagerEmail']); // send notification mail to the GIB team $templateIdentifierOverlay = $this->templateService->getTemplateIdentifierOverlay('newDataSheetTeamNotification', $project); $dataSheetArray = $this->dataSheetService->getProcessedDataSheet($project); $this->notificationMailService->sendNotificationMail($templateIdentifierOverlay, $project, $projectManager, '', '', $dataSheetArray); } $this->persistenceManager->persistAll(); // redirect to dashboard $formRuntime = $this->finisherContext->getFormRuntime(); $request = $formRuntime->getRequest()->getMainRequest(); $uriBuilder = new \TYPO3\Flow\Mvc\Routing\UriBuilder(); $uriBuilder->setRequest($request); $uriBuilder->reset(); $uri = $uriBuilder->uriFor('editDatasheet', array('project' => $project), 'Project'); $response = $formRuntime->getResponse(); $mainResponse = $response; while ($response = $response->getParentResponse()) { $mainResponse = $response; } $mainResponse->setStatus(303); $mainResponse->setHeader('Location', (string) $uri); throw new \TYPO3\Flow\Mvc\Exception\StopActionException(); }