PHP code example of cscfi / attribute-test-service
1. Go to this page and download the library: Download cscfi/attribute-test-service library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cscfi / attribute-test-service example snippets
curl -s https://getcomposer.org/installer | php
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler');
$this->loadComponent('Flash');
$this->loadComponent('Auth',[
'authorize' => [
'Controller'
],
'loginAction' => [
'controller' => 'attribute/releases',
'action' => 'index'
],
'flash' => [
'element' => 'error',
'key' => 'auth'
],
]);
if ($this->request->env('Shib-Session-ID')!==null && $this->Auth->user('role')===null) :
$role = (strtolower($this->request->env('schachomeorganization'))=='csc.fi') ? 'admin' : 'user';
$this->Auth->setUser(array('username'=>$this->request->env('displayname'),
'email'=>$this->request->env('mail'),
'eppn'=>$this->request->env('edupersonprincipalname'),
'sn'=>$this->request->env('sn'),
'givenname'=>$this->request->env('givenname'),
'role'=>$role
));
elseif ($this->request->env('Shib-Session-ID')===null && $this->Auth->user('role')!==null) :
$this->Auth->logout();
endif;
$this->Auth->allow(['index','test','view']);
}
public function isAuthorized($user)
{
if(isset($user['role'])) :
if ($user['role']=='admin') :
return true;
endif;
endif;
return false;
}
if ($this->request->session()->read('Auth.User.role') != null) :
echo $this->Flash->render();
echo $this->Flash->render('auth');