ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
15 protected $shibServerData;
16
17
24 public static function getInstance(shibServerData $shibServerData) {
26 }
27
28
35 $shibUser = new self();
36 $shibUser->shibServerData = $shibServerData;
37 $ext_id = $shibUser->shibServerData->getLogin();
38 $shibUser->setExternalAccount($ext_id);
39 $existing_usr_id = self::getUsrIdByExtId($ext_id);
40 if ($existing_usr_id) {
41 $shibUser->setId($existing_usr_id);
42 $shibUser->read();
43 }
44 $shibUser->setAuthMode('shibboleth');
45
46 return $shibUser;
47 }
48
49
50 public function updateFields() {
51 $shibConfig = shibConfig::getInstance();
52 if ($shibConfig->getUpdateFirstname()) {
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->setTitle($this->shibServerData->getTitle());
63 }
64 if ($shibConfig->getUpdateInstitution()) {
66 }
67 if ($shibConfig->getUpdateDepartment()) {
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()) {
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
107 public function createFields() {
108 $this->setFirstname($this->shibServerData->getFirstname());
109 $this->setLastname($this->shibServerData->getLastname());
110 $this->setLogin($this->returnNewLoginName());
112 $this->setGender($this->shibServerData->getGender());
114 $this->setTitle($this->shibServerData->getTitle());
117 $this->setStreet($this->shibServerData->getStreet());
118 $this->setZipcode($this->shibServerData->getZipcode());
119 $this->setCountry($this->shibServerData->getCountry());
121 $this->setPhoneHome($this->shibServerData->getPhoneHome());
123 $this->setFax($this->shibServerData->getFax());
125 $this->setEmail($this->shibServerData->getEmail());
126 $this->setHobby($this->shibServerData->getHobby());
127 $this->setTitle($this->getFullname());
128 $this->setDescription($this->getEmail());
129 $this->setLanguage($this->shibServerData->getLanguage());
130 $this->setTimeLimitOwner(7);
131 $this->setTimeLimitUnlimited(1);
132 $this->setTimeLimitFrom(time());
133 $this->setTimeLimitUntil(time());
134 $this->setActive(true);
135 }
136
137
138 public function create() {
139 if ($this->getLogin() != '' AND $this->getLogin() != '.') {
140 parent::create();
141 } else {
142 throw new ilUserException('No Login-name created');
143 }
144 }
145
146
150 protected function returnNewLoginName() {
151 $login = substr(self::cleanName($this->getFirstname()), 0, 1) . '.' . self::cleanName($this->getLastname());
152 $appendix = NULL;
153 $login_tmp = $login;
154 while (self::loginExists($login, $this->getId())) {
155 $login = $login_tmp . $appendix;
156 $appendix ++;
157 }
158
159 return $login;
160 }
161
162
166 public function isNew() {
167 return (bool)($this->getId() == 0);
168 }
169
170
176 protected static function cleanName($name) {
177 $name = strtolower(strtr(utf8_decode($name), utf8_decode('ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ'), 'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy'));
178
179 return $name;
180 }
181
182
183
190 private static function loginExists($login, $usr_id) {
191 global $ilDB;
195 $query = 'SELECT usr_id FROM usr_data WHERE login = ' . $ilDB->quote($login, 'text');
196 $query .= ' AND usr_id != ' . $ilDB->quote($usr_id, 'integer');
197
198 return (bool)($ilDB->numRows($ilDB->query($query)) > 0);
199 }
200
201
207 protected static function getUsrIdByExtId($ext_id) {
208 global $ilDB;
212 $query = 'SELECT usr_id FROM usr_data WHERE ext_account = ' . $ilDB->quote($ext_id, 'text');
213 $a_set = $ilDB->query($query);
214 if ($ilDB->numRows($a_set) == 0) {
215 return false;
216 } else {
217 $usr = $ilDB->fetchObject($a_set);
218
219 return $usr->usr_id;
220 }
221 }
222}
223
224?>
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)
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 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)
static getInstance(shibServerData $shibServerData)
create()
create
global $ilDB