コード例 #1
0
ファイル: api.php プロジェクト: ratbird/hope
 function setupAuth($router)
 {
     // Detect consumer
     $consumer = Consumer\Base::detectConsumer();
     if (!$consumer) {
         throw new RouterException(401, 'Unauthorized (no consumer)');
     }
     // Set authentication if present
     if ($user = $consumer->getUser()) {
         // Skip fake authentication if user is already logged in
         if ($GLOBALS['user']->id !== $user->id) {
             $GLOBALS['auth'] = new Seminar_Auth();
             $GLOBALS['auth']->auth = array('uid' => $user->user_id, 'uname' => $user->username, 'perm' => $user->perms);
             $GLOBALS['user'] = new Seminar_User($user->user_id);
             $GLOBALS['perm'] = new Seminar_Perm();
             $GLOBALS['MAIL_VALIDATE_BOX'] = false;
         }
         setTempLanguage($GLOBALS['user']->id);
     }
     return $consumer->getUser();
 }
コード例 #2
0
ファイル: UserPermissions.php プロジェクト: ratbird/hope
 /**
  * Get a list of all consumer the user has granted acces to.
  *
  * @return Array List of consumer objects
  */
 public function getConsumers()
 {
     $result = array();
     foreach ($this->permissions as $consumer_id => $granted) {
         if (!$granted) {
             continue;
         }
         $result[$consumer_id] = Consumer\Base::find($consumer_id);
     }
     return $result;
 }
コード例 #3
0
ファイル: OAuth.php プロジェクト: ratbird/hope
 /**
  * SimpleORMap constructor, registers neccessary callbacks.
  */
 public function __construct($id = null)
 {
     parent::__construct($id);
     $this->registerCallback('before_store', 'before_store');
 }
コード例 #4
0
ファイル: bootstrap-api.php プロジェクト: ratbird/hope
<?php

namespace {
    StudipAutoloader::addAutoloadPath($GLOBALS['STUDIP_BASE_PATH'] . '/vendor/oauth-php/library');
    StudipAutoloader::addClassLookup('DocBlock', 'vendor/docblock-parser/docblock-parser.php');
    // Set base url for URLHelper class
    URLHelper::setBaseUrl($GLOBALS['CANONICAL_RELATIVE_PATH_STUDIP']);
}
namespace RESTAPI {
    use Studip, OAuthStore;
    // Define api version
    const VERSION = '2';
    $router = Router::getInstance();
    // Register JSON content renderer
    $router->registerRenderer(new Renderer\JSONRenderer(), true);
    // If in development mode, register debug content renderer
    if (defined('Studip\\ENV') && Studip\ENV === 'development') {
        $router->registerRenderer(new Renderer\DebugRenderer());
    }
    OAuthStore::instance('PDO', array('dsn' => 'mysql:host=' . $GLOBALS['DB_STUDIP_HOST'] . ';dbname=' . $GLOBALS['DB_STUDIP_DATABASE'], 'username' => $GLOBALS['DB_STUDIP_USER'], 'password' => $GLOBALS['DB_STUDIP_PASSWORD']));
    // Register default consumers
    Consumer\Base::addType('http', 'RESTAPI\\Consumer\\HTTP');
    Consumer\Base::addType('studip', 'RESTAPI\\Consumer\\Studip');
    Consumer\Base::addType('oauth', 'RESTAPI\\Consumer\\OAuth');
    // $router->registerConsumer('oauth', new Consumer\OAuth);
    // $router->registerConsumer('basic', new Consumer\HTTP);
    // $router->registerConsumer('studip', new Consumer\Studip);
}