Ejemplo n.º 1
0
 public static function login($username)
 {
     require_once "handlers/SessionsHandler.php";
     $user_id = UserHandler::getUserId($username);
     if (!$user_id) {
         $user_id = static::createUser($username);
     }
     SessionsHandler::startSession();
     SessionsHandler::setSessionUser($user_id, $username);
 }
Ejemplo n.º 2
0
<?php

/**
 * Created by PhpStorm.
 * User: Kristaps
 * Date: 11/27/2015
 * Time: 12:01 AM
 */
require_once "handlers/UserHandler.php";
if (isset($_POST['username']) && $_POST['username'] != "") {
    UserHandler::login($_POST['username']);
    SessionsHandler::redirect('chatroom.php');
}
require_once "header.php";
?>

<div class="login-card">
    <h1>Log-in</h1><br>
    <form id="login_form" action="login.php" method="post">
        <input type="text" name="username" placeholder="Username">
        <input type="submit" name="login" class="login button" value="login">
    </form>

    <div class="login-help">
        There is no password
    </div>
</div>

<?php 
require_once "footer.php";
Ejemplo n.º 3
0
 * Time: 1:16 AM
 */
// THIS FILE IS MEANT TO RESPOND TO AJAX REQUESTS
require_once "handlers/SessionsHandler.php";
SessionsHandler::startSession();
SessionsHandler::checkAccess("operations.php");
require_once "handlers/UserHandler.php";
require_once "handlers/ChatHandler.php";
$action = $_GET["action"];
if ($action == "get_active_users") {
    // get users that have been active in the last 30 seconds
    $data = UserHandler::getActiveUsers();
} else {
    if ($action == "logout") {
        SessionsHandler::destroySession();
        SessionsHandler::redirect("login.php");
    } else {
        if ($action == "post") {
            if (isset($_GET["chat_id"]) && isset($_GET["msg"])) {
                $chat_id = $_GET["chat_id"];
                $message = $_GET["msg"];
                $data = ChatHandler::insertMessage(UserHandler::getCurrentUserId(), $chat_id, $message);
            }
        } else {
            if ($action == "get") {
                if (isset($_GET["chat_id"]) && isset($_GET["reload"])) {
                    $chat_id = $_GET["chat_id"];
                    $reload = $_GET["reload"];
                    $data = ChatHandler::getLatestMessages(UserHandler::getCurrentUserId(), $chat_id, $reload);
                }
            } else {
Ejemplo n.º 4
0
<?php

/**
 * Created by PhpStorm.
 * User: Kristaps
 * Date: 11/27/2015
 * Time: 1:15 AM
 */
require_once "handlers/SessionsHandler.php";
SessionsHandler::startSession();
SessionsHandler::checkAccess("chatroom.php");
require_once "handlers/DbHandler.php";
$conn = DbHandler::getConnection();
require_once "handlers/ChatHandler.php";
require_once "handlers/UserHandler.php";
$chatroom_name = UserHandler::getUsername(ChatHandler::PUBLIC_CHAT_ID);
$username = UserHandler::getCurrentUserName();
require_once "header.php";
?>
<div id="chat">
<div id="chat-content">
    <div style="header">
        <h1 id="topic">
            ChatRoom :: <span id="chat_name"><?php 
echo $chatroom_name;
?>
</span>
        </h1>
        click on user for private chat
        <div id="logout">
            <a href="operations.php?action=logout" class="button">
Ejemplo n.º 5
0
<?php

/**
 * Created by PhpStorm.
 * User: Kristaps
 * Date: 11/26/2015
 * Time: 11:39 PM
 */
require_once "handlers/SessionsHandler.php";
SessionsHandler::startSession();
require_once "header.php";
SessionsHandler::redirect("chatroom.php");
require_once "footer.php";