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