コード例 #1
0
ファイル: friends.php プロジェクト: AdventureKing/EventFeast
 public function getFriends($userId)
 {
     $db_parse = new DbHandlerParse();
     $usersArray = array();
     $db_mark = new DbHandlerMark();
     $db_mark->run_sql("SELECT * FROM follow WHERE follower_user_id = '{$userId}'");
     $stmt = $this->conn->prepare("SELECT * FROM follow WHERE follower_user_id = ?");
     $stmt->bind_param("s", $userId);
     if ($stmt->execute()) {
         /* Store the result (to get properties) */
         $stmt->store_result();
         /* Get the number of rows */
         $num_of_rows = $stmt->num_rows;
         /* Bind the result to variables */
         $stmt->bind_result($id, $followerUserId, $followedUserId, $status, $createdAt);
         while ($stmt->fetch()) {
             //echo 'ID: '.$id.'<br>';
             //echo 'Follower: '.$followerUserId.'<br>';
             //echo 'Followed: '.$followedUserId.'<br>';
             //echo 'status: '.$status.'<br>';
             //echo 'Created: '.$createdAt.'<br><br>';
             //printf("Follower ID: %s  Created: %s", $followerUserId, $createdAt);
             array_push($usersArray, $db_parse->getUserById($followedUserId));
         }
         /* free results */
         $stmt->free_result();
     }
     $stmt->close();
     return $usersArray;
 }
コード例 #2
0
 /**
  * Destroy friendship between requesting user and requested user
  * @param String $userId user id to whom call belongs to
  * @param String $friendUserId user id of the requested user
  */
 public function destroyFriendShip($userId, $friendUserId)
 {
     // Verify that requested friend exists
     $db_parse = new DbHandlerParse();
     $isFriendExist = $db_parse->isUserIdExists($friendUserId);
     if (!$isFriendExist || empty($userId) || $userId == $friendUserId) {
         echo $isFriendExist;
         return NULL;
     }
     // Verify that already following
     $stmt = $this->conn->prepare("SELECT f.follower_user_id, f.followed_user_id, f.status, f.created from follow f WHERE f.follower_user_id = ? AND f.followed_user_id = ?");
     $stmt->bind_param("ss", $userId, $friendUserId);
     if ($stmt->execute()) {
         $ret = $stmt->get_result()->fetch_assoc();
         $stmt->close();
         if (empty($ret)) {
             //echo "user is not already following friend!";
             return NULL;
         }
     }
     $db_mark = new DbHandlerMark();
     $db_mark->run_sql("DELETE from follow WHERE follower_user_id = '{$userId}' AND followed_user_id = '{$friendUserId}'");
     $stmt = $this->conn->prepare("DELETE from follow WHERE follower_user_id = ? AND followed_user_id = ?");
     $stmt->bind_param("ss", $userId, $friendUserId);
     $result = $stmt->execute();
     $stmt->close();
     if ($result) {
         // follow row removed
         $stmt = $this->conn->prepare("SELECT f.follower_user_id, f.followed_user_id, f.status, f.created from follow f WHERE f.follower_user_id = ? AND f.followed_user_id = ?");
         $stmt->bind_param("ss", $userId, $friendUserId);
         if ($stmt->execute()) {
             $ret = $stmt->get_result()->fetch_assoc();
             $stmt->close();
             if (empty($ret)) {
                 //echo "user is no longer following friend!";
                 return TRUE;
             }
         } else {
             return NULL;
         }
     } else {
         // unfollow request failed
         //echo "uh oh, why can't you unfollow friend?";
         return NULL;
     }
 }
コード例 #3
0
/**
 * Adding Middle Layer to authenticate every request
 * Checking if the request has valid api key in the 'Authorization' header
 */
