ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 
15  protected $shibServerData;
16 
17 
24  public static function getInstance(shibServerData $shibServerData) {
25  return self::buildInstance($shibServerData);
26  }
27 
28 
34  public static function buildInstance(shibServerData $shibServerData) {
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()) {
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->setTitle($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 
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());
113  $this->setExternalAccount($this->shibServerData->getLogin());
114  $this->setTitle($this->shibServerData->getTitle());
115  $this->setInstitution($this->shibServerData->getInstitution());
116  $this->setDepartment($this->shibServerData->getDepartment());
117  $this->setStreet($this->shibServerData->getStreet());
118  $this->setZipcode($this->shibServerData->getZipcode());
119  $this->setCountry($this->shibServerData->getCountry());
120  $this->setPhoneOffice($this->shibServerData->getPhoneOffice());
121  $this->setPhoneHome($this->shibServerData->getPhoneHome());
122  $this->setPhoneMobile($this->shibServerData->getPhoneMobile());
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 ?>
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
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
static getInstance(shibServerData $shibServerData)
setHobby($a_str)
set hobby public
setMatriculation($a_str)
set matriculation number public
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