コード例 #1
0
ファイル: view_user.php プロジェクト: Tom-Byrne/gocdb
function view_user()
{
    require_once __DIR__ . '/../../../../lib/Gocdb_Services/Factory.php';
    require_once __DIR__ . '/../../components/Get_User_Principle.php';
    if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
        throw new Exception("An id must be specified");
    }
    $userId = $_GET['id'];
    $user = \Factory::getUserService()->getUser($userId);
    if ($user === null) {
        throw new Exception("No user with that ID");
    }
    $params['user'] = $user;
    // get the targetUser's roles
    $roles = \Factory::getRoleService()->getUserRoles($user, \RoleStatus::GRANTED);
    //$user->getRoles();
    $callingUser = \Factory::getUserService()->getUserByPrinciple(Get_User_Principle());
    // can the calling user revoke the targetUser's roles?
    if ($user != $callingUser) {
        foreach ($roles as $r) {
            //$ownedEntityDetail = $r->getOwnedEntity()->getName(). ' ('. $r->getOwnedEntity()->getType().')';
            $authorisingRoleNames = \Factory::getRoleService()->authorizeAction(\Action::REVOKE_ROLE, $r->getOwnedEntity(), $callingUser);
            if (count($authorisingRoleNames) >= 1) {
                $allAuthorisingRoleNames = '';
                foreach ($authorisingRoleNames as $arName) {
                    $allAuthorisingRoleNames .= $arName . ', ';
                }
                $allAuthorisingRoleNames = substr($allAuthorisingRoleNames, 0, strlen($allAuthorisingRoleNames) - 2);
                $r->setDecoratorObject('[' . $allAuthorisingRoleNames . '] ');
            }
        }
    } else {
        // current user is viewing their own roles, so they can revoke their own roles
        foreach ($roles as $r) {
            $r->setDecoratorObject('[Self revoke own role]');
        }
    }
    // Check to see if the current calling user has permission to edit the target user
    try {
        \Factory::getUserService()->editUserAuthorization($user, $callingUser);
        $params['ShowEdit'] = true;
    } catch (Exception $e) {
        $params['ShowEdit'] = false;
    }
    /* @var $authToken \org\gocdb\security\authentication\IAuthentication */
    $authToken = Get_User_AuthToken();
    $params['authAttributes'] = $authToken->getDetails();
    $params['roles'] = $roles;
    $params['portalIsReadOnly'] = \Factory::getConfigService()->IsPortalReadOnly();
    $title = $user->getFullName();
    show_view("user/view_user.php", $params, $title);
}
コード例 #2
0
ファイル: register.php プロジェクト: Tom-Byrne/gocdb
/**
 * Draws the register user form
 * @return null
 */
function draw()
{
    $serv = \Factory::getUserService();
    $dn = Get_User_Principle();
    if (empty($dn)) {
        show_view('error.php', "Could not authenticate user - null user principle");
        die;
    }
    $user = $serv->getUserByPrinciple($dn);
    if (!is_null($user)) {
        show_view('error.php', "Only unregistered users can register");
        die;
    }
    /* @var $authToken \org\gocdb\security\authentication\IAuthentication */
    $authToken = Get_User_AuthToken();
    $params['authAttributes'] = $authToken->getDetails();
    $params['dn'] = $dn;
    show_view('user/register.php', $params);
}