getUserData() 공개 정적인 메소드

Get user's data Can be called to read only one field If $injson is true, data are returned json encoded getUserData('xxxx', 'email'); getUserData('xxxx', null, true);
public static getUserData ( $uid, $field = null, $injson = false )
예제 #1
0
 public static function getChannelUsers($cid, $withudata = false)
 {
     $cdir = self::getChannelsDir();
     $cupath = $cdir . '/' . $cid . '/users/';
     $subscribers = array();
     foreach (scandir($cupath) as $uid) {
         if ($uid === '.' || $uid === '..') {
             continue;
         }
         if ($withudata) {
             $subscribers[$uid] = Container_users::getUserData($uid);
         } else {
             $subscribers[] = $uid;
         }
     }
     return $subscribers;
 }
예제 #2
0
 /**
  * cid : recipient
  * uid : sender
  * msg : message to send
  */
 public static function postMsgToChannel($cid, $uid, $body, $type = 'msg')
 {
     $mid = self::generateMid($cid);
     $msg = array('id' => $mid, 'sender' => $uid, 'recipient' => 'channel|' . $cid, 'type' => $type, 'body' => $body, 'timestamp' => time());
     // when a join message is sent, body contains user's data
     if ($type == 'join') {
         $msg['body'] = Container_users::getUserData($uid);
     }
     // json encode msg before storing
     $msg = json_encode($msg);
     // search users subscribed to the channel
     foreach (Container_channels::getChannelUsers($cid) as $subuid) {
         // post this message on each users subscribed on the channel
         // /users/:uid/msg/
         if ($subuid != $uid) {
             // don't post message to the current connected user
             $umdir = Container_users::getDir() . '/' . $subuid . '/messages';
             file_put_contents($umdir . '/' . $mid, $msg);
         }
     }
     return $msg;
 }
예제 #3
0
    // Only allow to get userdata if connected user is in the same channel
    if ($_SESSION['userdata']['id'] != $uid) {
        $cuser1 = Container_users::getUserChannels($uid);
        $cuser2 = Container_users::getUserChannels($_SESSION['userdata']['id']);
        if (count(array_intersect($cuser1, $cuser2)) == 0) {
            $res->status(403);
            // Forbidden
            $res['Content-Type'] = 'application/json; charset=utf-8';
            $res->body('{ "error": "Forbidden" }');
            return;
        }
    }
    // returns user data in json
    $res->status(200);
    $res['Content-Type'] = 'application/json; charset=utf-8';
    $res->body(Container_users::getUserData($uid, null, true));
});
/**
 * Returns user's pending messages
 */
$app->get('/users/:uid/pending/', function ($uid) use($app, $req, $res) {
    // check user acces
    session_start();
    if (!isset($_SESSION['userdata']) or !isset($_SESSION['userdata']['id'])) {
        $res->status(401);
        // Need to authenticate
        return;
    }
    if ($uid !== $_SESSION['userdata']['id']) {
        $res->status(403);
        // Forbidden
예제 #4
0
 if (!Container_channels::checkChannelUser($cid, $online_uid)) {
     $res->status(403);
     // You have to join channel
     return;
 }
 // check this user is an operator on this channel
 if (!Container_channels_op::isOp($cid, $online_uid)) {
     $res->status(403);
     // You have to be an operator to banish a user
     $res['Content-Type'] = 'application/json; charset=utf-8';
     $res->body(GetPfcError(40306));
     // You have to be an operator to banish a user
     return;
 }
 // add name64 to the ban list
 $opname = Container_users::getUserData($online_uid, 'name');
 $reason = $req->params('reason');
 $ok = Container_channels_ban::addBan($cid, $name64, array('opname' => $opname, 'reason' => $reason ? $reason : '', 'timestamp' => time()));
 if ($ok) {
     $name = base64_decode($name64);
     $banuid = Container_indexes::getIndex('users/name', $name);
     $iskickban = $req->params('kickban') && $banuid;
     // notification to other connected user of this ban
     Container_messages::postMsgToChannel($cid, $online_uid, array('opname' => $opname, 'name' => $name, 'reason' => $reason ? $reason : '', 'kickban' => $iskickban), 'ban');
     // kick the user from the channel
     // (warning: do it after the above notification
     //  or he will not receive the notification)
     if ($iskickban) {
         Container_users::leaveChannel($banuid, $cid);
     }
     $res->status(201);
예제 #5
0
                $login = Container_users::getUserData($uid)->name;
                $channel = $cid;
                // todo: replace this by the channel fullname
                $isop = $hook($login, $channel, $uid, $cid);
            }
        }
        // first is op ? first connected user on the channel is an operator
        if ($GLOBALS['first_is_op'] and count(Container_channels::getChannelUsers($cid)) == 1) {
            $isop = Container_channels_op::addOp($cid, $uid);
        }
        if ($isop) {
            Container_channels_op::addOp($cid, $uid);
        }
        // post a join message
        // when a join message is sent, body contains user's data and the "op" flag
        $body = array('userdata' => Container_users::getUserData($uid), 'op' => $isop);
        $msg = Container_messages::postMsgToChannel($cid, $uid, $body, 'join');
        $res->status(201);
        // User joined the channel
        $res['Content-Type'] = 'application/json; charset=utf-8';
        $res->body(json_encode(array('users' => Container_channels::getChannelUsers($cid, true), 'op' => Container_channels_op::getOpList($cid))));
        return;
    }
});
/**
 * Leave a channel
 * or is kicked from a channel
 */
$app->delete('/channels/:cid/users/:uid', function ($cid, $uid) use($app, $req, $res) {
    // check user acces
    session_start();