‪TYPO3CMS  10.4
FrontendUserRepository.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Doctrine\DBAL\FetchMode;
26 
31 {
35  protected ‪$connection;
36 
40  protected ‪$context;
41 
45  protected ‪$userService;
46 
47  public function ‪__construct(
50  ) {
51  $this->userService = ‪$userService;
52  $this->connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($this->‪getTable());
53  $this->context = ‪$context;
54  }
55 
56  public function ‪getTable(): string
57  {
58  return $this->userService->getFeUserTable();
59  }
60 
68  public function ‪updatePasswordAndInvalidateHash(string $forgotPasswordHash, string $hashedPassword): void
69  {
70  $queryBuilder = $this->connection->createQueryBuilder();
71 
72  $currentTimestamp = $this->context->getPropertyFromAspect('date', 'timestamp');
73  $query = $queryBuilder
74  ->update($this->‪getTable())
75  ->set('password', $hashedPassword)
76  ->set('felogin_forgotHash', $this->connection->quote(''), false)
77  ->set('tstamp', $currentTimestamp)
78  ->where(
79  $queryBuilder->expr()->eq('felogin_forgotHash', $queryBuilder->createNamedParameter($forgotPasswordHash))
80  )
81  ;
82  $query->execute();
83  }
84 
91  public function ‪existsUserWithHash(string $hash): bool
92  {
93  $queryBuilder = $this->connection->createQueryBuilder();
94 
95  $query = $queryBuilder
96  ->count('uid')
97  ->from($this->‪getTable())
98  ->where(
99  $queryBuilder->expr()->eq(
100  'felogin_forgotHash',
101  $queryBuilder->createNamedParameter($hash)
102  )
103  )
104  ;
105 
106  return (bool)$query->execute()->fetchColumn();
107  }
108 
115  public function ‪updateForgotHashForUserByEmail(string $emailAddress, string $hash): void
116  {
117  $queryBuilder = $this->connection->createQueryBuilder();
118  $query = $queryBuilder
119  ->update($this->‪getTable())
120  ->where(
121  $queryBuilder->expr()->eq(
122  'email',
123  $queryBuilder->createNamedParameter($emailAddress)
124  )
125  )
126  ->set('felogin_forgotHash', $hash)
127  ;
128  $query->execute();
129  }
130 
138  public function ‪fetchUserInformationByEmail(string $emailAddress): array
139  {
140  $queryBuilder = $this->connection->createQueryBuilder();
141 
142  $query = $queryBuilder
143  ->select('uid', 'username', 'email', 'first_name', 'middle_name', 'last_name')
144  ->from($this->‪getTable())
145  ->where(
146  $queryBuilder->expr()->eq(
147  'email',
148  $queryBuilder->createNamedParameter($emailAddress)
149  )
150  )
151  ;
152  $result = $query->execute()->fetch(FetchMode::ASSOCIATIVE);
153  if (!is_array($result)) {
154  $result = [];
155  }
156  return $result;
157  }
158 
164  public function ‪findEmailByUsernameOrEmailOnPages(string $usernameOrEmail, array $pages = []): ?string
165  {
166  if ($usernameOrEmail === '') {
167  return null;
168  }
169 
170  $queryBuilder = $this->connection->createQueryBuilder();
171  $query = $queryBuilder
172  ->select('email')
173  ->from($this->‪getTable())
174  ->where(
175  $queryBuilder->expr()->orX(
176  $queryBuilder->expr()->eq('username', $queryBuilder->createNamedParameter($usernameOrEmail)),
177  $queryBuilder->expr()->eq('email', $queryBuilder->createNamedParameter($usernameOrEmail))
178  )
179  )
180  ;
181 
182  if (!empty($pages)) {
183  // respect storage pid
184  $query->andWhere($queryBuilder->expr()->in('pid', $pages));
185  }
186 
187  $column = $query->execute()->fetchColumn();
188  return $column === false || $column === '' ? null : (string)$column;
189  }
190 
195  public function ‪findOneByForgotPasswordHash(string $hash): ?array
196  {
197  if ($hash === '') {
198  return null;
199  }
200 
201  $queryBuilder = $this->connection->createQueryBuilder();
202  $query = $queryBuilder
203  ->select('*')
204  ->from($this->‪getTable())
205  ->where(
206  $queryBuilder->expr()->eq(
207  'felogin_forgotHash',
208  $queryBuilder->createNamedParameter($hash)
209  )
210  )
211  ->setMaxResults(1)
212  ;
213 
214  $row = $query->execute()->fetch();
215  return is_array($row) ? $row : null;
216  }
217 
222  public function ‪findRedirectIdPageByUserId(int $uid): ?int
223  {
224  $queryBuilder = $this->connection->createQueryBuilder();
225  $queryBuilder->getRestrictions()->removeAll();
226  $query = $queryBuilder
227  ->select('felogin_redirectPid')
228  ->from($this->‪getTable())
229  ->where(
230  $queryBuilder->expr()->neq(
231  'felogin_redirectPid',
232  $this->connection->quote('')
233  ),
234  $queryBuilder->expr()->eq(
235  $this->userService->getFeUserIdColumn(),
236  $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
237  )
238  )
239  ->setMaxResults(1)
240  ;
241 
242  $column = $query->execute()->fetchColumn();
243  return $column === false ? null : (int)$column;
244  }
245 }
‪TYPO3\CMS\FrontendLogin\Domain\Repository\FrontendUserRepository\updatePasswordAndInvalidateHash
‪updatePasswordAndInvalidateHash(string $forgotPasswordHash, string $hashedPassword)
Definition: FrontendUserRepository.php:65
‪TYPO3\CMS\FrontendLogin\Domain\Repository\FrontendUserRepository\$connection
‪Connection $connection
Definition: FrontendUserRepository.php:34
‪TYPO3\CMS\FrontendLogin\Domain\Repository\FrontendUserRepository
Definition: FrontendUserRepository.php:31
‪TYPO3\CMS\FrontendLogin\Domain\Repository\FrontendUserRepository\__construct
‪__construct(UserService $userService, Context $context)
Definition: FrontendUserRepository.php:44
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\FrontendLogin\Domain\Repository\FrontendUserRepository\findEmailByUsernameOrEmailOnPages
‪string null findEmailByUsernameOrEmailOnPages(string $usernameOrEmail, array $pages=[])
Definition: FrontendUserRepository.php:161
‪TYPO3\CMS\FrontendLogin\Domain\Repository\FrontendUserRepository\fetchUserInformationByEmail
‪array fetchUserInformationByEmail(string $emailAddress)
Definition: FrontendUserRepository.php:135
‪TYPO3\CMS\FrontendLogin\Domain\Repository\FrontendUserRepository\updateForgotHashForUserByEmail
‪updateForgotHashForUserByEmail(string $emailAddress, string $hash)
Definition: FrontendUserRepository.php:112
‪TYPO3\CMS\FrontendLogin\Service\UserService
Definition: UserService.php:26
‪TYPO3\CMS\FrontendLogin\Domain\Repository\FrontendUserRepository\findOneByForgotPasswordHash
‪array null findOneByForgotPasswordHash(string $hash)
Definition: FrontendUserRepository.php:192
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:36
‪TYPO3\CMS\FrontendLogin\Domain\Repository\FrontendUserRepository\existsUserWithHash
‪bool existsUserWithHash(string $hash)
Definition: FrontendUserRepository.php:88
‪TYPO3\CMS\FrontendLogin\Domain\Repository\FrontendUserRepository\$context
‪Context $context
Definition: FrontendUserRepository.php:38
‪TYPO3\CMS\FrontendLogin\Domain\Repository\FrontendUserRepository\$userService
‪UserService $userService
Definition: FrontendUserRepository.php:42
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\FrontendLogin\Domain\Repository\FrontendUserRepository\getTable
‪getTable()
Definition: FrontendUserRepository.php:53
‪TYPO3\CMS\FrontendLogin\Domain\Repository\FrontendUserRepository\findRedirectIdPageByUserId
‪int null findRedirectIdPageByUserId(int $uid)
Definition: FrontendUserRepository.php:219
‪TYPO3\CMS\FrontendLogin\Domain\Repository
Definition: FrontendUserGroupRepository.php:18