예제 #1
0
 public static function get_user_groups($user_id = null)
 {
     if (is_null($user_id)) {
         $user = Base::getUser();
         $groups = $user['groups'];
         $inheritance = (!empty($user['inheritance']) and is_array($user['inheritance'])) ? $user['inheritance'] : array();
         $groups = array_unique(array_merge($groups, $inheritance));
         // may comment this line to disable inheritance
     } else {
         $user_model = new \GCore\Admin\Models\User();
         $user = $user_model->find('first', array('conditions' => array('id' => $user_id)));
         if (!empty($user)) {
             $groups = Arr::getVal($user, array('GroupUser', '[n]', 'group_id'), self::get_public_groups());
             $user_groups_paths = Arr::getVal($user, array('Group', '[n]', 'path'), array());
             $user_inheritance = array();
             foreach ($user_groups_paths as $user_groups_path) {
                 $user_inheritance = array_merge($user_inheritance, array_filter(explode('.', $user_groups_path)));
             }
             $user_inheritance = array_unique($user_inheritance);
             $groups = array_unique(array_merge($groups, $user_inheritance));
             // may comment this line to disable inheritance
             $user = $user['User'];
             if (!empty($user['activation'])) {
                 return self::get_public_groups();
             }
             if ($user['blocked'] == 1) {
                 return self::get_public_groups();
             }
         }
     }
     return $groups;
 }
예제 #2
0
 public static function check_rules($rules, $groups = array(), $owner_id = null, $user_id = null)
 {
     $user = Base::getUser();
     if (empty($groups)) {
         $groups = Authenticate::get_user_groups($user_id);
     }
     if (!empty($owner_id) and $owner_id == $user['id']) {
         $groups[] = 'owner';
     }
     if (!is_array($rules)) {
         $rules = (array) $rules;
     }
     //check if any denied groups match user's groups
     $denied = array_keys($rules, -1);
     if (count(array_intersect($denied, $groups)) > 0) {
         //one or more of the user's groups is denied, return false
         return false;
     }
     //check if any allowed groups match user's groups
     $allowed = array_keys($rules, 1);
     if (count(array_intersect($allowed, $groups)) > 0) {
         //one or more of the user's groups is denied, return false
         return true;
     }
     //check if any not set groups match user's groups
     $not_set = array_keys($rules, '');
     if (count(array_intersect($not_set, $groups)) > 0) {
         //one or more of the user's groups is denied, return false
         return 0;
     }
     return null;
 }
예제 #3
0
파일: app.php 프로젝트: ejailesb/repo_empr
 function initialize()
 {
     //start the session
     $user = Base::getUser();
     Event::trigger('on_initialize');
 }
예제 #4
0
 function beforeSave(&$data, &$params, $mode)
 {
     foreach ($this->params_fields as $params_field) {
         if (isset($data[$params_field]) and is_array($data[$params_field])) {
             $p_obj = new Parameter($data[$params_field]);
             $data[$params_field] = $p_obj->toString();
         }
     }
     if (isset($data['extras']) and is_array($data['extras'])) {
         $base_string = new Base64($data['extras']);
         $data['extras'] = $base_string->encode();
     }
     if (array_key_exists('alias', $data) and empty($data['alias']) and !empty($data['title'])) {
         $count = 1;
         $test = $alias = Str::slug($data['title']);
         redo:
         $exists = $this->find('first', array('fields' => array($this->pkey), 'conditions' => array('alias' => $test)));
         if (!empty($exists)) {
             $count++;
             $test = $alias . $count;
             goto redo;
         }
         $data['alias'] = $test;
     }
     if ($mode == 'create' and in_array('user_id', $this->table_fields) and !isset($data['user_id'])) {
         $user = Base::getUser();
         $data['user_id'] = $user['id'];
     }
 }
예제 #5
0
파일: routes.php 프로젝트: nbar1/gs
 */
$app->get('/api/v1/queue/', function () use($base) {
    if (ApiHandler::validKey()) {
        ApiHandler::sendResponse(200, true, array('queue' => $base->getQueue()->getQueue()));
    } else {
        ApiHandler::notAuthenticated();
    }
});
/**
 * Add song to the queue
 */
$app->post('/api/v1/queue/add/', function () use($base) {
    if (ApiHandler::validKey()) {
        $song_info = $base->getSong()->getSongInformationFromGrooveShark($_POST['songID']);
        $base->getSong()->setSongInformation($song_info['SongID'], $song_info['SongName'], $song_info['ArtistName'], $song_info['ArtistID'], $song_info['CoverArtFilename'], $_POST['songPriority']);
        $base->getUser()->getUserByApiKey($_GET['apikey']);
        if ($base->getQueue()->addSongToQueue($base->getSong(), $base->getUser())) {
            ApiHandler::sendResponse(200, true);
        } else {
            ApiHandler::sendResponse(500, false);
        }
    } else {
        ApiHandler::notAuthenticated();
    }
});
/**
 * Register
 */
$app->post('/api/v1/register/', function () use($base) {
    $register = $base->getUser()->registerUser($_POST['username'], $_POST['password']);
    if ($register === USER_ALREADY_EXISTS) {