ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ILIAS\User\Profile\ChangeMailTokenDBRepository Class Reference
+ Inheritance diagram for ILIAS\User\Profile\ChangeMailTokenDBRepository:
+ Collaboration diagram for ILIAS\User\Profile\ChangeMailTokenDBRepository:

Public Member Functions

 __construct (private readonly \ilDBInterface $db, private readonly \ilSetting $settings)
 
 getNewTokenForUser (\ilObjUser $user, string $new_email, int $now)
 
 hasUserValidEmailConfirmationToken (\ilObjUser $user)
 
 getTokenForTokenString (string $token_string, \ilObjUser $user)
 This Function will check if the token is actually valid for the given user before returning the new email. More...
 
 moveToNextStep (ChangeMailToken $token, int $now)
 
 deleteEntryByToken (string $token)
 
 deleteExpiredEntries ()
 

Data Fields

const TABLE_NAME = 'usr_change_email_token'
 

Private Member Functions

 storeChangeMailToken (ChangeMailToken $token)
 

Detailed Description

Definition at line 23 of file ChangeMailTokenDBRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\User\Profile\ChangeMailTokenDBRepository::__construct ( private readonly \ilDBInterface  $db,
private readonly \ilSetting  $settings 
)

Definition at line 27 of file ChangeMailTokenDBRepository.php.

30  {
31  }

Member Function Documentation

◆ deleteEntryByToken()

ILIAS\User\Profile\ChangeMailTokenDBRepository::deleteEntryByToken ( string  $token)

Implements ILIAS\User\Profile\ChangeMailTokenRepository.

Definition at line 121 of file ChangeMailTokenDBRepository.php.

References ilDBConstants\T_TEXT.

Referenced by ILIAS\User\Profile\ChangeMailTokenDBRepository\moveToNextStep().

121  : void
122  {
123  $query = 'DELETE FROM `' . self::TABLE_NAME . '` WHERE `token` = %s';
124  $this->db->manipulateF($query, [\ilDBConstants::T_TEXT], [$token]);
125  }
$token
Definition: xapitoken.php:70
+ Here is the caller graph for this function:

◆ deleteExpiredEntries()

ILIAS\User\Profile\ChangeMailTokenDBRepository::deleteExpiredEntries ( )

Implements ILIAS\User\Profile\ChangeMailTokenRepository.

Definition at line 127 of file ChangeMailTokenDBRepository.php.

References ILIAS\Repository\settings(), and ilDBConstants\T_INTEGER.

127  : void
128  {
129  $validity = max(
130  ChangeMailStatus::Login->getValidity($this->settings),
131  ChangeMailStatus::EmailConfirmation->getValidity($this->settings)
132  );
133  $query = 'DELETE FROM `' . self::TABLE_NAME . '` WHERE `created_ts` < %s';
134  $this->db->manipulateF($query, [\ilDBConstants::T_INTEGER], [time() - $validity]);
135  }
+ Here is the call graph for this function:

◆ getNewTokenForUser()

ILIAS\User\Profile\ChangeMailTokenDBRepository::getNewTokenForUser ( \ilObjUser  $user,
string  $new_email,
int  $now 
)

Implements ILIAS\User\Profile\ChangeMailTokenRepository.

Definition at line 33 of file ChangeMailTokenDBRepository.php.

References $token, ilObjUser\getEmail(), ilObject\getId(), and ILIAS\User\Profile\ChangeMailTokenDBRepository\storeChangeMailToken().

37  : ChangeMailToken {
38  $token = new ChangeMailToken(
39  $user->getId(),
40  $user->getEmail(),
41  $new_email,
42  $now
43  );
44 
46  return $token;
47  }
$token
Definition: xapitoken.php:70
+ Here is the call graph for this function:

◆ getTokenForTokenString()

ILIAS\User\Profile\ChangeMailTokenDBRepository::getTokenForTokenString ( string  $token_string,
\ilObjUser  $user 
)

This Function will check if the token is actually valid for the given user before returning the new email.

Returns
string The new email a user wishes to be used or an empty string if validation failed or there is no usable entry.

Implements ILIAS\User\Profile\ChangeMailTokenRepository.

Definition at line 77 of file ChangeMailTokenDBRepository.php.

References $token, ILIAS\ResourceStorage\Flavour\Machine\DefaultMachines\from(), ilObjUser\getEmail(), ilObject\getId(), null, and ilDBConstants\T_TEXT.

