Esempio n. 1
0
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>
        
        <meta charset="utf-8"/>
        <meta http-equiv="refresh" content="2; url=index.php" />
Esempio n. 2
0
    }
    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) {
        $openGroups = $groupSys->FindGroup($userId);
        $groupSys->AddToGroup($openGroups[0], $userId);
    }
} catch (Exception $e) {
    $error_msg = $e->getMessage();
    $success = false;
}
echo json_encode(array('success' => $success, 'error_msg' => $error_msg));
Esempio n. 3
0
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;
}
echo json_encode(array('success' => $success, 'error_msg' => $error_msg, 'group' => $newGroup));