ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.shibUser.php
Go to the documentation of this file.
1 <?php
23 class shibUser extends ilObjUser
24 {
26 
32  public static function buildInstance(shibServerData $shibServerData): shibUser
33  {
34  $shib_user = new self();
35  $shib_user->setLastPasswordChangeToNow();
36  $shib_user->shibServerData = $shibServerData;
37  $ext_id = $shib_user->shibServerData->getLogin();
38  $shib_user->setExternalAccount($ext_id);
39  $existing_usr_id = self::getUsrIdByExtId($ext_id);
40  if ($existing_usr_id !== null) {
41  $shib_user->setId($existing_usr_id);
42  $shib_user->read();
43  }
44  $shib_user->setAuthMode('shibboleth');
45 
46  return $shib_user;
47  }
48 
49  public function updateFields(): void
50  {
51  $shibConfig = shibConfig::getInstance();
52  if ($shibConfig->getUpdateFirstname()) {
53  $this->setFirstname($this->shibServerData->getFirstname());
54  }
55  if ($shibConfig->getUpdateLastname()) {
56  $this->setLastname($this->shibServerData->getLastname());
57  }
58  if ($shibConfig->getUpdateGender()) {
59  $this->setGender($this->shibServerData->getGender());
60  }
61  if ($shibConfig->getUpdateTitle()) {
62  $this->setUTitle($this->shibServerData->getTitle());
63  }
64  if ($shibConfig->getUpdateInstitution()) {
66  }
67  if ($shibConfig->getUpdateDepartment()) {
68  $this->setDepartment($this->shibServerData->getDepartment());
69  }
70  if ($shibConfig->getUpdateStreet()) {
71  $this->setStreet($this->shibServerData->getStreet());
72  }
73  if ($shibConfig->getUpdateZipcode()) {
74  $this->setZipcode($this->shibServerData->getZipcode());
75  }
76  if ($shibConfig->getUpdateCountry()) {
77  $this->setCountry($this->shibServerData->getCountry());
78  }
79  if ($shibConfig->getUpdatePhoneOffice()) {
81  }
82  if ($shibConfig->getUpdatePhoneHome()) {
83  $this->setPhoneHome($this->shibServerData->getPhoneHome());
84  }
85  if ($shibConfig->getUpdatePhoneMobile()) {
87  }
88  if ($shibConfig->getUpdateFax()) {
89  $this->setFax($this->shibServerData->getFax());
90  }
91  if ($shibConfig->getUpdateMatriculation()) {
93  }
94  if ($shibConfig->getUpdateEmail()) {
95  $this->setEmail($this->shibServerData->getEmail());
96  }
97  if ($shibConfig->getUpdateHobby()) {
98  $this->setHobby($this->shibServerData->getHobby());
99  }
100  if ($shibConfig->getUpdateLanguage()) {
101  $this->setLanguage($this->shibServerData->getLanguage());
102  }
103  $this->setDescription($this->getEmail());
104  }
105 
106  public function createFields(): void
107  {
108  $this->setFirstname($this->shibServerData->getFirstname());
109  $this->setLastname($this->shibServerData->getLastname());
110  $this->setLogin($this->returnNewLoginName());
112  $this->setPasswd(md5((string) end($array)), ilObjUser::PASSWD_CRYPTED);
113  $this->setGender($this->shibServerData->getGender());
114  $this->setExternalAccount($this->shibServerData->getLogin());
115  $this->setUTitle($this->shibServerData->getTitle());
116  $this->setInstitution($this->shibServerData->getInstitution());
117  $this->setDepartment($this->shibServerData->getDepartment());
118  $this->setStreet($this->shibServerData->getStreet());
119  $this->setZipcode($this->shibServerData->getZipcode());
120  $this->setCountry($this->shibServerData->getCountry());
121  $this->setPhoneOffice($this->shibServerData->getPhoneOffice());
122  $this->setPhoneHome($this->shibServerData->getPhoneHome());
123  $this->setPhoneMobile($this->shibServerData->getPhoneMobile());
124  $this->setFax($this->shibServerData->getFax());
126  $this->setEmail($this->shibServerData->getEmail());
127  $this->setHobby($this->shibServerData->getHobby());
128  $this->setTitle($this->getFullname());
129  $this->setDescription($this->getEmail());
130  $this->setLanguage($this->shibServerData->getLanguage());
131  $this->setTimeLimitOwner(7);
132  $this->setTimeLimitUnlimited(1);
133  $this->setTimeLimitFrom(time());
134  $this->setTimeLimitUntil(time());
135  $this->setActive(true);
136  }
137 
141  #[\Override]
142  public function create(): int
143  {
145  $registration_settings = new ilRegistrationSettings();
146  $recipients = array_filter($registration_settings->getApproveRecipients(), static fn($v): bool => is_int($v));
147  if ($recipients !== [] && $c->isActivateNew()) {
148  $this->setActive(false);
149  $mail = new ilRegistrationMailNotification();
151  $mail->setRecipients($registration_settings->getApproveRecipients());
152  $mail->setAdditionalInformation(['usr' => $this]);
153  $mail->send();
154  }
155 
156  if ($this->getLogin() !== '' && $this->getLogin() !== '.') {
157  return parent::create();
158  }
159 
160  throw new ilUserException('No Login-name created');
161  }
162 
163  protected function returnNewLoginName(): ?string
164  {
165  $login = substr($this->cleanName($this->getFirstname()), 0, 1) . '.' . $this->cleanName($this->getLastname());
166  //remove whitespaces see mantis 0023123: https://www.ilias.de/mantis/view.php?id=23123
167  $login = preg_replace('/\s+/', '', $login);
168  $appendix = null;
169  $login_tmp = $login;
170  while ($this->loginExists($login, $this->getId())) {
171  $login = $login_tmp . $appendix;
172  $appendix++;
173  }
174 
175  return $login;
176  }
177 
178  public function isNew(): bool
179  {
180  return $this->getId() === 0;
181  }
182 
183  protected function cleanName(string $name): string
184  {
185  return strtolower(
186  strtr(
187  $name,
188  'ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ',
189  'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy'
190  )
191  );
192  }
193 
194  private function loginExists(string $login, int $usr_id): bool
195  {
196  global $DIC;
197 
198  $db = $DIC->database();
199 
200  $query = 'SELECT usr_id FROM usr_data WHERE login = ' . $db->quote($login, 'text');
201  $query .= ' AND usr_id != ' . $db->quote($usr_id, 'integer');
202 
203  return $db->numRows($db->query($query)) > 0;
204  }
205 
206  protected static function getUsrIdByExtId(string $ext_id): ?int
207  {
208  global $DIC;
209 
210  $db = $DIC->database();
211 
212  $query = 'SELECT usr_id FROM usr_data WHERE ext_account = ' . $db->quote($ext_id, 'text');
213  $a_set = $db->query($query);
214  if ($db->numRows($a_set) === 0) {
215  return null;
216  }
217 
218  $usr = $db->fetchObject($a_set);
219 
220  return ($usr !== null && 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...
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
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setPhoneHome(string $a_str)
ilDBInterface $db
global $DIC
Definition: shib_login.php:22
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)