/** * Init * * @return void */ public function initializeAction() { $this->databaseConnection = $GLOBALS['TYPO3_DB']; $this->controllerContext = $this->buildControllerContext(); $this->user = $this->div->getCurrentUser(); $this->cObj = $this->configurationManager->getContentObject(); $this->pluginVariables = $this->request->getArguments(); $this->allConfig = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK); $this->config = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT); $this->config = $this->config['plugin.']['tx_femanager.']['settings.']; $controllerName = strtolower($this->controllerContext->getRequest()->getControllerName()); $removeFromUserGroupSelection = $this->settings[$controllerName]['misc']['removeFromUserGroupSelection']; $this->allUserGroups = $this->userGroupRepository->findAllForFrontendSelection($removeFromUserGroupSelection); if (isset($this->arguments['user'])) { $this->arguments['user']->getPropertyMappingConfiguration()->forProperty('dateOfBirth')->setTypeConverterOption('TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\DateTimeConverter', DateTimeConverter::CONFIGURATION_DATE_FORMAT, LocalizationUtility::translate('tx_femanager_domain_model_user.dateFormat', 'femanager')); } // check if ts is included if ($this->settings['_TypoScriptIncluded'] != 1 && !GeneralUtility::_GP('eID') && TYPO3_MODE !== 'BE') { $this->addFlashMessage(LocalizationUtility::translate('error_no_typoscript', 'femanager'), '', FlashMessage::ERROR); } // check if storage pid was set if (intval($this->allConfig['persistence']['storagePid']) === 0 && !GeneralUtility::_GP('eID') && TYPO3_MODE !== 'BE') { $this->addFlashMessage(LocalizationUtility::translate('error_no_storagepid', 'femanager'), '', FlashMessage::ERROR); } }
/** * Generate Email Body * * @param string $template Template file in Templates/Email/ * @param array $variables Variables for assignMultiple * @return string */ protected function getMailBody($template, $variables) { /** @var \In2\Femanager\Utility\StandaloneViewMultiplePaths $emailBodyObject */ $emailBodyObject = $this->objectManager->get('In2\\Femanager\\Utility\\StandaloneViewMultiplePaths'); $emailBodyObject->getRequest()->setControllerExtensionName('Femanager'); $emailBodyObject->getRequest()->setPluginName('Pi1'); $emailBodyObject->getRequest()->setControllerName('New'); $emailBodyObject->setTemplatePathAndFilename($this->div->getTemplatePath('Email/' . ucfirst($template) . '.html')); $emailBodyObject->setLayoutRootPaths($this->div->getTemplateFolders('layout')); $emailBodyObject->setPartialRootPaths($this->div->getTemplateFolders('partial')); $emailBodyObject->assignMultiple($variables); return $emailBodyObject->render(); }
/** * @return boolean */ public function getIsOnline() { // check if last login was within 2h if (method_exists($this->getLastlogin(), 'getTimestamp') && $this->getLastlogin()->getTimestamp() > time() - 2 * 60 * 60 && \In2\Femanager\Utility\Div::checkFrontendSessionToUser($this)) { return TRUE; } return $this->isOnline; }
/** * action user logout * * @param User $user * @return void */ public function userLogoutAction(User $user) { Div::removeFrontendSessionToUser($user); $this->addFlashMessage('User successfully logged out'); $this->redirect('list'); }
/** * action user logout * * @param \In2\Femanager\Domain\Model\User $user * @return void */ public function userLogoutAction(\In2\Femanager\Domain\Model\User $user) { Div::removeFrontendSessionToUser($user); $this->flashMessageContainer->add('User successfully logged out'); $this->redirect('list'); }
/** * action delete * * @param int $user User UID * @param string $hash * @return void */ public function deleteAction($user, $hash = NULL) { $user = $this->userRepository->findByUid($user); if (Div::createHash($user->getUsername() . $user->getUid()) === $hash) { // write log $this->div->log(LocalizationUtility::translate('tx_femanager_domain_model_log.state.402', 'femanager'), 300, $user); // add flashmessage $this->addFlashMessage(LocalizationUtility::translate('tx_femanager_domain_model_log.state.402', 'femanager')); // send notify email to admin if ($this->settings['invitation']['notifyAdminStep1']) { $this->sendMail->send('invitationRefused', Div::makeEmailArray($this->settings['invitation']['notifyAdminStep1'], $this->settings['invitation']['email']['invitationRefused']['receiver']['name']['value']), Div::makeEmailArray($user->getEmail(), $user->getUsername()), 'Profile deleted from User after invitation - Step 1', array('user' => $user, 'settings' => $this->settings), $this->config['invitation.']['email.']['invitationRefused.']); } // delete user $this->userRepository->remove($user); $this->redirectByAction('invitation', 'redirectDelete'); $this->redirect('status'); } else { $this->addFlashMessage(LocalizationUtility::translate('tx_femanager_domain_model_log.state.403', 'femanager'), '', FlashMessage::ERROR); $this->redirect('status'); } }
/** * Validate Field * * @return bool */ public function validateField() { $validationSettings = GeneralUtility::trimExplode(',', $this->validationSettingsString, 1); $validationSettings = str_replace('|', ',', $validationSettings); foreach ($validationSettings as $validationSetting) { switch ($validationSetting) { case 'required': if (!$this->validateRequired($this->getValue())) { $this->addMessage('validationErrorRequired'); $this->isValid = FALSE; } break; case 'email': if ($this->getValue() && !$this->validateEmail($this->getValue())) { $this->addMessage('validationErrorEmail'); $this->isValid = FALSE; } break; case stristr($validationSetting, 'min('): if ($this->getValue() && !$this->validateMin($this->getValue(), Div::getValuesInBrackets($validationSetting))) { $this->addMessage('validationErrorMin'); $this->isValid = FALSE; } break; case stristr($validationSetting, 'max('): if ($this->getValue() && !$this->validateMax($this->getValue(), Div::getValuesInBrackets($validationSetting))) { $this->addMessage('validationErrorMax'); $this->isValid = FALSE; } break; case 'intOnly': if ($this->getValue() && !$this->validateInt($this->getValue())) { $this->addMessage('validationErrorInt'); $this->isValid = FALSE; } break; case 'lettersOnly': if ($this->getValue() && !$this->validateLetters($this->getValue())) { $this->addMessage('validationErrorLetters'); $this->isValid = FALSE; } break; case 'uniqueInPage': if ($this->getValue() && !$this->validateUniquePage($this->getValue(), $this->getFieldName(), $this->getUser())) { $this->addMessage('validationErrorUniquePage'); $this->isValid = FALSE; } break; case 'uniqueInDb': if ($this->getValue() && !$this->validateUniqueDb($this->getValue(), $this->getFieldName(), $this->getUser())) { $this->addMessage('validationErrorUniqueDb'); $this->isValid = FALSE; } break; case stristr($validationSetting, 'mustInclude('): if ($this->getValue() && !$this->validateMustInclude($this->getValue(), Div::getValuesInBrackets($validationSetting))) { $this->addMessage('validationErrorMustInclude'); $this->isValid = FALSE; } break; case stristr($validationSetting, 'mustNotInclude('): if ($this->getValue() && !$this->validateMustNotInclude($this->getValue(), Div::getValuesInBrackets($validationSetting))) { $this->addMessage('validationErrorMustNotInclude'); $this->isValid = FALSE; } break; case stristr($validationSetting, 'inList('): if (!$this->validateInList($this->getValue(), Div::getValuesInBrackets($validationSetting))) { $this->addMessage('validationErrorInList'); $this->isValid = FALSE; } break; case stristr($validationSetting, 'sameAs('): if (!$this->validateSameAs($this->getValue(), $this->getAdditionalValue())) { $this->addMessage('validationErrorSameAs'); $this->isValid = FALSE; } break; case 'date': if ($this->getValue() && !$this->validateDate($this->getValue(), LocalizationUtility::translate('tx_femanager_domain_model_user.dateFormat', 'femanager'))) { $this->addMessage('validationErrorDate'); $this->isValid = FALSE; } break; default: // e.g. search for method validateCustom() if (method_exists($this, 'validate' . ucfirst(Div::getValuesBeforeBrackets($validationSetting)))) { if (!$this->{'validate' . ucfirst(Div::getValuesBeforeBrackets($validationSetting))}($this->getValue(), Div::getValuesInBrackets($validationSetting))) { $this->addMessage('validationError' . ucfirst(Div::getValuesBeforeBrackets($validationSetting))); $this->isValid = FALSE; } } } } return $this->isValid; }
/** * Update if hash is ok * * @param \In2\Femanager\Domain\Model\User $user User object * @param \string $hash Given hash * @param \string $status "confirm", "refuse", "silentRefuse" * @return void */ public function confirmUpdateRequestAction(User $user, $hash, $status = 'confirm') { $this->view->assign('user', $user); // if wrong hash or if no update xml if (Div::createHash($user->getUsername() . $user->getUid()) !== $hash || !$user->getTxFemanagerChangerequest()) { $this->flashMessageContainer->add(LocalizationUtility::translate('updateFailedProfile', 'femanager'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR); return; } switch ($status) { case 'confirm': // overwrite properties $values = GeneralUtility::xml2array($user->getTxFemanagerChangerequest(), '', 0, 'changes'); foreach ((array) $values as $field => $value) { if ($field != 'usergroup' && method_exists($user, 'set' . ucfirst($field))) { $user->{'set' . ucfirst($field)}($value['new']); } else { $user->removeAllUsergroups(); $usergroupUids = GeneralUtility::trimExplode(',', $value['new'], 1); foreach ($usergroupUids as $usergroupUid) { $user->addUsergroup($this->userGroupRepository->findByUid($usergroupUid)); } } } $user = $this->div->forceValues($user, $this->config['edit.']['forceValues.']['onAdminConfirmation.'], $this->cObj); $this->div->log(LocalizationUtility::translate('tx_femanager_domain_model_log.state.202', 'femanager'), 202, $user); $this->flashMessageContainer->add(LocalizationUtility::translate('updateProfile', 'femanager')); break; case 'refuse': // send email to user $this->div->sendEmail('updateRequestRefused', Div::makeEmailArray($user->getEmail(), $user->getFirstName() . ' ' . $user->getLastName()), array('*****@*****.**' => 'Sender Name'), 'Your change request was refused', array('user' => $user, 'settings' => $this->settings), $this->config['edit.']['email.']['updateRequestRefused.']); $this->div->log(LocalizationUtility::translate('tx_femanager_domain_model_log.state.203', 'femanager'), 203, $user); $this->flashMessageContainer->add(LocalizationUtility::translate('tx_femanager_domain_model_log.state.203', 'femanager')); break; case 'silentRefuse': $this->div->log(LocalizationUtility::translate('tx_femanager_domain_model_log.state.203', 'femanager'), 203, $user); $this->flashMessageContainer->add(LocalizationUtility::translate('tx_femanager_domain_model_log.state.203', 'femanager')); break; default: } $user->setTxFemanagerChangerequest(''); $this->userRepository->update($user); $this->signalSlotDispatcher->dispatch(__CLASS__, __FUNCTION__ . 'AfterPersist', array($user, $hash, $status, $this)); }
/** * Update if hash is ok * * @param \int $user User UID * @param \string $hash Given hash * @param \string $status * "userConfirmation", "userConfirmationRefused", "adminConfirmation", * "adminConfirmationRefused", "adminConfirmationRefusedSilent" * @return void */ public function confirmCreateRequestAction($user, $hash, $status = 'adminConfirmation') { $user = $this->userRepository->findByUid($user); // if there is still no user in db if ($user === NULL) { $this->flashMessageContainer->add(LocalizationUtility::translate('missingUserInDatabase', 'femanager'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR); $this->redirect('new'); } switch ($status) { // registration confirmed by user case 'userConfirmation': if (Div::createHash($user->getUsername()) === $hash) { // if user is already confirmed by himself if ($user->getTxFemanagerConfirmedbyuser()) { $this->flashMessageContainer->add(LocalizationUtility::translate('userAlreadyConfirmed', 'femanager'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR); $this->redirect('new'); } $user = $this->div->forceValues($user, $this->config['new.']['forceValues.']['onUserConfirmation.'], $this->cObj); $user->setTxFemanagerConfirmedbyuser(TRUE); $this->userRepository->update($user); $this->persistenceManager->persistAll(); $this->div->log(LocalizationUtility::translate('tx_femanager_domain_model_log.state.102', 'femanager'), 102, $user); // must be still confirmed from admin if (!empty($this->settings['new']['confirmByAdmin']) && !$user->getTxFemanagerConfirmedbyadmin()) { // send email to admin to get this confirmation $this->div->sendEmail('createAdminConfirmation', Div::makeEmailArray($this->settings['new']['confirmByAdmin'], $this->settings['new']['email']['createAdminConfirmation']['receiver']['name']['value']), Div::makeEmailArray($user->getEmail(), $user->getUsername()), 'New Registration request', array('user' => $user, 'hash' => Div::createHash($user->getUsername() . $user->getUid())), $this->config['new.']['email.']['createAdminConfirmation.']); $this->flashMessageContainer->add(LocalizationUtility::translate('createRequestWaitingForAdminConfirm', 'femanager')); } else { $user->setDisable(FALSE); $this->flashMessageContainer->add(LocalizationUtility::translate('create', 'femanager')); $this->div->log(LocalizationUtility::translate('tx_femanager_domain_model_log.state.101', 'femanager'), 101, $user); $this->finalCreate($user, 'new', 'createStatus', TRUE, $status); } } else { $this->flashMessageContainer->add(LocalizationUtility::translate('createFailedProfile', 'femanager'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR); return; } break; case 'userConfirmationRefused': if (Div::createHash($user->getUsername()) === $hash) { $this->div->log(LocalizationUtility::translate('tx_femanager_domain_model_log.state.104', 'femanager'), 104, $user); $this->flashMessageContainer->add(LocalizationUtility::translate('createProfileDeleted', 'femanager')); $this->userRepository->remove($user); } else { $this->flashMessageContainer->add(LocalizationUtility::translate('createFailedProfile', 'femanager'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR); return; } break; case 'adminConfirmation': // registration complete if (Div::createHash($user->getUsername() . $user->getUid())) { $user = $this->div->forceValues($user, $this->config['new.']['forceValues.']['onAdminConfirmation.'], $this->cObj); $user->setTxFemanagerConfirmedbyadmin(TRUE); if ($user->getTxFemanagerConfirmedbyuser() || empty($this->settings['new']['confirmByUser'])) { $user->setDisable(FALSE); } $this->flashMessageContainer->add(LocalizationUtility::translate('create', 'femanager')); $this->div->log(LocalizationUtility::translate('tx_femanager_domain_model_log.state.103', 'femanager'), 103, $user); // send email to user to inform him about his profile confirmation $this->div->sendEmail('createUserNotify', Div::makeEmailArray($user->getEmail(), $user->getFirstName() . ' ' . $user->getLastName()), array('*****@*****.**' => 'Sender Name'), 'Your profile was confirmed', array('user' => $user), $this->config['new.']['email.']['createUserNotify.']); $this->finalCreate($user, 'new', 'createStatus', FALSE); } else { $this->flashMessageContainer->add(LocalizationUtility::translate('createFailedProfile', 'femanager'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR); return; } break; case 'adminConfirmationRefused': // Admin refuses profile // Admin refuses profile case 'adminConfirmationRefusedSilent': if (Div::createHash($user->getUsername() . $user->getUid())) { $this->div->log(LocalizationUtility::translate('tx_femanager_domain_model_log.state.105', 'femanager'), 105, $user); $this->flashMessageContainer->add(LocalizationUtility::translate('createProfileDeleted', 'femanager')); if (!stristr($status, 'silent')) { // send email to user to inform him about his profile confirmation $this->div->sendEmail('CreateUserNotifyRefused', Div::makeEmailArray($user->getEmail(), $user->getFirstName() . ' ' . $user->getLastName()), array('*****@*****.**' => 'Sender Name'), 'Your profile was refused', array('user' => $user), $this->config['new.']['email.']['createUserNotifyRefused.']); } $this->userRepository->remove($user); } else { $this->flashMessageContainer->add(LocalizationUtility::translate('createFailedProfile', 'femanager'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR); return; } break; default: } /** * redirect by TypoScript setting * [userConfirmation|userConfirmationRefused|adminConfirmation| * adminConfirmationRefused|adminConfirmationRefusedSilent]Redirect */ $this->redirectByAction('new', $status . 'Redirect'); $this->redirect('new'); }
/** * Test for getValuesBeforeBrackets() * * @param \string $start * @param \string $expectedResult * @return void * @dataProvider getValuesBeforeBracketsDataProvider * @test */ public function getValuesBeforeBracketsReturnsString($start, $expectedResult) { $result = \In2\Femanager\Utility\Div::getValuesBeforeBrackets($start); $this->assertEquals($result, $expectedResult); }
/** * getRandomStringAlwaysReturnsStringsOfGivenLength Test * * @param int $length * @param bool $addUpperCase * @param bool $addSpecialCharacters * @dataProvider getRandomStringAlwaysReturnsStringsOfGivenLengthDateProvider * @return void * @test */ public function getRandomStringAlwaysReturnsStringsOfGivenLength($length, $addUpperCase, $addSpecialCharacters) { for ($i = 0; $i < 100; $i++) { $string = \In2\Femanager\Utility\Div::getRandomString($length, $addUpperCase, $addSpecialCharacters); if ($addUpperCase) { $regex = '~[a-zA-Z0-9]{' . $length . '}~'; } else { $regex = '~[a-z0-9]{' . $length . '}~'; } $this->assertSame(1, preg_match($regex, $string)); } }