ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.shibUser.php
Go to the documentation of this file.
1 <?php
2 
20 
26 class shibUser extends ilObjUser
27 {
29 
35  public static function buildInstance(shibServerData $shibServerData): shibUser
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()) {
56  $this->setFirstname($this->shibServerData->getFirstname());
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()) {
71  $this->setDepartment($this->shibServerData->getDepartment());
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()) {
86  $this->setPhoneHome($this->shibServerData->getPhoneHome());
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());
117  $this->setExternalAccount($this->shibServerData->getLogin());
118  $this->setUTitle($this->shibServerData->getTitle());
119  $this->setInstitution($this->shibServerData->getInstitution());
120  $this->setDepartment($this->shibServerData->getDepartment());
121  $this->setStreet($this->shibServerData->getStreet());
122  $this->setZipcode($this->shibServerData->getZipcode());
123  $this->setCountry($this->shibServerData->getCountry());
124  $this->setPhoneOffice($this->shibServerData->getPhoneOffice());
125  $this->setPhoneHome($this->shibServerData->getPhoneHome());
126  $this->setPhoneMobile($this->shibServerData->getPhoneMobile());
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->setTimeLimitOwner(7);
135  $this->setTimeLimitUnlimited(1);
136  $this->setTimeLimitFrom(time());
137  $this->setTimeLimitUntil(time());
138  $this->setActive(true);
139  }
140 
144  #[\Override]
145  public function create(): int
146  {
148  $registration_settings = new ilRegistrationSettings();
149  $recipients = array_filter($registration_settings->getApproveRecipients(), static fn($v): bool => is_int($v));
150  if ($recipients !== [] && $c->isActivateNew()) {
151  $this->setActive(false);
152  $mail = new ilRegistrationMailNotification();
154  $mail->setRecipients($registration_settings->getApproveRecipients());
155  $mail->setAdditionalInformation(['usr' => $this]);
156  $mail->send();
157  }
158 
159  if ($this->getLogin() !== '' && $this->getLogin() !== '.') {
160  return parent::create();
161  }
162 
163  throw new ilUserException('No Login-name created');
164  }
165 
166  protected function returnNewLoginName(): ?string
167  {
168  $login = substr($this->cleanName($this->getFirstname()), 0, 1) . '.' . $this->cleanName($this->getLastname());
169  //remove whitespaces see mantis 0023123: https://www.ilias.de/mantis/view.php?id=23123
170  $login = preg_replace('/\s+/', '', $login);
171  $appendix = null;
172  $login_tmp = $login;
173  while ($this->loginExists($login, $this->getId())) {
174  $login = $login_tmp . $appendix;
175  $appendix++;
176  }
177 
178  return $login;
179  }
180 
181  public function isNew(): bool
182  {
183  return $this->getId() === 0;
184  }
185 
186  protected function cleanName(string $name): string
187  {
188  $umlaut_map = [
189  'ä' => 'ae', 'ö' => 'oe', 'ü' => 'ue',
190  'Ä' => 'Ae', 'Ö' => 'Oe', 'Ü' => 'Ue',
191  'ß' => 'ss'
192  ];
193  $name = strtr($name, $umlaut_map);
194 
195  $form_d = new UTFNormal();
196  $name = $form_d->formD()->transform($name);
197  $name = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', (string) $name);
198 
199  return strtolower((string) preg_replace('/[^a-zA-Z0-9\s]/', '', $name));
200  }
201 
202  private function loginExists(string $login, int $usr_id): bool
203  {
204  global $DIC;
205 
206  $db = $DIC->database();
207 
208  $query = 'SELECT usr_id FROM usr_data WHERE login = ' . $db->quote($login, 'text');
209  $query .= ' AND usr_id != ' . $db->quote($usr_id, 'integer');
210 
211  return $db->numRows($db->query($query)) > 0;
212  }
213 
214  protected static function getUsrIdByExtId(string $ext_id): ?int
215  {
216  global $DIC;
217 
218  $db = $DIC->database();
219 
220  $query = 'SELECT usr_id FROM usr_data WHERE ext_account = ' . $db->quote($ext_id, 'text');
221  $a_set = $db->query($query);
222  if ($db->numRows($a_set) === 0) {
223  return null;
224  }
225 
226  $usr = $db->fetchObject($a_set);
227 
228  return ($usr !== null && isset($usr->usr_id)) ? (int) $usr->usr_id : null;
229  }
230 }
setUTitle(string $a_str)
set user title (note: don&#39;t mix up this method with setTitle() that is derived from ilObject and sets...
setTimeLimitUnlimited(bool $a_unlimited)
numRows(ilDBStatement $statement)
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)
quote($value, string $type)
setTitle(string $title)
$c
Definition: deliver.php:25
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)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
ilDBInterface $db
global $DIC
Definition: shib_login.php:26
fetchObject(ilDBStatement $query_result)
query(string $query)
Run a (read-only) Query on the database.
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)