ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.shibUser.php
Go to the documentation of this file.
1 <?php
2 require_once('./Services/AuthShibboleth/classes/Config/class.shibConfig.php');
3 require_once('./Services/User/classes/class.ilObjUser.php');
4 
10 class shibUser extends ilObjUser
11 {
12 
16  protected $shibServerData;
17 
18 
25  {
26  $shibUser = new self();
27  $shibUser->shibServerData = $shibServerData;
28  $ext_id = $shibUser->shibServerData->getLogin();
29  $shibUser->setExternalAccount($ext_id);
30  $existing_usr_id = self::getUsrIdByExtId($ext_id);
31  if ($existing_usr_id) {
32  $shibUser->setId($existing_usr_id);
33  $shibUser->read();
34  }
35  $shibUser->setAuthMode('shibboleth');
36 
37  return $shibUser;
38  }
39 
40 
41  public function updateFields()
42  {
43  $shibConfig = shibConfig::getInstance();
44  if ($shibConfig->getUpdateFirstname()) {
45  $this->setFirstname($this->shibServerData->getFirstname());
46  }
47  if ($shibConfig->getUpdateLastname()) {
48  $this->setLastname($this->shibServerData->getLastname());
49  }
50  if ($shibConfig->getUpdateGender()) {
51  $this->setGender($this->shibServerData->getGender());
52  }
53  if ($shibConfig->getUpdateTitle()) {
54  $this->setTitle($this->shibServerData->getTitle());
55  }
56  if ($shibConfig->getUpdateInstitution()) {
58  }
59  if ($shibConfig->getUpdateDepartment()) {
60  $this->setDepartment($this->shibServerData->getDepartment());
61  }
62  if ($shibConfig->getUpdateStreet()) {
63  $this->setStreet($this->shibServerData->getStreet());
64  }
65  if ($shibConfig->getUpdateZipcode()) {
66  $this->setZipcode($this->shibServerData->getZipcode());
67  }
68  if ($shibConfig->getUpdateCountry()) {
69  $this->setCountry($this->shibServerData->getCountry());
70  }
71  if ($shibConfig->getUpdatePhoneOffice()) {
73  }
74  if ($shibConfig->getUpdatePhoneHome()) {
75  $this->setPhoneHome($this->shibServerData->getPhoneHome());
76  }
77  if ($shibConfig->getUpdatePhoneMobile()) {
79  }
80  if ($shibConfig->getUpdateFax()) {
81  $this->setFax($this->shibServerData->getFax());
82  }
83  if ($shibConfig->getUpdateMatriculation()) {
85  }
86  if ($shibConfig->getUpdateEmail()) {
87  $this->setEmail($this->shibServerData->getEmail());
88  }
89  if ($shibConfig->getUpdateHobby()) {
90  $this->setHobby($this->shibServerData->getHobby());
91  }
92  if ($shibConfig->getUpdateLanguage()) {
93  $this->setLanguage($this->shibServerData->getLanguage());
94  }
95  $this->setDescription($this->getEmail());
96  }
97 
98 
99  public function createFields()
100  {
101  $this->setFirstname($this->shibServerData->getFirstname());
102  $this->setLastname($this->shibServerData->getLastname());
103  $this->setLogin($this->returnNewLoginName());
105  $this->setGender($this->shibServerData->getGender());
106  $this->setExternalAccount($this->shibServerData->getLogin());
107  $this->setTitle($this->shibServerData->getTitle());
108  $this->setInstitution($this->shibServerData->getInstitution());
109  $this->setDepartment($this->shibServerData->getDepartment());
110  $this->setStreet($this->shibServerData->getStreet());
111  $this->setZipcode($this->shibServerData->getZipcode());
112  $this->setCountry($this->shibServerData->getCountry());
113  $this->setPhoneOffice($this->shibServerData->getPhoneOffice());
114  $this->setPhoneHome($this->shibServerData->getPhoneHome());
115  $this->setPhoneMobile($this->shibServerData->getPhoneMobile());
116  $this->setFax($this->shibServerData->getFax());
118  $this->setEmail($this->shibServerData->getEmail());
119  $this->setHobby($this->shibServerData->getHobby());
120  $this->setTitle($this->getFullname());
121  $this->setDescription($this->getEmail());
122  $this->setLanguage($this->shibServerData->getLanguage());
123  $this->setTimeLimitOwner(7);
124  $this->setTimeLimitUnlimited(1);
125  $this->setTimeLimitFrom(time());
126  $this->setTimeLimitUntil(time());
127  $this->setActive(true);
128  }
129 
130 
131  public function create()
132  {
134  if ($c->isActivateNew()) {
135  $this->setActive(false);
136  require_once('./Services/Registration/classes/class.ilRegistrationMailNotification.php');
137  require_once('./Services/Registration/classes/class.ilRegistrationSettings.php');
138  $ilRegistrationSettings = new ilRegistrationSettings();
139  $mail = new ilRegistrationMailNotification();
141  $mail->setRecipients($ilRegistrationSettings->getApproveRecipients());
142  $mail->setAdditionalInformation(array('usr' => $this));
143  $mail->send();
144  }
145 
146  if ($this->getLogin() != '' and $this->getLogin() != '.') {
147  parent::create();
148  } else {
149  throw new ilUserException('No Login-name created');
150  }
151  }
152 
153 
157  protected function returnNewLoginName()
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 
176  public function isNew()
177  {
178  return (bool) ($this->getId() == 0);
179  }
180 
181 
187  protected static function cleanName($name)
188  {
189  $name = strtolower(strtr(utf8_decode($name), utf8_decode('ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ'), 'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy'));
190 
191  return $name;
192  }
193 
194 
201  private static function loginExists($login, $usr_id)
202  {
203  global $DIC;
204  $ilDB = $DIC['ilDB'];
208  $query = 'SELECT usr_id FROM usr_data WHERE login = ' . $ilDB->quote($login, 'text');
209  $query .= ' AND usr_id != ' . $ilDB->quote($usr_id, 'integer');
210 
211  return (bool) ($ilDB->numRows($ilDB->query($query)) > 0);
212  }
213 
214 
220  protected static function getUsrIdByExtId($ext_id)
221  {
222  global $DIC;
223  $ilDB = $DIC['ilDB'];
227  $query = 'SELECT usr_id FROM usr_data WHERE ext_account = ' . $ilDB->quote($ext_id, 'text');
228  $a_set = $ilDB->query($query);
229  if ($ilDB->numRows($a_set) == 0) {
230  return false;
231  } else {
232  $usr = $ilDB->fetchObject($a_set);
233 
234  return $usr->usr_id;
235  }
236  }
237 }
static cleanName($name)
Class for user related exception handling in ILIAS.
setActive($a_active, $a_owner=0)
set user active state and updates system fields appropriately public
setInstitution($a_str)
set institution public
getLogin()
get login / username public
Class shibServerData.
setDepartment($a_str)
set department public
getFirstname()
get firstname public
global $DIC
Definition: saml.php:7
setLanguage($a_str)
set user language public
const IL_PASSWD_CRYPTED
$login
all user related data in single vars public
setTimeLimitOwner($a_owner)
static generatePasswords($a_number)
Generate a number of passwords.
setLastname($a_str)
set lastame public
static getInstance()
setCountry($a_str)
Set country (free text)
setPhoneHome($a_str)
set home phone public
setTimeLimitUnlimited($a_unlimited)
setTitle($a_title)
set object title
setZipcode($a_str)
set zipcode public
setEmail($a_str)
set email public
setPasswd($a_str, $a_type=IL_PASSWD_PLAIN)
set password public
setTimeLimitUntil($a_until)
setLogin($a_str)
set login / username public
getEmail()
get email address public
getLastname()
get lastname public
Class shibUser.
setExternalAccount($a_str)
set external account
getId()
get object id public
setHobby($a_str)
set hobby public
setMatriculation($a_str)
set matriculation number public
$query
static buildInstance(shibServerData $shibServerData)
setGender($a_str)
set gender public
setTimeLimitFrom($a_from)
setPhoneOffice($a_str)
set office phone public
getFullname($a_max_strlen=0)
get fullname public
setFirstname($a_str)
set firstname public
setFax($a_str)
set fax public
global $ilDB
setDescription($a_desc)
set object description
setStreet($a_str)
set street public
setPhoneMobile($a_str)
set mobile phone public