ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Token.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26
27class Token
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 Status $status = Status::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(): Status
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}
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
isTokenValidForCurrentStatus(\ilSetting $settings)
Definition: Token.php:70
getUriForStatus(URIBuilder $uri_builder)
Definition: Token.php:79
__construct(private readonly int $user_id, private readonly string $current_email, private readonly string $new_email, private readonly int $created_timestamp, private readonly Status $status=Status::Login, private ?string $token=null)
Definition: Token.php:29
ILIAS Setting Class.
build(string $namespace, ?ReferenceId $reference_id=null, array $additional_parameters=[])
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$token
Definition: xapitoken.php:70