コード例 #1
0
ファイル: LoadData.php プロジェクト: zepi/turbo-base
 /**
  * Loads the data from the server
  * 
  * @access public
  * @param \Zepi\Turbo\Framework $framework
  * @param \Zepi\Turbo\Request\WebRequest $request
  * @param \Zepi\Turbo\Response\Response $response
  */
 public function execute(Framework $framework, WebRequest $request, Response $response)
 {
     // Verify the session
     if (!$request->hasSession() || $request->getRouteParam('token') == '') {
         $response->redirectTo('/');
         return;
     }
     $token = $request->getRouteParam('token');
     // Verify the datatable session data
     if (!$this->hasValidSessionData($request, $token)) {
         $response->redirectTo('/');
         return;
     }
     $class = $request->getSessionData('dt-class-' . $token);
     $time = $request->getSessionData('dt-time-' . $token);
     // Session time expired
     if ($time > time() + 600) {
         $response->redirectTo('/');
         return;
     }
     $table = new $class($framework, false);
     $generator = $this->getTableRenderer();
     $preparedTable = $generator->prepareTable($request, $table, '');
     $data = array('data' => array());
     foreach ($preparedTable->getBody()->getRows() as $row) {
         $data['data'][] = $row->toArray();
     }
     $response->setOutput(json_encode($data));
 }
コード例 #2
0
 /**
  * Authorizes the user with his username and password. Initializes
  * the user session if the user data are valid.
  * 
  * @access protected
  * @param \Zepi\Turbo\Framework $framework
  * @param \Zepi\Turbo\Request\RequestAbstract $request
  * @param \Zepi\Turbo\Response\Response $response
  * @return string|boolean
  */
 protected function generateNewPassword(Framework $framework, RequestAbstract $request, Response $response)
 {
     $uuid = $request->getRouteParam('uuid');
     $token = $request->getRouteParam('token');
     if ($uuid === false || !$this->userManager->hasUserForUuid($uuid) || $token === false) {
         $response->redirectTo('/');
         return;
     }
     // Load the user
     $user = $this->userManager->getUserForUuid($uuid);
     if ($user->getMetaData('passwordRequestToken') == '') {
         return array('result' => false, 'message' => $this->translate('You haven\'t requested a new password.', '\\Zepi\\Web\\AccessControl'));
     }
     // If the validate function returned a string there was an error in the validation.
     if ($user->getMetaData('passwordRequestToken') !== $token || $user->getMetaData('passwordRequestTokenLifetime') < time()) {
         return array('result' => false, 'message' => $this->translate('The given token is invalid or expired. Please request a new password.', '\\Zepi\\Web\\AccessControl'));
     }
     // Generate a new password
     $password = $this->generateRandomPassword();
     // Save the new password
     $user->setNewPassword($password);
     // Reset the token
     $user->setMetaData('passwordRequestToken', '');
     $user->setMetaData('passwordRequestTokenLifetime', 0);
     // Update the user
     $this->userManager->updateUser($user);
     // Send the request mail
     $this->mailHelper->sendMail($user->getMetaData('email'), $this->translate('New password generated', '\\Zepi\\Web\\AccessControl'), $this->render('\\Zepi\\Web\\AccessControl\\Mail\\GenerateNewPassword', array('user' => $user, 'password' => $password)));
     return array('result' => true, 'message' => $this->translate('Your new password is generated and saved. You will receive an email with the new password.', '\\Zepi\\Web\\AccessControl'));
 }
コード例 #3
0
 /**
  * If the request is a WebRequest, the user will be redirected to the login page.
  * Otherwise the event handler will display an information message.
  * 
  * @access public
  * @param \Zepi\Turbo\Framework $framework
  * @param \Zepi\Turbo\Request\RequestAbstract $request
  * @param \Zepi\Turbo\Response\Response $response
  */
 public function execute(Framework $framework, RequestAbstract $request, Response $response)
 {
     if ($request instanceof WebRequest) {
         $response->redirectTo('/login/', 307, true);
         return;
     }
     $response->setOutputPart('sessionNeeded', 'You need a session to execute this command!');
 }
コード例 #4
0
ファイル: Administration.php プロジェクト: zepi/turbo-base
 /**
  * Displays the administration overview page
  * 
  * @access public
  * @param \Zepi\Turbo\Framework $framework
  * @param \Zepi\Turbo\Request\WebRequest $request
  * @param \Zepi\Turbo\Response\Response $response
  */
 public function execute(Framework $framework, WebRequest $request, Response $response)
 {
     // Redirect if the user hasn't a valid session
     if (!$request->hasSession()) {
         $response->redirectTo('/');
         return;
     }
     // Prepare the page
     $this->setTitle($this->translate('Administration', '\\Zepi\\Web\\General'));
     $menuEntry = $this->activateMenuEntry();
     // Generate the overview page
     $overviewPage = $this->getOverviewPageRenderer()->render($framework, $menuEntry);
     // Display the overview page
     $response->setOutput($this->render('\\Zepi\\Web\\General\\Templates\\Administration', array('overviewPage' => $overviewPage)));
 }
