ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ILIAS\User\Profile\ProfileChangeMailTokenDBRepository Class Reference
+ Inheritance diagram for ILIAS\User\Profile\ProfileChangeMailTokenDBRepository:
+ Collaboration diagram for ILIAS\User\Profile\ProfileChangeMailTokenDBRepository:

Public Member Functions

 __construct (\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
 
ilDBInterface $db
 

Detailed Description

Definition at line 23 of file ProfileChangeMailTokenDBRepository.php.

Constructor & Destructor Documentation

◆ __construct()

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

Member Function Documentation

◆ deleteEntryByToken()

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

Implements ILIAS\User\Profile\ProfileChangeMailTokenRepository.

Definition at line 78 of file ProfileChangeMailTokenDBRepository.php.

References $query, and ilDBConstants\T_TEXT.

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

◆ deleteExpiredEntries()

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

Definition at line 84 of file ProfileChangeMailTokenDBRepository.php.

References $query, and ilDBConstants\T_INTEGER.

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

84  : void
85  {
86  $query = 'DELETE FROM `' . self::TABLE_NAME . '` WHERE `valid_until` <= %s';
87  $this->db->manipulateF($query, [\ilDBConstants::T_INTEGER], [time()]);
88  }
$query
+ 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 57 of file ProfileChangeMailTokenDBRepository.php.

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

57  : string
58  {
59  if (hash('md5', $user->getId() . '-' . $user->getEmail()) !== $received_token) {
60  return '';
61  }
62 
63  $query = $this->db->queryF(
64  'SELECT `new_email` FROM `' . self::TABLE_NAME . '` WHERE `token` = %s AND `valid_until` >= %s',
66  [$received_token, time()]
67  );
68 
69  $result = $this->db->fetchObject($query);
70 
71  if ($result !== null) {
72  return $result->new_email;
73  }
74 
75  return '';
76  }
$query
+ 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 36 of file ProfileChangeMailTokenDBRepository.php.

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

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

Field Documentation

◆ $db

ilDBInterface ILIAS\User\Profile\ProfileChangeMailTokenDBRepository::$db
private

◆ 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: