correctly set and use logged user

This commit is contained in:
coderkun 2014-04-07 23:10:15 +02:00
commit 55d4de044d
9 changed files with 30 additions and 28 deletions

View file

@ -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>
*/
abstract class ToplevelController extends \hhu\z\Controller
abstract class IntermediateController extends \hhu\z\Controller
{
/**
* Required models
@ -32,7 +32,9 @@
*/
public static $user = null;
/**
* Current Seminary
*
* var array
*/
public static $seminary = null;
/**
@ -46,7 +48,7 @@
/**
* Construct a new application Controller.
* Construct a new IntermediateController.
*
* @throws DriverNotFoundException
* @throws DriverNotValidException
@ -76,22 +78,22 @@
// Get userdata
try {
static::$user = $this->Users->getUserById($this->Auth->getUserId());
self::$user = $this->Users->getUserById($this->Auth->getUserId());
// Determine user roles
static::$user['roles'] = array();
$roles = $this->Userroles->getUserrolesForUserById(static::$user['id']);
self::$user['roles'] = array();
$roles = $this->Userroles->getUserrolesForUserById(self::$user['id']);
foreach($roles as &$role) {
static::$user['roles'][] = $role['name'];
self::$user['roles'][] = $role['name'];
}
// Character
$controller = $this->agent->getIntermediateAgent()->controller;
$controller = $this->agent->controller;
if(is_subclass_of($controller, '\hhu\z\controllers\SeminaryRoleController'))
{
$seminaryUrl = $this->request->getParam(3);
static::$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
static::$character = $this->Characters->getCharacterForUserAndSeminary(static::$user['id'], static::$seminary['id']);
self::$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
self::$character = $this->Characters->getCharacterForUserAndSeminary(self::$user['id'], self::$seminary['id']);
}
}
catch(\nre\exceptions\IdNotFoundException $e) {
@ -101,9 +103,9 @@
$this->checkPermission($request, $response);
// Set userdata
$this->set('loggedUser', static::$user);
$this->set('loggedSeminary', static::$seminary);
$this->set('loggedCharacter', static::$character);
$this->set('loggedUser', self::$user);
$this->set('loggedSeminary', self::$seminary);
$this->set('loggedCharacter', self::$character);
}
@ -130,8 +132,8 @@
{
// Determine user
$userRoles = array('guest');
if(!is_null(static::$user)) {
$userRoles = static::$user['roles'];
if(!is_null(self::$user)) {
$userRoles = self::$user['roles'];
}
@ -144,7 +146,7 @@
}
// Determine permissions of Intermediate Controller for current action
$controller = $this->agent->getIntermediateAgent()->controller;
$controller = $this->agent->controller;
$action = $this->request->getParam(2, 'action');
if(!property_exists($controller, 'permissions')) {
return; // Allow if nothing is specified

View file

@ -18,7 +18,7 @@
*
* @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

View file

@ -17,7 +17,7 @@
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
*/
class BinaryController extends \hhu\z\controllers\ToplevelController
class BinaryController extends \hhu\z\controllers\IntermediateController
{

View file

@ -17,7 +17,7 @@
*
* @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'));
// Set userdata
$this->set('loggedUser', static::$user);
$this->set('loggedSeminary', static::$seminary);
$this->set('loggedCharacter', static::$character);
$this->set('loggedUser', IntermediateController::$user);
$this->set('loggedSeminary', IntermediateController::$seminary);
$this->set('loggedCharacter', IntermediateController::$character);
}
}

View file

@ -17,7 +17,7 @@
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
*/
class IntroductionController extends \hhu\z\Controller
class IntroductionController extends \hhu\z\controllers\IntermediateController
{

View file

@ -34,7 +34,7 @@
parent::preFilter($request, $response);
// Set userdata
$this->set('loggedUser', HtmlController::$user);
$this->set('loggedUser', IntermediateController::$user);
}

View file

@ -35,8 +35,8 @@
parent::preFilter($request, $response);
// Set userdata
$this->set('loggedUser', HtmlController::$user);
$this->set('loggedSeminary', HtmlController::$seminary);
$this->set('loggedUser', IntermediateController::$user);
$this->set('loggedSeminary', IntermediateController::$seminary);
}

View file

@ -17,7 +17,7 @@
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
*/
class UploadsController extends \hhu\z\Controller
class UploadsController extends \hhu\z\controllers\IntermediateController
{
/**
* Required models

View file

@ -17,7 +17,7 @@
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
*/
class UsersController extends \hhu\z\Controller
class UsersController extends \hhu\z\controllers\IntermediateController
{
/**
* User permissions