ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.shibUser.php
Go to the documentation of this file.
1<?php
2require_once('./Services/AuthShibboleth/classes/Config/class.shibConfig.php');
3require_once('./Services/User/classes/class.ilObjUser.php');
4
10class 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()) {
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()) {
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()) {
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());
107 $this->setTitle($this->shibServerData->getTitle());
110 $this->setStreet($this->shibServerData->getStreet());
111 $this->setZipcode($this->shibServerData->getZipcode());
112 $this->setCountry($this->shibServerData->getCountry());
114 $this->setPhoneHome($this->shibServerData->getPhoneHome());
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}
An exception for terminatinating execution or to throw for unit testing.
const IL_PASSWD_CRYPTED
setLanguage($a_str)
set user language @access public
setInstitution($a_str)
set institution @access public
setFirstname($a_str)
set firstname @access public
$login
all user related data in single vars @access public
setDepartment($a_str)
set department @access public
getLastname()
get lastname @access public
setExternalAccount($a_str)
set external account
setLogin($a_str)
set login / username @access public
setTimeLimitFrom($a_from)
getEmail()
get email address @access public
setCountry($a_str)
Set country (free text)
setPasswd($a_str, $a_type=IL_PASSWD_PLAIN)
set password @access public
setPhoneHome($a_str)
set home phone @access public
setFax($a_str)
set fax @access public
setTimeLimitUntil($a_until)
setTimeLimitOwner($a_owner)
getFirstname()
get firstname @access public
setZipcode($a_str)
set zipcode @access public
getLogin()
get login / username @access public
setLastname($a_str)
set lastame @access public
setStreet($a_str)
set street @access public
setActive($a_active, $a_owner=0)
set user active state and updates system fields appropriately @access public
setGender($a_str)
set gender @access public
setTimeLimitUnlimited($a_unlimited)
setEmail($a_str)
set email @access public
getFullname($a_max_strlen=0)
get fullname @access public
setMatriculation($a_str)
set matriculation number @access public
setHobby($a_str)
set hobby @access public
setPhoneOffice($a_str)
set office phone @access public
setPhoneMobile($a_str)
set mobile phone @access public
setTitle($a_title)
set object title
setDescription($a_desc)
set object description
getId()
get object id @access public
Class ilObjAuthSettingsGUI.
Class for user related exception handling in ILIAS.
static generatePasswords($a_number)
Generate a number of passwords.
static getInstance()
Class shibServerData.
Class shibUser.
static buildInstance(shibServerData $shibServerData)
static cleanName($name)
create()
create
if($format !==null) $name
Definition: metadata.php:146
$query
global $DIC
Definition: saml.php:7
global $ilDB