ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilECSUser.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
29
31 private $source;
32
33 public string $login;
34 public string $email;
35 public string $firstname;
36 public string $lastname;
37 public string $institution;
38 public string $uid_hash;
39
40 protected string $external_account = '';
41 protected string $auth_mode = '';
42
43
47 public function __construct($a_data)
48 {
49 global $DIC;
50
51 $this->setting = $DIC->settings();
52
53 $this->source = $a_data;
54 if (is_object($a_data)) {
55 $this->loadFromObject();
56 } elseif (is_array($a_data)) {
57 $this->loadFromGET();
58 }
59 }
60
64 public function getLogin(): string
65 {
66 return $this->login;
67 }
68
69 public function getExternalAccount(): string
70 {
72 }
73
74
75
79 public function getFirstname(): string
80 {
81 return $this->firstname;
82 }
83
87 public function getLastname(): string
88 {
89 return $this->lastname;
90 }
91
95 public function getEmail(): string
96 {
97 return $this->email;
98 }
102 public function getInstitution(): string
103 {
104 return $this->institution;
105 }
106
110 public function getImportId(): string
111 {
112 return $this->uid_hash;
113 }
114
118 public function loadFromObject(): void
119 {
120 $this->login = $this->source->getLogin();
121 $this->firstname = $this->source->getFirstname();
122 $this->lastname = $this->source->getLastname();
123 $this->email = $this->source->getEmail();
124 $this->institution = $this->source->getInstitution();
125 if ($this->source instanceof ilObjUser) {
126 $this->external_account = $this->source->getExternalAccount();
127 $this->auth_mode = $this->source->getAuthMode();
128 }
129 $this->uid_hash = 'il_' . $this->setting->get('inst_id', "0") . '_usr_' . $this->source->getId();
130 }
131
135 public function loadFromGET(): void
136 {
137 //TODO add proper testing for get parameters
138 $this->login = ilUtil::stripSlashes(urldecode($this->source['ecs_login']));
139 $this->firstname = ilUtil::stripSlashes(urldecode($this->source['ecs_firstname']));
140 $this->lastname = ilUtil::stripSlashes(urldecode($this->source['ecs_lastname']));
141 $this->email = ilUtil::stripSlashes(urldecode($this->source['ecs_email']));
142 $this->institution = ilUtil::stripSlashes(urldecode($this->source['ecs_institution']));
143
144 if (isset($this->source['ecs_uid_hash'])) {
145 $this->uid_hash = ilUtil::stripSlashes(urldecode($this->source['ecs_uid_hash']));
146 } elseif (isset($this->source['ecs_uid'])) {
147 $this->uid_hash = ilUtil::stripSlashes(urldecode($this->source['ecs_uid']));
148 }
149 }
150
151 public function toJSON(): string
152 {
153 return urlencode(json_encode($this, JSON_THROW_ON_ERROR));
154 }
155
159 public function toGET(ilECSParticipantSetting $setting): string
160 {
161 $login = '';
162 $external_account_info = '';
163
164 // check for external auth mode
165 $external_auth_modes = $setting->getOutgoingExternalAuthModes();
166 if (in_array($this->auth_mode, $external_auth_modes)) {
167 $placeholder = $setting->getOutgoingUsernamePlaceholderByAuthMode($this->auth_mode);
168 if (stripos($placeholder, ilECSParticipantSetting::LOGIN_PLACEHOLDER) !== false) {
169 $login = str_replace(
171 $this->getLogin(),
172 $placeholder
173 );
174 }
175 if (stripos($placeholder, ilECSParticipantSetting::EXTERNAL_ACCOUNT_PLACEHOLDER) !== false) {
176 $login = str_replace(
178 $this->getExternalAccount(),
179 $placeholder
180 );
181 }
182 $external_account_info = '&ecs_external_account=1';
183 } else {
184 $login = $this->getLogin();
185 }
186 return '&ecs_login=' . urlencode((string) $login) .
187 '&ecs_firstname=' . urlencode($this->firstname) .
188 '&ecs_lastname=' . urlencode($this->lastname) .
189 '&ecs_email=' . urlencode($this->email) .
190 '&ecs_institution=' . urlencode($this->institution) .
191 '&ecs_uid_hash=' . urlencode($this->uid_hash) .
192 $external_account_info;
193 }
194
198 public function toREALM(): string
199 {
200 return
201 $this->login .
202 $this->firstname .
203 $this->lastname .
204 $this->email .
205 $this->institution .
207 }
208}
Stores relevant user data.
string $institution
string $lastname
string $auth_mode
loadFromObject()
load from object
getFirstname()
get firstname
getLastname()
getLastname
getLogin()
get login
ilSetting $setting
string $external_account
loadFromGET()
load user data from GET parameters
toGET(ilECSParticipantSetting $setting)
get GET parameter string
toREALM()
Concatenate all attributes to one string.
getImportId()
get Email
string $uid_hash
__construct($a_data)
getEmail()
get email
getInstitution()
get institution
string $firstname
User class.
ILIAS Setting Class.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
global $DIC
Definition: shib_login.php:26