TYPO3  7.6
FrontendFormProtection.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\FormProtection;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
70 
75 {
82  protected $frontendUser;
83 
92  {
93  $this->frontendUser = $frontendUser;
94  $this->validationFailedCallback = $validationFailedCallback;
95  if (!$this->isAuthorizedFrontendSession()) {
96  throw new \TYPO3\CMS\Core\Error\Exception('A front-end form protection may only be instantiated if there is an active front-end session.', 1285067843);
97  }
98  }
99 
105  protected function retrieveSessionToken()
106  {
107  $this->sessionToken = $this->frontendUser->getSessionData('formProtectionSessionToken');
108  if (empty($this->sessionToken)) {
109  $this->sessionToken = $this->generateSessionToken();
110  $this->persistSessionToken();
111  }
112  return $this->sessionToken;
113  }
114 
122  public function persistSessionToken()
123  {
124  $this->frontendUser->setAndSaveSessionData('formProtectionSessionToken', $this->sessionToken);
125  }
126 
132  protected function isAuthorizedFrontendSession()
133  {
134  return !empty($this->frontendUser->user['uid']);
135  }
136 
137 }