Exemplo n.º 1
0
<?php

require_once '../php/Connection.php';
require_once '../php/GroupSystem.php';
$db = new Connection();
$groupSys = new GroupSystem($db);
echo $groupSys->is_member(1, 60);
echo '<hr>' . $groupSys->error;
Exemplo n.º 2
0
require_once '../php/LoginSystem.php';
require_once '../php/PostSystem.php';
require_once '../php/GroupSystem.php';
$success = false;
$error_msg = 'msg';
try {
    if (!($params = json_decode(file_get_contents('php://input')))) {
        throw new Exception("Couldn't decode incoming data!");
    }
    if (!($db = new Connection())) {
        throw new Exception("Couldn't connect to database!");
    }
    if (!($loginSys = new LoginSystem($db))) {
        throw new Exception("Couldn't connect to login system!");
    }
    if (!($groupSys = new GroupSystem($db))) {
        throw new Exception("Couldn't connect to group system!");
    }
    if (!($postSys = new PostSystem($db))) {
        throw new Exception("Couldn't connect to post system!");
    }
    if (!($params->post_id && $params->content)) {
        throw new Exception("Missing parameters!");
    } else {
        $user_id = $loginSys->user['id'];
        $post_id = $params->post_id;
        $content = $params->content;
        $group_id = $postSys->GetPost($post_id)['group_id'];
        // get group id directly from post to verify user's membership
        // Verify that user is a member of group
        if (!$groupSys->is_member($group_id, $user_id)) {
Exemplo n.º 3
0
$members = array();
try {
    // Test Parameters
    if (!isset($_GET['group_id'])) {
        throw new Exception("Request not received!");
    } else {
        $group_id = $_GET['group_id'];
    }
    // Setup API
    if (!($db = new Connection())) {
        throw new Exception("Couldn't connect to database!");
    }
    if (!($loginSys = new LoginSystem($db))) {
        throw new Exception("Couldn't connect to login system!");
    }
    if (!($groupSys = new GroupSystem($db))) {
        throw new Exception("Couldn't connect to group system!");
    }
    // Get Group Member Ids
    if (!($memberIds = $groupSys->GetMembers($group_id))) {
        throw new Exception("Couldn't retreive group members!");
    }
    // Get Member Details
    if (!($members = $loginSys->GetUsers($memberIds))) {
        throw new Exception("Couldn't retreive member details!");
    }
    // Prepare output array
    $output = array();
    foreach ($members as $member) {
        array_push($output, array('id' => $member['id'], 'handle' => $member['handle']));
    }
Exemplo n.º 4
0
    } else {
        $group_id = $_GET['group_id'];
        $oldest_post_id = $_GET['oldest_post_id'];
        $last_update = $_GET['last_update'];
    }
    // Setup API
    if (!($db = new Connection())) {
        throw new Exception("Couldn't connect to database!");
    }
    if (!($loginSys = new LoginSystem($db))) {
        throw new Exception("Couldn't connect to login system!");
    }
    if (!($postSys = new PostSystem($db))) {
        throw new Exception("Couldn't connect to post system!");
    }
    if (!($groupSys = new GroupSystem($db))) {
        throw new Exception("Couldn't connect to group system!");
    }
    // Verify that user is member of group
    if (!$groupSys->is_member($group_id, $loginSys->user['id'])) {
        throw new Exception("User isn't a member of requested group!");
    }
    // Get Posts
    if (!($posts = $postSys->GetPostUpdate($group_id, $oldest_post_id, $last_update))) {
        throw new Exception($postSys->error);
    }
} catch (Exception $e) {
    $error_msg = $e->getMessage();
    $success = false;
}
echo json_encode(array('success' => $success, 'error_msg' => $error_msg, 'posts' => $posts));
Exemplo n.º 5
0
require_once '../php/Connection.php';
require_once '../php/LoginSystem.php';
require_once '../php/GroupSystem.php';
$success = true;
$error_msg = '';
try {
    if (!($params = json_decode(file_get_contents('php://input')))) {
        throw new Exception("Couldn't decode incoming data!");
    }
    if (!($db = new Connection())) {
        throw new Exception("Couldn't connect to database!");
    }
    if (!($loginSys = new LoginSystem($db))) {
        throw new Exception("Couldn't connect to login system!");
    }
    if (!($groupSys = new GroupSystem($db))) {
        throw new Exception("Couldn't connect to group system!");
    }
    if (!($params->user && $params->pass)) {
        throw new Exception('Form incomplete!');
    }
    // Login
    $user = $params->user;
    $pass = $params->pass;
    if (!($success = $loginSys->Login($user, $pass))) {
        throw new Exception('Wrong username/password!');
    }
    // Find a group for user if not a member of any.
    $userId = $loginSys->user['id'];
    $userGroups = $groupSys->GetUserGroups($userId);
    if (count($userGroups) == 0) {
Exemplo n.º 6
0
<?php

if (isset($_GET['group'])) {
    require_once '../php/Connection.php';
    require_once '../php/LoginSystem.php';
    require_once '../php/GroupSystem.php';
    $db = new Connection();
    $loginSys = new LoginSystem($db);
    $groupSys = new GroupSystem($db);
    $userGroups = $groupSys->GetUserGroups($loginSys->user['id']);
    foreach ($userGroups as $group) {
        if ($group == $_GET['group']) {
            // user is in group
            $loginSys->SelectGroup($_GET['group']);
            break;
        }
    }
}
// Redirect back
header('Location: index.php');
Exemplo n.º 7
0
require_once '../php/GroupSystem.php';
require_once '../php/PostSystem.php';
$success = true;
$error_msg = '';
try {
    // Test Parameters
    if (!isset($_GET['group_id'])) {
        throw new Exception("Parameters not received!");
    }
    if (!($db = new Connection())) {
        throw new Exception("Couldn't connect to database!");
    }
    if (!($loginSys = new LoginSystem($db))) {
        throw new Exception("Couldn't connect to login system!");
    }
    if (!($groupSys = new GroupSystem($db))) {
        throw new Exception("Couldn't connect to group system!");
    }
    if (!($postSys = new PostSystem($db))) {
        throw new Exception("Couldn't connect to post system!");
    }
    // Set Variables
    $group_id = $_GET['group_id'];
    $user_id = $loginSys->user['id'];
    if (!$groupSys->is_member($group_id, $user_id)) {
        throw new Exception("Not a member of group.");
    }
    if (!$groupSys->RemoveFromGroup($group_id, $user_id)) {
        throw new Exception("Couldn't remove from group!");
    }
    if (!$postSys->RemoveAllUserPosts($group_id, $user_id)) {
Exemplo n.º 8
0
<?php

require_once '../php/Connection.php';
require_once '../php/LoginSystem.php';
require_once '../php/GroupSystem.php';
$db = new Connection();
$loginSys = new LoginSystem($db);
$groupSys = new GroupSystem($db);
$success = false;
if (isset($_POST['user'], $_POST['pass1'], $_POST['pass2'], $_POST['email'], $_POST['name'], $_POST['location'], $_POST['birthdate'])) {
    // Register New User
    $success = $loginSys->Register($_POST['user'], $_POST['pass1'], $_POST['pass2'], $_POST['email'], $_POST['name'], $_POST['location'], $_POST['birthdate']);
    // Login
    if ($success) {
        // Login
        $loginSys->Login($_POST['user'], $_POST['pass1']);
        // Find group
        if ($openGroups = $groupSys->FindGroup($loginSys->user['id'])) {
            if ($groupSys->AddToGroup($openGroups[0], $loginSys->user['id'])) {
                $loginSys->SetDefaultGroup($openGroups[0]);
                $loginSys->SelectGroup($openGroups[0]);
            }
        }
    }
}
?>
<!doctype html>
<html>
    <head>
        <title>Register</title>
        
Exemplo n.º 9
0
<?php

require_once '../php/Connection.php';
require_once '../php/LoginSystem.php';
require_once '../php/GroupSystem.php';
$success = true;
$error_msg = '';
try {
    if (!($db = new Connection())) {
        throw new Exception("Couldn't connect to database!");
    }
    if (!($loginSys = new LoginSystem($db))) {
        throw new Exception("Couldn't connect to login system!");
    }
    if (!($groupSys = new GroupSystem($db))) {
        throw new Exception("Couldn't connect to group system!");
    }
    // Find a group for user if not a member of any.
    if (!($userId = $loginSys->user['id'])) {
        throw new Exception("Not logged in!");
    }
    if (!($newGroup = $groupSys->FindGroup($userId))) {
        throw new Exception($groupSys->error);
    }
    if (!$groupSys->AddToGroup($newGroup, $userId)) {
        throw new Exception("Couldn't add new group!");
    }
} catch (Exception $e) {
    $error_msg = $e->getMessage();
    $success = false;
}
Exemplo n.º 10
0
<?php

require_once '../php/Connection.php';
require_once '../php/LoginSystem.php';
require_once '../php/GroupSystem.php';
$success = true;
$error_msg = '';
$groups = array();
try {
    // Setup API
    if (!($db = new Connection())) {
        throw new Exception("Couldn't connect to database!");
    }
    if (!($loginSys = new LoginSystem($db))) {
        throw new Exception("Couldn't connect to login system!");
    }
    if (!($groupSys = new GroupSystem($db))) {
        throw new Exception("Couldn't connect to group system!");
    }
    // Get user groups
    if (!($groups = $groupSys->getUserGroups($loginSys->user['id']))) {
        throw new Exception("Couldn't retreive user groups!");
    }
} catch (Exception $e) {
    $error_msg = $e->getMessage();
    $success = false;
}
echo json_encode(array('success' => $success, 'error_msg' => $error_msg, 'groups' => $groups));
Exemplo n.º 11
0
<?php

require_once '../php/Connection.php';
require_once '../php/LoginSystem.php';
require_once '../php/GroupSystem.php';
require_once '../php/PostSystem.php';
require_once '../php/Time.php';
$db = new Connection();
$loginSys = new LoginSystem($db);
$groupSys = new GroupSystem($db);
$postSys = new PostSystem($db);
// Not logged in
if (!$loginSys->user) {
    ?>

<!doctype html>
<html>
    <head>
        <meta http-equiv="refresh" content="0; url=/"/>
    </head>
    <body></body>
</html>

<?php 
    // Logged in
} else {
    // Get Associated groups
    $groups = $groupSys->GetUserGroups($loginSys->user['id']);
    // Get Group Members
    $members = $loginSys->GetUsers($groupSys->GetMembers($loginSys->group_id));
    // Get group posts