77  : ?ChangeMailToken
78  {
79  $query = $this->db->queryF(
80  'SELECT * FROM `' . self::TABLE_NAME . '` WHERE `token` = %s',
82  [$token_string]
83  );
84 
85  $result = $this->db->fetchObject($query);
86 
87  if ($result === null) {
88  return null;
89  }
90 
91  $token = new ChangeMailToken(
92  $user->getId(),
93  $user->getEmail(),
94  $result->new_email,
95  $result->created_ts,
96  ChangeMailStatus::from($result->status),
97  $result->token
98  );
99 
100  if (!$token->isTokenValidForCurrentStatus($this->settings)) {
101  return null;
102  }
103 
104  return $token;
105  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$token
Definition: xapitoken.php:70
+ Here is the call graph for this function:

◆ hasUserValidEmailConfirmationToken()

ILIAS\User\Profile\ChangeMailTokenDBRepository::hasUserValidEmailConfirmationToken ( \ilObjUser  $user)

Implements ILIAS\User\Profile\ChangeMailTokenRepository.

Definition at line 49 of file ChangeMailTokenDBRepository.php.

References ilObject\getId(), ILIAS\Repository\settings(), and ilDBConstants\T_INTEGER.

49  : bool
50  {
51  $query = $this->db->queryF(
52  'SELECT count(*) as cnt FROM `' . self::TABLE_NAME . '`' . PHP_EOL
53  . 'WHERE `usr_id` = %s' . PHP_EOL
54  . 'AND `status` = %s' . PHP_EOL
55  . 'AND `created_ts` >= %s',
56  [
60  ],
61  [
62  $user->getId(),
63  ChangeMailStatus::EmailConfirmation->value,
64  time() - ChangeMailStatus::EmailConfirmation->getValidity($this->settings)
65  ]
66  );
67 
68  $result = $this->db->fetchObject($query);
69 
70  if ($result->cnt > 0) {
71  return true;
72  }
73 
74  return false;
75  }
+ Here is the call graph for this function:

◆ moveToNextStep()

ILIAS\User\Profile\ChangeMailTokenDBRepository::moveToNextStep ( ChangeMailToken  $token,
int  $now 
)

Implements ILIAS\User\Profile\ChangeMailTokenRepository.

Definition at line 107 of file ChangeMailTokenDBRepository.php.

References ILIAS\User\Profile\ChangeMailTokenDBRepository\deleteEntryByToken(), ILIAS\User\Profile\ChangeMailToken\getCurrentEmail(), ILIAS\User\Profile\ChangeMailToken\getNewEmail(), ILIAS\User\Profile\ChangeMailToken\getStatus(), ILIAS\User\Profile\ChangeMailToken\getToken(), ILIAS\User\Profile\ChangeMailToken\getUserId(), and ILIAS\User\Profile\ChangeMailTokenDBRepository\storeChangeMailToken().

107  : ChangeMailToken
108  {
109  $new_token = new ChangeMailToken(
110  $token->getUserId(),
111  $token->getCurrentEmail(),
112  $token->getNewEmail(),
113  $now,
114  $token->getStatus()->next()
115  );
116  $this->deleteEntryByToken($token->getToken());
117  $this->storeChangeMailToken($new_token);
118  return $new_token;
119  }
$token
Definition: xapitoken.php:70
+ Here is the call graph for this function:

◆ storeChangeMailToken()

ILIAS\User\Profile\ChangeMailTokenDBRepository::storeChangeMailToken ( ChangeMailToken  $token)
private

Definition at line 137 of file ChangeMailTokenDBRepository.php.

References ILIAS\User\Profile\ChangeMailToken\getCreatedTimestamp(), ILIAS\User\Profile\ChangeMailToken\getNewEmail(), ILIAS\User\Profile\ChangeMailToken\getStatus(), ILIAS\User\Profile\ChangeMailToken\getToken(), ILIAS\User\Profile\ChangeMailToken\getUserId(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

Referenced by ILIAS\User\Profile\ChangeMailTokenDBRepository\getNewTokenForUser(), and ILIAS\User\Profile\ChangeMailTokenDBRepository\moveToNextStep().

137  : void
138  {
139  $this->db->replace(
140  self::TABLE_NAME,
141  [
142  'token' => ['text', $token->getToken()]
143  ],
144  [
145  'usr_id' => [\ilDBConstants::T_TEXT, $token->getUserId()],
146  'new_email' => [\ilDBConstants::T_TEXT, $token->getNewEmail()],
147  'status' => [\ilDBConstants::T_INTEGER, $token->getStatus()->value],
148  'created_ts' => [\ilDBConstants::T_INTEGER, $token->getCreatedTimestamp()]
149  ]
150  );
151  }
$token
Definition: xapitoken.php:70
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ TABLE_NAME

const ILIAS\User\Profile\ChangeMailTokenDBRepository::TABLE_NAME = 'usr_change_email_token'

Definition at line 25 of file ChangeMailTokenDBRepository.php.


The documentation for this class was generated from the following file: