ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.shibUser.php
Go to the documentation of this file.
1<?php
2
20
26class shibUser extends ilObjUser
27{
29
36 {
37 $shib_user = new self();
38 $shib_user->setLastPasswordChangeToNow();
39 $shib_user->shibServerData = $shibServerData;
40 $ext_id = $shib_user->shibServerData->getLogin();
41 $shib_user->setExternalAccount($ext_id);
42 $existing_usr_id = self::getUsrIdByExtId($ext_id);
43 if ($existing_usr_id !== null) {
44 $shib_user->setId($existing_usr_id);
45 $shib_user->read();
46 }
47 $shib_user->setAuthMode('shibboleth');
48
49 return $shib_user;
50 }
51
52 public function updateFields(): void
53 {
54 $shibConfig = shibConfig::getInstance();
55 if ($shibConfig->getUpdateFirstname()) {
57 }
58 if ($shibConfig->getUpdateLastname()) {
59 $this->setLastname($this->shibServerData->getLastname());
60 }
61 if ($shibConfig->getUpdateGender()) {
62 $this->setGender($this->shibServerData->getGender());
63 }
64 if ($shibConfig->getUpdateTitle()) {
65 $this->setUTitle($this->shibServerData->getTitle());
66 }
67 if ($shibConfig->getUpdateInstitution()) {
69 }
70 if ($shibConfig->getUpdateDepartment()) {
72 }
73 if ($shibConfig->getUpdateStreet()) {
74 $this->setStreet($this->shibServerData->getStreet());
75 }
76 if ($shibConfig->getUpdateZipcode()) {
77 $this->setZipcode($this->shibServerData->getZipcode());
78 }
79 if ($shibConfig->getUpdateCountry()) {
80 $this->setCountry($this->shibServerData->getCountry());
81 }
82 if ($shibConfig->getUpdatePhoneOffice()) {
84 }
85 if ($shibConfig->getUpdatePhoneHome()) {
87 }
88 if ($shibConfig->getUpdatePhoneMobile()) {
90 }
91 if ($shibConfig->getUpdateFax()) {
92 $this->setFax($this->shibServerData->getFax());
93 }
94 if ($shibConfig->getUpdateMatriculation()) {
96 }
97 if ($shibConfig->getUpdateEmail()) {
98 $this->setEmail($this->shibServerData->getEmail());
99 }
100 if ($shibConfig->getUpdateHobby()) {
101 $this->setHobby($this->shibServerData->getHobby());
102 }
103 if ($shibConfig->getUpdateLanguage()) {
104 $this->setLanguage($this->shibServerData->getLanguage());
105 }
106 $this->setDescription($this->getEmail());
107 }
108
109 public function createFields(): void
110 {
111 $this->setFirstname($this->shibServerData->getFirstname());
112 $this->setLastname($this->shibServerData->getLastname());
113 $this->setLogin($this->returnNewLoginName());
115 $this->setPasswd(md5((string) end($array)), ilObjUser::PASSWD_CRYPTED);
116 $this->setGender($this->shibServerData->getGender());
118 $this->setUTitle($this->shibServerData->getTitle());
121 $this->setStreet($this->shibServerData->getStreet());
122 $this->setZipcode($this->shibServerData->getZipcode());
123 $this->setCountry($this->shibServerData->getCountry());
125 $this->setPhoneHome($this->shibServerData->getPhoneHome());
127 $this->setFax($this->shibServerData->getFax());
129 $this->setEmail($this->shibServerData->getEmail());
130 $this->setHobby($this->shibServerData->getHobby());
131 $this->setTitle($this->getFullname());
132 $this->setDescription($this->getEmail());
133 $this->setLanguage($this->shibServerData->getLanguage());
134 $this->setTimeLimitUnlimited(true);
135 $this->setTimeLimitFrom(time());
136 $this->setTimeLimitUntil(time());
137 $this->setActive(true);
138 }
139
143 #[\Override]
144 public function create(): int
145 {
147 $registration_settings = new ilRegistrationSettings();
148 $recipients = array_filter($registration_settings->getApproveRecipients(), static fn($v): bool => is_int($v));
149 if ($recipients !== [] && $c->isActivateNew()) {
150 $this->setActive(false);
151 $mail = new ilRegistrationMailNotification();
153 $mail->setRecipients($registration_settings->getApproveRecipients());
154 $mail->setAdditionalInformation(['usr' => $this]);
155 $mail->send();
156 }
157
158 if ($this->getLogin() !== '' && $this->getLogin() !== '.') {
159 return parent::create();
160 }
161
162 throw new ilUserException('No Login-name created');
163 }
164
165 protected function returnNewLoginName(): ?string
166 {
167 $login = substr($this->cleanName($this->getFirstname()), 0, 1) . '.' . $this->cleanName($this->getLastname());
168 //remove whitespaces see mantis 0023123: https://www.ilias.de/mantis/view.php?id=23123
169 $login = preg_replace('/\s+/', '', $login);
170 $appendix = null;
171 $login_tmp = $login;
172 while ($this->loginExists($login, $this->getId())) {
173 $login = $login_tmp . $appendix;
174 $appendix++;
175 }
176
177 return $login;
178 }
179
180 public function isNew(): bool
181 {
182 return $this->getId() === 0;
183 }
184
185 protected function cleanName(string $name): string
186 {
187 $umlaut_map = [
188 'ä' => 'ae', 'ö' => 'oe', 'ü' => 'ue',
189 'Ä' => 'Ae', 'Ö' => 'Oe', 'Ü' => 'Ue',
190 'ß' => 'ss'
191 ];
192 $name = strtr($name, $umlaut_map);
193
194 $form_d = new UTFNormal();
195 $name = $form_d->formD()->transform($name);
196 $name = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', (string) $name);
197
198 return strtolower((string) preg_replace('/[^a-zA-Z0-9\s]/', '', $name));
199 }
200
201 private function loginExists(string $login, int $usr_id): bool
202 {
203 global $DIC;
204
205 $db = $DIC->database();
206
207 $query = 'SELECT usr_id FROM usr_data WHERE login = ' . $db->quote($login, 'text');
208 $query .= ' AND usr_id != ' . $db->quote($usr_id, 'integer');
209
210 return $db->numRows($db->query($query)) > 0;
211 }
212
213 protected static function getUsrIdByExtId(string $ext_id): ?int
214 {
215 global $DIC;
216
217 $db = $DIC->database();
218
219 $query = 'SELECT usr_id FROM usr_data WHERE ext_account = ' . $db->quote($ext_id, 'text');
220 $a_set = $db->query($query);
221 if ($db->numRows($a_set) === 0) {
222 return null;
223 }
224
225 $usr = $db->fetchObject($a_set);
226
227 return ($usr !== null && isset($usr->usr_id)) ? (int) $usr->usr_id : null;
228 }
229}
User class.
setGender(string $gender_string)
setPhoneMobile(string $phone)
setLanguage(string $language)
setLogin(string $login)
setStreet(string $street)
setEmail(string $email)
setTimeLimitUntil(?int $a_until)
setTimeLimitFrom(?int $a_from)
setPhoneHome(string $phone)
const PASSWD_CRYPTED
getFullname(int $max_strlen=0)
setHobby(string $hobby)
setFax(string $fax)
setMatriculation(string $matriculation)
setPasswd(string $a_str, string $a_type=ilObjUser::PASSWD_PLAIN)
setActive(bool $active, int $owner=0)
set user active state and updates system fields appropriately
setZipcode(string $zipcode)
setLastname(string $lastname)
setCountry(string $country)
setDepartment(string $department)
setPhoneOffice(string $phone)
setExternalAccount(string $a_str)
setTimeLimitUnlimited(bool $unlimited)
setLastPasswordChangeToNow()
setInstitution(string $instituion)
setFirstname(string $firstname)
setUTitle(string $user_title)
This sets the USER's title NOT the OBJECT's title!
setTitle(string $title)
setDescription(string $description)
ilDBInterface $db
Class ilObjAuthSettingsGUI.
static generatePasswords(int $a_number)
Generate a number of passwords.
static getInstance()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class shibUser.
static getUsrIdByExtId(string $ext_id)
loginExists(string $login, int $usr_id)
shibServerData $shibServerData
static buildInstance(shibServerData $shibServerData)
cleanName(string $name)
$c
Definition: deliver.php:25
fetchObject(ilDBStatement $query_result)
numRows(ilDBStatement $statement)
quote($value, string $type)
query(string $query)
Run a (read-only) Query on the database.
global $DIC
Definition: shib_login.php:26