function authenticate(\Slim\Route $route)
{
    // Getting request headers
    $headers = apache_request_headers();
    $response = array();
    $app = \Slim\Slim::getInstance();
    // Verifying Authorization Header
    if (isset($headers['Authorization']) && isset($headers['Token'])) {
        $db = new DbHandlerParse();
        // get the api key
        $api_key = $headers['Authorization'];
        // get the session token
        $session_token = $headers['Token'];
        // validating api key
        if (!$db->isValidApiKey($api_key)) {
            // api key is not present in users table
            $response["result"] = "error";
            $response["message"] = "Access Denied. Invalid Api key";
            echoRespnse(401, $response);
            $app->stop();
        } else {
            if (!$db->isValidSessionToken($session_token, $api_key)) {
                // session token does not match api key or is just invalid
                $response["result"] = "error";
                $response["message"] = "Access Denied. Invalid Token";
                echoRespnse(401, $response);
                $app->stop();
            } else {
                global $user_id;
                // get user primary key id
                $userID = $db->getUserId($api_key);
                if (NULL != $userID) {
                    $user_id = $userID;
                    $_SESSION['userId'] = $user_id;
                }
            }
        }
    } else {
        if (!isset($headers['Authorization'])) {
            // api key is missing in header
            $response["result"] = "error";
            $response["message"] = "Api key is misssing";
            echoRespnse(400, $response);
            $app->stop();
        } else {
            // token is missing in header
            $response["result"] = "error";
            $response["message"] = "Token is misssing";
            echoRespnse(400, $response);
            $app->stop();
        }
    }
}
コード例 #4
0
ファイル: user.php プロジェクト: AdventureKing/UTSASCHOOLWORK
 $eventId = $app->request()->post('eventId');
 $eventSource = $app->request()->post('eventSource');
 $postMsg = $app->request()->post('postMsg');
 $postLat = $app->request()->post('userLat');
 $postLng = $app->request()->post('userLng');
 $postInfo = array();
 $postInfo['message'] = $postMsg;
 $postInfo['latitude'] = $postLat;
 $postInfo['longitude'] = $postLng;
 $db = new DbHandlerNeo();
 // TODO: Check if event exists too
 if ($db->isUserExistsByUserId($userId)) {
     $result = $db->createPostNoPhotos($userId, $eventId, $eventSource, $postInfo);
 } else {
     //Try and create parse user if exists in parse
     $dbParse = new DbHandlerParse();
     $parseUser = $dbParse->getUserById($userId);
     if (null != $parseUser) {
         $db->createUser($parseUser->getObjectId(), $parseUser->get('email'), $parseUser->get('username'));
         $result = $db->createPostNoPhotos($parseUser->getObjectId(), $eventId, $eventSource, $postInfo);
     } else {
         $result = false;
     }
 }
 if ($result == 'POST_CREATED') {
     $response['result'] = 'success';
     $response['message'] = "User ID: {$userId} successfully created a new post!";
 } else {
     if ($result == 'EVENT_NOT_FOUND') {
         $response['result'] = 'error';
         $response['message'] = 'Post could not be created because the associated event was not found.';
コード例 #5
0
ファイル: users.php プロジェクト: AdventureKing/EventFeast
<?php

/**
 * Users List
 * url - /list
 * method - GET
 */
$app->get('/users/list', 'authenticate', function () use($app) {
    $response = array();
    $db = new DbHandlerParse();
    $results = $db->getUserList();
    $records = array();
    $followers = new Followers();
    //echo "Successfully retrieved " . count($results) . " scores.<br><br>";
    // Do something with the returned ParseObject values
    for ($i = 0; $i < count($results); $i++) {
        $object = $results[$i];
        $record = array();
        $records[$i]['userId'] = $object->getObjectId();
        $records[$i]['firstName'] = $object->get('firstName');
        $records[$i]['lastName'] = $object->get('lastName');
        $records[$i]['username'] = $object->get('username');
        $records[$i]['email'] = $object->get('email');
        $records[$i]['following'] = $followers->isFollowing($object->getObjectId());
        //echo $object->getObjectId() . ' - ' . $object->get('username') . '<br>';
    }
    // check for records returned
    if ($records) {
        $response["result"] = "success";
        $response['message'] = count($records) . " users found.";
        $response['items'] = $records;