/** * @param Request $request * @return PartialHtmlResponse */ public function run(Request $request) { $userSession = $this->serviceContainer->getUserSession(); $userSession->logout(); $urlBuilder = $this->serviceContainer->getUrlBuilder(); return new HttpRedirectResponse($urlBuilder->createActionUrl('login')); }
/** * @param Request $request * @return PartialHtmlResponse */ public function run(Request $request) { $addUrl = $this->serviceContainer->getTemplateBuilder()->createTemplate(); $url = $this->serviceContainer->getUrlBuilder()->createActionUrl('createUrl'); $csrfHandler = $this->serviceContainer->getCsrfHandler()->createNewToken(); $list_urls_link = $this->serviceContainer->getUrlBuilder()->createActionUrl('listUrls'); $addUrl->loadFile('addUrl.html')->addPlaceHolder('form_action', $url)->addPlaceHolder('list_urls_link', $list_urls_link)->addCsrfToken($csrfHandler); return new PartialHtmlResponse($addUrl->render()); }
/** * @param Request $request * @return PartialHtmlResponse */ public function run(Request $request) { $urlQuery = $this->serviceContainer->getUrlQuery(); $urlBuilder = $this->serviceContainer->getUrlBuilder(); $userSession = $this->serviceContainer->getUserSession(); $csrfHandler = $this->serviceContainer->getCsrfHandler(); if ($csrfHandler->requestIsValid($request) == false) { return new CompleteHtmlResponse($csrfHandler->getErrorMessage()); } $user_id = $userSession->getUserId(); $urlQuery->emptyTrashByUserId($user_id); return new HttpRedirectResponse($urlBuilder->createActionUrl('listUrls')); }
/** * @param Request $request * @return PartialHtmlResponse */ public function run(Request $request) { $now = $this->serviceContainer->getCurrentDate(); $userSession = $this->serviceContainer->getUserSession(); $urlBuilder = $this->serviceContainer->getUrlBuilder(); $formMapper = $this->serviceContainer->getUrlFormMapper(); $csrfHandler = $this->serviceContainer->getCsrfHandler(); if ($csrfHandler->requestIsValid($request) == false) { return new CompleteHtmlResponse($csrfHandler->getErrorMessage()); } $urlDataObject = $formMapper->mapToDataObject($request, $userSession->getUserId()); $formMapper->initValues($urlDataObject, $now); $this->addUrlToDb($urlDataObject); return new HttpRedirectResponse($urlBuilder->createActionUrl('listUrls')); }
/** * @param Request $request * @return PartialHtmlResponse */ public function run(Request $request) { $urlBuilder = $this->serviceContainer->getUrlBuilder(); $editUrl = $this->serviceContainer->getTemplateBuilder()->createTemplate(); $userUrlLoader = $this->serviceContainer->getUserUrlLoader(); $csrfHandler = $this->serviceContainer->getCsrfHandler()->createNewToken(); $url = $userUrlLoader->loadUrl($request->getGetVal('id')); if ($url == null) { return new PartialHtmlResponse('Sorry, you are not allowed to edit this url.'); } $update_action_url = $urlBuilder->createActionUrl('updateUrl', $request->getGetVal('id')); $trash_link = $urlBuilder->createActionUrl('trashUrl', $url->getId(), $csrfHandler->getCurrentToken()); $editUrl->loadFile('editUrl.html')->addPlaceHolder('form_action', $update_action_url)->addPlaceHolder('url', $url->getUrl())->addPlaceHolder('title', $url->getTitle())->addPlaceHolder('description', $url->getDescription())->addPlaceHolder('trash_link', $trash_link)->addPlaceHolder('list_urls_link', $urlBuilder->createActionUrl('listUrls'))->addCsrfToken($csrfHandler); return new PartialHtmlResponse($editUrl->render()); }
/** * @param Request $request * @return PartialHtmlResponse */ public function run(Request $request) { $userSession = $this->serviceContainer->getUserSession(); $urlBuilder = $this->serviceContainer->getUrlBuilder(); $csrfHandler = $this->serviceContainer->getCsrfHandler()->createNewToken(); if ($userSession->userIsLoggedIn()) { return new HttpRedirectResponse($urlBuilder->createActionUrl('listUrls')); } $templateBuilder = $this->serviceContainer->getTemplateBuilder(); $urlBuilder = $this->serviceContainer->getUrlBuilder(); $actionUrl = $urlBuilder->createActionUrl('performLogin'); $loginForm = $templateBuilder->createTemplate(); $loginForm->loadFile('loginForm.html')->addPlaceHolder('form_action', $actionUrl)->addCsrfToken($csrfHandler); return new PartialHtmlResponse($loginForm->render()); }
/** * @param int $user_id * @return string */ private function renderUrlListEntriesForUser($user_id) { $urlBuilder = $this->serviceContainer->getUrlBuilder(); $urlListEntryBuilder = $this->serviceContainer->getUrlListEntryBuilder(); $rendered = ''; $urls = $this->getUrlsByUserId($user_id); if (empty($urls)) { $rendered = '<p>No URLs here.</p>'; } foreach ($urls as $url) { $edit_link = $urlBuilder->createActionUrl('editUrl', $url->getId()); $urlListEntry = $urlListEntryBuilder->buildUrlListEntry($url, $edit_link); $rendered .= $urlListEntry->render(); } return $rendered; }
/** * @param int $user_id * @return string */ private function renderTrashedEntriesForUser($user_id) { $urlBuilder = $this->serviceContainer->getUrlBuilder(); $urlListEntryBuilder = $this->serviceContainer->getUrlListEntryBuilder(); $csrfHandler = $this->serviceContainer->getCsrfHandler(); $rendered = ''; $urls = $this->getTrashedUrlsByUserId($user_id); foreach ($urls as $url) { $untrash_link = $urlBuilder->createActionUrl('unTrashUrl', $url->getId(), $csrfHandler->getCurrentToken()); $urlListEntry = $urlListEntryBuilder->buildUrlListEntry($url, $untrash_link); $rendered .= $urlListEntry->render(); } if (empty($urls)) { $rendered = '<p>No trashed items.</p>'; } return $rendered; }
/** * @param Request $request * @return PartialHtmlResponse */ public function run(Request $request) { $userName = $request->getPostVal('user'); $password = $request->getPostVal('password'); $urlBuilder = $this->serviceContainer->getUrlBuilder(); $passwordVerifier = $this->serviceContainer->getPasswordVerifier(); $userSession = $this->serviceContainer->getUserSession(); $csrfHandler = $this->serviceContainer->getCsrfHandler(); if ($csrfHandler->requestIsValid($request) == false) { return new CompleteHtmlResponse($csrfHandler->getErrorMessage()); } $user = $this->getUserByName($userName); if ($user == null) { return new HttpRedirectResponse($urlBuilder->createActionUrl('login')); } if ($passwordVerifier->verifyUserPassword($user, $password)) { $userSession->loginAs($user->getId(), $user->getName()); } else { return new HttpRedirectResponse($urlBuilder->createActionUrl('login')); } return new HttpRedirectResponse($urlBuilder->createActionUrl('listUrls')); }
/** * Does not feel right yet... * @param Request $request */ private function redirectToLoginIfNotLoggedIn(Request $request) { $userSession = $this->serviceContainer->getUserSession(); if ($userSession->userIsLoggedIn()) { return; } $actionName = $request->getGetVal('action'); if ($actionName == 'login' || $actionName == 'performLogin') { return; } $loginUrl = $this->serviceContainer->getUrlBuilder()->createActionUrl('login'); $redirectResponse = new HttpRedirectResponse($loginUrl); // Maybe just make a redirect method which always exits $this->handleResponse($redirectResponse); exit; }