コード例 #5
0
ファイル: VerifyEventName.php プロジェクト: zepi/turbo-base
 /**
  * Replaces the event name with a redirect event if the url 
  * hasn't a slash at the end of the url.
  * 
  * @access public
  * @param \Zepi\Turbo\Framework $framework
  * @param \Zepi\Turbo\Request\RequestAbstract $request
  * @param \Zepi\Turbo\Response\Response $response
  * @param mixed $value
  * @return mixed
  */
 public function execute(Framework $framework, RequestAbstract $request, Response $response, $value = null)
 {
     if (!$request instanceof WebRequest) {
         return $value;
     }
     $fullUrl = $request->getRequestedUrl();
     $urlParts = parse_url($fullUrl);
     if ($urlParts == false) {
         return $value;
     }
     $urlParts = $this->verifyPath($urlParts);
     $completeUrl = $response->buildUrl($urlParts);
     if ($completeUrl !== $request->getRequestedUrl()) {
         $response->redirectTo($completeUrl);
         return null;
     }
     return $value;
 }
コード例 #6
0
ファイル: SessionManager.php プロジェクト: zepi/turbo-base
 /**
  * Initializes the session
  * 
  * @access public
  * @param \Zepi\Turbo\Request\WebRequest $request
  * @param \Zepi\Turbo\Response\Response $response
  */
 public function reinitializeSession(Framework $framework, WebRequest $request, Response $response)
 {
     // Sets the correct name:
     session_name('ZTSM');
     // Start the session
     session_start();
     // If the session wasn't started before, we start it now...
     if ($request->getSessionData('sessionStarted') === false) {
         $this->startSession($request);
     }
     // Validate the session data
     $valid = $this->validateSessionData($request);
     // If the session not is valid we redirect to the start of everything
     if (!$valid) {
         $response->redirectTo('');
     }
     // There is a 1% chance that we regenerate the session
     if (mt_rand(1, 100) <= 1) {
         $this->regenerateSession($request);
     }
     // Initialize the user session
     if ($request->getSessionData('userUuid') !== false) {
         $this->reinitializeUserSession($framework, $request, $response);
     }
 }
コード例 #7
0
ファイル: DeleteUser.php プロジェクト: zepi/turbo-base
 /**
  * Displays the edit user form and saves the data to the database.
  * 
  * @access public
  * @param \Zepi\Turbo\Framework $framework
  * @param \Zepi\Turbo\Request\WebRequest $request
  * @param \Zepi\Turbo\Response\Response $response
  */
 public function execute(Framework $framework, WebRequest $request, Response $response)
 {
     // Prepare the page
     $additionalTitle = $this->translate('Delete user', '\\Zepi\\Web\\AccessControl');
     $title = $this->translate('User management', '\\Zepi\\Web\\AccessControl') . ' - ' . $additionalTitle;
     $this->setTitle($title, $additionalTitle);
     $this->activateMenuEntry('user-administration');
     // Get the user
     $uuid = $request->getRouteParam('uuid');
     // If the UUID does not exists redirect to the overview page
     if (!is_string($uuid) || !$this->userManager->hasUserForUuid($uuid)) {
         $response->redirectTo($request->getFullRoute('/administration/users/'));
         return;
     }
     $user = $this->userManager->getUserForUuid($uuid);
     // If $result isn't true, display the edit user form
     if ($request->getRouteParam('confirmation') === 'confirmed') {
         $this->userManager->deleteUser($user);
         $response->setOutput($this->render('\\Zepi\\Web\\AccessControl\\Templates\\Administration\\DeleteUserFinished', array('user' => $user)));
     } else {
         // Display the delete user confirmation
         $response->setOutput($this->render('\\Zepi\\Web\\AccessControl\\Templates\\Administration\\DeleteUser', array('user' => $user)));
     }
 }
コード例 #8
0
ファイル: Login.php プロジェクト: zepi/turbo-base
 /**
  * Filters the given menu entries and removes all protected menu
  * entries for which the sender hasn't the correct permission.
  * 
  * @access public
  * @param \Zepi\Turbo\Framework $framework
  * @param \Zepi\Turbo\Request\WebRequest $request
  * @param \Zepi\Turbo\Response\Response $response
  */
 public function execute(Framework $framework, WebRequest $request, Response $response)
 {
     // Redirect if the user already has a valid session
     if ($request->hasSession()) {
         $response->redirectTo('/', 307);
         return;
     }
     // Set the title for the page
     $this->setTitle($this->translate('Login', '\\Zepi\\Web\\AccessControl'));
     // Get the form object
     $loginForm = $this->createForm($framework, $request, $response);
     // Process the submitted form data
     $loginForm->processFormData($request);
     // Validate the form data and authorize the user
     $result = false;
     $errors = array();
     if ($loginForm->isSubmitted()) {
         $errors = $loginForm->validateFormData($framework);
         if (count($errors) === 0) {
             $result = $this->authorizeUser($loginForm, $framework, $request, $response);
         }
     }
     // Fill the errors into the error box
     $errorBox = $loginForm->getPart('login-errors');
     $errorBox->updateErrorBox($loginForm, $result, $errors);
     // If $result isn't true, display the login form
     if (!$loginForm->isSubmitted() || $errorBox->hasErrors()) {
         $renderedOutput = $this->render('\\Zepi\\Web\\AccessControl\\Templates\\LoginForm', array('result' => $result, 'errors' => $errors, 'form' => $loginForm, 'layoutRenderer' => $this->getLayoutRenderer(), 'allowRegistration' => $this->getSetting('accesscontrol.allowRegistration'), 'allowRenewPassword' => $this->getSetting('accesscontrol.allowRenewPassword')));
         $response->setOutput($renderedOutput);
     }
 }