ILIAS  release_7 Revision v7.30-3-g800a261c036
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)
 
 getNewTokenForUser (\ilObjUser $user, string $new_email)
 
 getNewEmailForUser (\ilObjUser $user, string $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
 
 $db
 

Detailed Description

Definition at line 23 of file ProfileChangeMailTokenDBRepository.php.

Constructor & Destructor Documentation

◆ __construct()

Member Function Documentation

◆ deleteEntryByToken()

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

Implements ILIAS\User\Profile\ProfileChangeMailTokenRepository.

Definition at line 78 of file ProfileChangeMailTokenDBRepository.php.

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

References $query, $token, and ilDBConstants\T_TEXT.

◆ deleteExpiredEntries()

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

Definition at line 84 of file ProfileChangeMailTokenDBRepository.php.

84 : void
85 {
86 $query = 'DELETE FROM `' . self::TABLE_NAME . '` WHERE `valid_until` <= %s';
87 $this->db->manipulateF($query, [\ilDBConstants::T_INTEGER], [time()]);
88 }

References $query, and ilDBConstants\T_INTEGER.

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

+ 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.

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 }
$result

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

+ 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.

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 }

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

+ Here is the call graph for this function:

Field Documentation

◆ $db

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: