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