Actualización
This commit is contained in:
44
main/auth/shibboleth/app/model/admin.class.php
Normal file
44
main/auth/shibboleth/app/model/admin.class.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Shibboleth;
|
||||
|
||||
require_once __DIR__.'/scaffold/admin.class.php';
|
||||
|
||||
/**
|
||||
* A Chamilo admin. Model for the Admin table.
|
||||
*
|
||||
* Should be moved to the core. It only exists because it is not available through
|
||||
* the API.
|
||||
*
|
||||
* The _Admin objet is generated by the scaffolder. Admin inherits from it to allow
|
||||
* modifications without touching the generated file. Don't modify _Admin as
|
||||
* it may change in the future. Instead add modifications to this class.
|
||||
*
|
||||
* @license see /license.txt
|
||||
* @author Laurent Opprecht <laurent@opprecht.info>, Nicolas Rod for the University of Geneva
|
||||
*/
|
||||
class Admin extends _Admin
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store for Admin objects. Interact with the database. Allows to save and retrieve
|
||||
* admin objects.
|
||||
*
|
||||
* Should be moved to the core. It only exists because it is not available through
|
||||
* the API.
|
||||
*
|
||||
* The _AdminStore objet is generated by the scaffolder. This class inherits from it to allow
|
||||
* modifications without touching the generated file. Don't modify the _ object as
|
||||
* it may change in the future. Instead add modifications to this class.
|
||||
*
|
||||
* @copyright (c) 2012 University of Geneva
|
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
|
||||
* @author Laurent Opprecht <laurent@opprecht.info>
|
||||
*/
|
||||
class AdminStore extends _AdminStore
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
134
main/auth/shibboleth/app/model/scaffold/admin.class.php
Normal file
134
main/auth/shibboleth/app/model/scaffold/admin.class.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace Shibboleth;
|
||||
|
||||
/**
|
||||
* This file is autogenerated. Do not modifiy it.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Model for table admin
|
||||
*
|
||||
* @license see /license.txt
|
||||
* @author Laurent Opprecht <laurent@opprecht.info>, Nicolas Rod for the University of Geneva
|
||||
*/
|
||||
class _Admin
|
||||
{
|
||||
|
||||
/**
|
||||
* Store for Admin objects. Interact with the database.
|
||||
*
|
||||
* @return AdminStore
|
||||
*/
|
||||
public static function store()
|
||||
{
|
||||
static $result = false;
|
||||
if (empty($result))
|
||||
{
|
||||
$result = new AdminStore();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Admin
|
||||
*/
|
||||
public static function create($data = null)
|
||||
{
|
||||
return self::store()->create_object($data);
|
||||
}
|
||||
|
||||
public $user_id = null;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
return self::store()->save($this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store for Admin objects. Interact with the database.
|
||||
*
|
||||
* @copyright (c) 2012 University of Geneva
|
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
|
||||
* @author Laurent Opprecht <laurent@opprecht.info>
|
||||
*/
|
||||
class _AdminStore extends Store
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @return AdminStore
|
||||
*/
|
||||
public static function instance()
|
||||
{
|
||||
static $result = false;
|
||||
if (empty($result))
|
||||
{
|
||||
$result = new self();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('admin', '\Shibboleth\Admin', 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Admin
|
||||
*/
|
||||
public function get($w)
|
||||
{
|
||||
$args = func_get_args();
|
||||
$f = array('parent', 'get');
|
||||
return call_user_func_array($f, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Admin
|
||||
*/
|
||||
public function create_object($data)
|
||||
{
|
||||
return parent::create_object($data);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Admin
|
||||
*/
|
||||
public function get_by_user_id($value)
|
||||
{
|
||||
return $this->get(array('user_id' => $value));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function user_id_exists($value)
|
||||
{
|
||||
return $this->exist(array('user_id' => $value));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete_by_user_id($value)
|
||||
{
|
||||
return $this->delete(array('user_id' => $value));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
185
main/auth/shibboleth/app/model/scaffold/user.class.php
Normal file
185
main/auth/shibboleth/app/model/scaffold/user.class.php
Normal file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
namespace Shibboleth;
|
||||
|
||||
/**
|
||||
* This file is autogenerated. Do not modifiy it.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Model for table user
|
||||
*
|
||||
* @license see /license.txt
|
||||
* @author Laurent Opprecht <laurent@opprecht.info>, Nicolas Rod for the University of Geneva
|
||||
*/
|
||||
class _User
|
||||
{
|
||||
|
||||
/**
|
||||
* Store for User objects. Interact with the database.
|
||||
*
|
||||
* @return UserStore
|
||||
*/
|
||||
public static function store()
|
||||
{
|
||||
static $result = false;
|
||||
if (empty($result))
|
||||
{
|
||||
$result = new UserStore();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public static function create($data = null)
|
||||
{
|
||||
return self::store()->create_object($data);
|
||||
}
|
||||
|
||||
public $user_id = null;
|
||||
public $lastname = null;
|
||||
public $firstname = null;
|
||||
public $username = null;
|
||||
public $password = null;
|
||||
public $auth_source = null;
|
||||
public $shibb_unique_id = null;
|
||||
public $email = null;
|
||||
public $status = null;
|
||||
public $official_code = null;
|
||||
public $phone = null;
|
||||
public $picture_uri = null;
|
||||
public $creator_id = null;
|
||||
public $competences = null;
|
||||
public $diplomas = null;
|
||||
public $openarea = null;
|
||||
public $teach = null;
|
||||
public $productions = null;
|
||||
public $language = null;
|
||||
public $registration_date = null;
|
||||
public $expiration_date = null;
|
||||
public $active = null;
|
||||
public $openid = null;
|
||||
public $theme = null;
|
||||
public $hr_dept_id = null;
|
||||
public $shibb_persistent_id = null;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
return self::store()->save($this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store for User objects. Interact with the database.
|
||||
*
|
||||
* @copyright (c) 2012 University of Geneva
|
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
|
||||
* @author Laurent Opprecht <laurent@opprecht.info>
|
||||
*/
|
||||
class _UserStore extends Store
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @return UserStore
|
||||
*/
|
||||
public static function instance()
|
||||
{
|
||||
static $result = false;
|
||||
if (empty($result))
|
||||
{
|
||||
$result = new self();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('user', '\Shibboleth\User', 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function get($w)
|
||||
{
|
||||
$args = func_get_args();
|
||||
$f = array('parent', 'get');
|
||||
return call_user_func_array($f, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function create_object($data)
|
||||
{
|
||||
return parent::create_object($data);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function get_by_user_id($value)
|
||||
{
|
||||
return $this->get(array('user_id' => $value));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function user_id_exists($value)
|
||||
{
|
||||
return $this->exist(array('user_id' => $value));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete_by_user_id($value)
|
||||
{
|
||||
return $this->delete(array('user_id' => $value));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function get_by_username($value)
|
||||
{
|
||||
return $this->get(array('username' => $value));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function username_exists($value)
|
||||
{
|
||||
return $this->exist(array('username' => $value));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete_by_username($value)
|
||||
{
|
||||
return $this->delete(array('username' => $value));
|
||||
}
|
||||
|
||||
}
|
||||
197
main/auth/shibboleth/app/model/shibboleth_store.class.php
Normal file
197
main/auth/shibboleth/app/model/shibboleth_store.class.php
Normal file
@@ -0,0 +1,197 @@
|
||||
<?php
|
||||
|
||||
namespace Shibboleth;
|
||||
|
||||
/**
|
||||
* Returns Shibboleth user's values based on Shibboleth's configuration.
|
||||
* Shibboleth returns not only whether a user is authenticated but returns as
|
||||
* well several paralemeter fields.
|
||||
*
|
||||
* If a user is not authenticated nothing is returned.
|
||||
*
|
||||
* @license see /license.txt
|
||||
* @author Laurent Opprecht <laurent@opprecht.info>, Nicolas Rod for the University of Geneva
|
||||
*/
|
||||
class ShibbolethStore
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @return ShibbolethStore
|
||||
*/
|
||||
public static function instance()
|
||||
{
|
||||
static $result = false;
|
||||
if (empty($result))
|
||||
{
|
||||
$result = new self();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return ShibbolethConfig
|
||||
*/
|
||||
public static function config()
|
||||
{
|
||||
return Shibboleth::config();
|
||||
}
|
||||
|
||||
public function get_unique_id()
|
||||
{
|
||||
return $this->get(__FUNCTION__);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the user has more than one surname, it is possible depending of the user
|
||||
* home organization that they are all given to the resource.
|
||||
* In the case of the University of Geneva, with two surnames, three different values
|
||||
* for the surname are sent. They are:
|
||||
* 1) "givenname1"
|
||||
* 2) "givenname2"
|
||||
* 3) "givenname1 givenname2"
|
||||
* meaning the string is as follow: "givenname1;givenname2;givenname1 givenname2"
|
||||
*
|
||||
* In such a case, the correct surname is the one which is followed by a space.
|
||||
* This function tests if such a situation is encountered, and returns the first given name.
|
||||
*
|
||||
* @author Nicolas Rod
|
||||
*/
|
||||
public function get_firstname()
|
||||
{
|
||||
$result = $this->get(__FUNCTION__);
|
||||
|
||||
if (!is_array($result))
|
||||
{
|
||||
$result = ucfirst($result);
|
||||
return $result;
|
||||
}
|
||||
foreach ($result as $name)
|
||||
{
|
||||
$parts = explode(' ', $name);
|
||||
|
||||
if (count($parts) > 1)
|
||||
{
|
||||
$result = reset($parts);
|
||||
$result = ucfirst($result);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
$result = reset($result);
|
||||
$result = ucfirst($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function get_lastname()
|
||||
{
|
||||
$result = $this->get(__FUNCTION__);
|
||||
$result = ucfirst($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function get_email()
|
||||
{
|
||||
return $this->get(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function get_language()
|
||||
{
|
||||
return $this->get(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function get_gender()
|
||||
{
|
||||
return $this->get(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function get_address()
|
||||
{
|
||||
return $this->get(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function get_staff_category()
|
||||
{
|
||||
return $this->get(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function get_home_organization_type()
|
||||
{
|
||||
return $this->get(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function get_home_organization()
|
||||
{
|
||||
return $this->get(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function get_affiliation()
|
||||
{
|
||||
return $this->get(__FUNCTION__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ShibbolethUser
|
||||
*/
|
||||
public function get_user()
|
||||
{
|
||||
$result = new ShibbolethUser();
|
||||
foreach ($result as $key => $val)
|
||||
{
|
||||
$f = array($this, "get_$key");
|
||||
if (is_callable($f))
|
||||
{
|
||||
$result->{$key} = call_user_func($f);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shibboleth value stored in $_SERVER if it exists or $default if it is not the case.
|
||||
*
|
||||
* @param string $name the generic name. I.e. one of the class const.
|
||||
* @param string $default default value if it is not provided by Shibboleth
|
||||
* @return string
|
||||
*/
|
||||
public function get($name = '', $default = '')
|
||||
{
|
||||
$config = (array) Shibboleth::config();
|
||||
if ($name)
|
||||
{
|
||||
$name = str_replace('get_', '', $name);
|
||||
$shib_name = isset($config[$name]) ? $config[$name] : '';
|
||||
if ($shib_name)
|
||||
{
|
||||
$result = isset($_SERVER[$shib_name]) ? $_SERVER[$shib_name] : $default;
|
||||
$result = explode(';', $result);
|
||||
if (empty($result))
|
||||
{
|
||||
$result = $default;
|
||||
}
|
||||
else if (count($result) == 1)
|
||||
{
|
||||
$result = reset($result);
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach ($config as $key => $val)
|
||||
{
|
||||
$f = array($this, "get_$key");
|
||||
if (is_callable($f))
|
||||
{
|
||||
$result[$key] = call_user_func($f);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
33
main/auth/shibboleth/app/model/shibboleth_user.class.php
Normal file
33
main/auth/shibboleth/app/model/shibboleth_user.class.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Shibboleth;
|
||||
|
||||
/**
|
||||
* Represent a Shibboleth user. Not to be missunderstand with a Chamilo user
|
||||
* since they don't have the same attributes.
|
||||
*
|
||||
* @license see /license.txt
|
||||
* @author Laurent Opprecht <laurent@opprecht.info>, Nicolas Rod for the University of Geneva
|
||||
*/
|
||||
class ShibbolethUser
|
||||
{
|
||||
|
||||
public $unique_id = '';
|
||||
public $firstname = '';
|
||||
public $lastname = '';
|
||||
public $email = '';
|
||||
public $language = '';
|
||||
public $gender = '';
|
||||
public $address = '';
|
||||
public $staff_category = '';
|
||||
public $home_organization_type = '';
|
||||
public $home_organization = '';
|
||||
public $affiliation = '';
|
||||
public $persistent_id = '';
|
||||
|
||||
public function is_empty()
|
||||
{
|
||||
return empty($this->unique_id);
|
||||
}
|
||||
|
||||
}
|
||||
95
main/auth/shibboleth/app/model/user.class.php
Normal file
95
main/auth/shibboleth/app/model/user.class.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Shibboleth;
|
||||
|
||||
require_once __DIR__.'/scaffold/user.class.php';
|
||||
|
||||
/**
|
||||
* A Chamilo user. Model for the User table.
|
||||
*
|
||||
* Should be moved to the core. It only exists because it is not available through
|
||||
* the API.
|
||||
*
|
||||
* The _User objet is generated by the scaffolder. User inherits from it to allow
|
||||
* modifications without touching the generated file. Don't modify _User as
|
||||
* it may change in the future. Instead add modifications to this class.
|
||||
*
|
||||
* @license see /license.txt
|
||||
* @author Laurent Opprecht <laurent@opprecht.info>, Nicolas Rod for the University of Geneva
|
||||
*/
|
||||
class User extends _User
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store for User objects. Interact with the database. Allows to save and retrieve
|
||||
* user objects.
|
||||
*
|
||||
* Should be moved to the core. It only exists because it is not available through
|
||||
* the API.
|
||||
*
|
||||
* The _UserStore objet is generated by the scaffolder. This class inherits from it to allow
|
||||
* modifications without touching the generated file. Don't modify the _ object as
|
||||
* it may change in the future. Instead add modifications to this class.
|
||||
*
|
||||
* @copyright (c) 2012 University of Geneva
|
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
|
||||
* @author Laurent Opprecht <laurent@opprecht.info>
|
||||
*/
|
||||
class UserStore extends _UserStore
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
ShibbolethUpgrade::update();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $id
|
||||
* @return User
|
||||
*/
|
||||
public function get_by_shibboleth_id($id)
|
||||
{
|
||||
return $this->get(array('shibb_unique_id' => $id));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
*/
|
||||
public function shibboleth_id_exists($id)
|
||||
{
|
||||
return $this->exist(array('shibb_unique_id' => $id));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param User $object
|
||||
*/
|
||||
protected function before_save($object)
|
||||
{
|
||||
$object->username = $object->username ? $object->username : $this->generate_username();
|
||||
$object->password = $object->password ? $object->password : api_generate_password();
|
||||
$object->language = $object->language ? $object->language : $this->default_language();
|
||||
}
|
||||
|
||||
function default_language()
|
||||
{
|
||||
return api_get_setting('platformLanguage');
|
||||
}
|
||||
|
||||
function generate_username()
|
||||
{
|
||||
$result = uniqid('s', true);
|
||||
$result = str_replace('.', '', $result);
|
||||
while ($this->username_exists($result))
|
||||
{
|
||||
$result = uniqid('s', true);
|
||||
$result = str_replace('.', '', $result);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user