ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ILIAS\User\Profile\ProfileChangeMailTokenDBRepository Class Reference
+ Inheritance diagram for ILIAS\User\Profile\ProfileChangeMailTokenDBRepository:
+ Collaboration diagram for ILIAS\User\Profile\ProfileChangeMailTokenDBRepository:

Public Member Functions

 __construct (private \ilDBInterface $db)
 
 getNewTokenForUser (\ilObjUser $user, string $new_email)
 
 getNewEmailForUser (\ilObjUser $user, string $received_token)
 This Function will check if the token is actually valid for the given user before returning the new email. More...
 
 deleteEntryByToken (string $token)
 

Private Member Functions

 deleteExpiredEntries ()
 

Private Attributes

const TABLE_NAME = 'usr_change_email_token'
 
const VALIDITY = 300
 

Detailed Description

Definition at line 23 of file ProfileChangeMailTokenDBRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\User\Profile\ProfileChangeMailTokenDBRepository::__construct ( private \ilDBInterface  $db)

Member Function Documentation

◆ deleteEntryByToken()

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

Implements ILIAS\User\Profile\ProfileChangeMailTokenRepository.

Definition at line 76 of file ProfileChangeMailTokenDBRepository.php.

References ilDBConstants\T_TEXT.

76  : void
77  {
78  $query = 'DELETE FROM `' . self::TABLE_NAME . '` WHERE `token` = %s';
79  $this->db->manipulateF($query, [\ilDBConstants::T_TEXT], [$token]);
80  }
$token
Definition: xapitoken.php:70

◆ deleteExpiredEntries()

ILIAS\User\Profile\ProfileChangeMailTokenDBRepository::deleteExpiredEntries ( )
private

Definition at line 82 of file ProfileChangeMailTokenDBRepository.php.

References ilDBConstants\T_INTEGER.

Referenced by ILIAS\User\Profile\ProfileChangeMailTokenDBRepository\__construct().

82  : void
83  {
84  $query = 'DELETE FROM `' . self::TABLE_NAME . '` WHERE `valid_until` <= %s';
85  $this->db->manipulateF($query, [\ilDBConstants::T_INTEGER], [time()]);
86  }
+ Here is the caller graph for this function:

◆ getNewEmailForUser()

ILIAS\User\Profile\ProfileChangeMailTokenDBRepository::getNewEmailForUser ( \ilObjUser  $user,
string  $token 
)

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\ProfileChangeMailTokenRepository.

Definition at line 55 of file ProfileChangeMailTokenDBRepository.php.

References ilObjUser\getEmail(), ilObject\getId(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

55  : string
56  {
57  if (hash('md5', $user->getId() . '-' . $user->getEmail()) !== $received_token) {
58  return '';
59  }
60 
61  $query = $this->db->queryF(
62  'SELECT `new_email` FROM `' . self::TABLE_NAME . '` WHERE `token` = %s AND `valid_until` >= %s',
64  [$received_token, time()]
65  );
66 
67  $result = $this->db->fetchObject($query);
68 
69  if ($result !== null) {
70  return $result->new_email;
71  }
72 
73  return '';
74  }
+ Here is the call graph for this function:

◆ getNewTokenForUser()

ILIAS\User\Profile\ProfileChangeMailTokenDBRepository::getNewTokenForUser ( \ilObjUser  $user,
string  $new_email 
)

Implements ILIAS\User\Profile\ProfileChangeMailTokenRepository.

Definition at line 34 of file ProfileChangeMailTokenDBRepository.php.

References $token, ilObjUser\getEmail(), ilObject\getId(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

34  : string
35  {
36  $token = hash('md5', $user->getId() . '-' . $user->getEmail());
37  $result = $this->db->replace(
38  self::TABLE_NAME,
39  [
40  'token' => ['text', $token]
41  ],
42  [
43  'new_email' => [\ilDBConstants::T_TEXT, $new_email],
44  'valid_until' => [\ilDBConstants::T_INTEGER, time() + self::VALIDITY]
45  ]
46  );
47 
48  if ($result === 1) {
49  return $token;
50  }
51 
52  return '';
53  }
$token
Definition: xapitoken.php:70
+ Here is the call graph for this function:

Field Documentation

◆ TABLE_NAME

const ILIAS\User\Profile\ProfileChangeMailTokenDBRepository::TABLE_NAME = 'usr_change_email_token'
private

Definition at line 25 of file ProfileChangeMailTokenDBRepository.php.

◆ VALIDITY

const ILIAS\User\Profile\ProfileChangeMailTokenDBRepository::VALIDITY = 300
private

Definition at line 26 of file ProfileChangeMailTokenDBRepository.php.


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