correctly set and use logged user
This commit is contained in:
parent
979e9db2c2
commit
55d4de044d
9 changed files with 30 additions and 28 deletions
|
|
@ -13,11 +13,11 @@
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class for implementing a Controller of a ToplevelAgent.
|
* Abstract class for implementing a Controller of an IntermediateAgent.
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
abstract class ToplevelController extends \hhu\z\Controller
|
abstract class IntermediateController extends \hhu\z\Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Required models
|
* Required models
|
||||||
|
|
@ -32,7 +32,9 @@
|
||||||
*/
|
*/
|
||||||
public static $user = null;
|
public static $user = null;
|
||||||
/**
|
/**
|
||||||
|
* Current Seminary
|
||||||
*
|
*
|
||||||
|
* var array
|
||||||
*/
|
*/
|
||||||
public static $seminary = null;
|
public static $seminary = null;
|
||||||
/**
|
/**
|
||||||
|
|
@ -46,7 +48,7 @@
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new application Controller.
|
* Construct a new IntermediateController.
|
||||||
*
|
*
|
||||||
* @throws DriverNotFoundException
|
* @throws DriverNotFoundException
|
||||||
* @throws DriverNotValidException
|
* @throws DriverNotValidException
|
||||||
|
|
@ -76,22 +78,22 @@
|
||||||
|
|
||||||
// Get userdata
|
// Get userdata
|
||||||
try {
|
try {
|
||||||
static::$user = $this->Users->getUserById($this->Auth->getUserId());
|
self::$user = $this->Users->getUserById($this->Auth->getUserId());
|
||||||
|
|
||||||
// Determine user roles
|
// Determine user roles
|
||||||
static::$user['roles'] = array();
|
self::$user['roles'] = array();
|
||||||
$roles = $this->Userroles->getUserrolesForUserById(static::$user['id']);
|
$roles = $this->Userroles->getUserrolesForUserById(self::$user['id']);
|
||||||
foreach($roles as &$role) {
|
foreach($roles as &$role) {
|
||||||
static::$user['roles'][] = $role['name'];
|
self::$user['roles'][] = $role['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Character
|
// Character
|
||||||
$controller = $this->agent->getIntermediateAgent()->controller;
|
$controller = $this->agent->controller;
|
||||||
if(is_subclass_of($controller, '\hhu\z\controllers\SeminaryRoleController'))
|
if(is_subclass_of($controller, '\hhu\z\controllers\SeminaryRoleController'))
|
||||||
{
|
{
|
||||||
$seminaryUrl = $this->request->getParam(3);
|
$seminaryUrl = $this->request->getParam(3);
|
||||||
static::$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
self::$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||||
static::$character = $this->Characters->getCharacterForUserAndSeminary(static::$user['id'], static::$seminary['id']);
|
self::$character = $this->Characters->getCharacterForUserAndSeminary(self::$user['id'], self::$seminary['id']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(\nre\exceptions\IdNotFoundException $e) {
|
catch(\nre\exceptions\IdNotFoundException $e) {
|
||||||
|
|
@ -101,9 +103,9 @@
|
||||||
$this->checkPermission($request, $response);
|
$this->checkPermission($request, $response);
|
||||||
|
|
||||||
// Set userdata
|
// Set userdata
|
||||||
$this->set('loggedUser', static::$user);
|
$this->set('loggedUser', self::$user);
|
||||||
$this->set('loggedSeminary', static::$seminary);
|
$this->set('loggedSeminary', self::$seminary);
|
||||||
$this->set('loggedCharacter', static::$character);
|
$this->set('loggedCharacter', self::$character);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -130,8 +132,8 @@
|
||||||
{
|
{
|
||||||
// Determine user
|
// Determine user
|
||||||
$userRoles = array('guest');
|
$userRoles = array('guest');
|
||||||
if(!is_null(static::$user)) {
|
if(!is_null(self::$user)) {
|
||||||
$userRoles = static::$user['roles'];
|
$userRoles = self::$user['roles'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -144,7 +146,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine permissions of Intermediate Controller for current action
|
// Determine permissions of Intermediate Controller for current action
|
||||||
$controller = $this->agent->getIntermediateAgent()->controller;
|
$controller = $this->agent->controller;
|
||||||
$action = $this->request->getParam(2, 'action');
|
$action = $this->request->getParam(2, 'action');
|
||||||
if(!property_exists($controller, 'permissions')) {
|
if(!property_exists($controller, 'permissions')) {
|
||||||
return; // Allow if nothing is specified
|
return; // Allow if nothing is specified
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
abstract class SeminaryRoleController extends \hhu\z\Controller
|
abstract class SeminaryRoleController extends \hhu\z\controllers\IntermediateController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Required components
|
* Required components
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
class BinaryController extends \hhu\z\controllers\ToplevelController
|
class BinaryController extends \hhu\z\controllers\IntermediateController
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
class HtmlController extends \hhu\z\controllers\ToplevelController
|
class HtmlController extends \hhu\z\Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -49,9 +49,9 @@
|
||||||
$this->set('title', $this->request->getParam(1, 'intermediate'));
|
$this->set('title', $this->request->getParam(1, 'intermediate'));
|
||||||
|
|
||||||
// Set userdata
|
// Set userdata
|
||||||
$this->set('loggedUser', static::$user);
|
$this->set('loggedUser', IntermediateController::$user);
|
||||||
$this->set('loggedSeminary', static::$seminary);
|
$this->set('loggedSeminary', IntermediateController::$seminary);
|
||||||
$this->set('loggedCharacter', static::$character);
|
$this->set('loggedCharacter', IntermediateController::$character);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
class IntroductionController extends \hhu\z\Controller
|
class IntroductionController extends \hhu\z\controllers\IntermediateController
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@
|
||||||
parent::preFilter($request, $response);
|
parent::preFilter($request, $response);
|
||||||
|
|
||||||
// Set userdata
|
// Set userdata
|
||||||
$this->set('loggedUser', HtmlController::$user);
|
$this->set('loggedUser', IntermediateController::$user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@
|
||||||
parent::preFilter($request, $response);
|
parent::preFilter($request, $response);
|
||||||
|
|
||||||
// Set userdata
|
// Set userdata
|
||||||
$this->set('loggedUser', HtmlController::$user);
|
$this->set('loggedUser', IntermediateController::$user);
|
||||||
$this->set('loggedSeminary', HtmlController::$seminary);
|
$this->set('loggedSeminary', IntermediateController::$seminary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
class UploadsController extends \hhu\z\Controller
|
class UploadsController extends \hhu\z\controllers\IntermediateController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Required models
|
* Required models
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
class UsersController extends \hhu\z\Controller
|
class UsersController extends \hhu\z\controllers\IntermediateController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* User permissions
|
* User permissions
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue