ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ChangeMailToken.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\User\Profile;
22 
23 use ILIAS\Data\URI;
26 
28 {
29  public function __construct(
30  private readonly int $user_id,
31  private readonly string $current_email,
32  private readonly string $new_email,
33  private readonly int $created_timestamp,
34  private readonly ChangeMailStatus $status = ChangeMailStatus::Login,
35  private ?string $token = null
36  ) {
37  $this->token ??= $this->buildValidToken();
38  }
39 
40  public function getToken(): string
41  {
42  return $this->token;
43  }
44 
45  public function getUserId(): int
46  {
47  return $this->user_id;
48  }
49 
50  public function getCurrentEmail(): string
51  {
52  return $this->current_email;
53  }
54 
55  public function getNewEmail(): string
56  {
57  return $this->new_email;
58  }
59 
60  public function getCreatedTimestamp(): int
61  {
62  return $this->created_timestamp;
63  }
64 
65  public function getStatus(): ChangeMailStatus
66  {
67  return $this->status;
68  }
69 
70  public function isTokenValidForCurrentStatus(\ilSetting $settings): bool
71  {
72  if ($this->buildValidToken() === $this->token
73  && time() < $this->created_timestamp + $this->status->getValidity($settings)) {
74  return true;
75  }
76  return false;
77  }
78 
79  public function getUriForStatus(URIBuilder $uri_builder): URI
80  {
81  return $uri_builder->build(
83  null,
84  [StaticUrlHandler::CHANGE_EMAIL_OPERATIONS, $this->token]
85  );
86  }
87 
88  private function buildValidToken(): string
89  {
90  return hash('md5', "{$this->created_timestamp}-{$this->user_id}-{$this->current_email}-{$this->status->value}");
91  }
92 }
__construct(private readonly int $user_id, private readonly string $current_email, private readonly string $new_email, private readonly int $created_timestamp, private readonly ChangeMailStatus $status=ChangeMailStatus::Login, private ?string $token=null)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$token
Definition: xapitoken.php:70
build(string $namespace, ?ReferenceId $reference_id=null, array $additional_parameters=[])
isTokenValidForCurrentStatus(\ilSetting $settings)
getUriForStatus(URIBuilder $uri_builder)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...