Exemplo n.º 1
0
<?php

require_once __DIR__ . '../../../../businessLogic/business.php';
$business = new business();
if (isset($_COOKIE['auth'])) {
    $token = $_COOKIE['auth'];
    $id;
    $info = $business->check_token($token);
    if ($info != FALSE) {
        $user = $business->view_user($info['id']);
        $username = $user['loginId'];
        $usertype = $business->get_user_type($username);
        if ($usertype == 'admin') {
            header('Location: ./../root.admin.companies.list/list.php');
            exit;
        } else {
            echo '<script>console.log("not authorized");</script>';
            header('Location: ./../root.login/login.php');
            exit;
        }
    } else {
        echo '<script>console.log("wrong token");</script>';
        header('Location: ./../root.login/login.php');
        exit;
    }
} else {
    echo '<script>console.log("no token found");</script>';
    header('Location: ./../root.login/login.php');
    exit;
}
Exemplo n.º 2
0
if (isset($_POST['login']) && !empty($_POST['username']) && !empty($_POST['password'])) {
    if ($business->check_password($_POST['username'], $_POST['password'])) {
        $duration = 86400 * 30;
        $token = $business->generate_token();
        $business->create_token($_POST['username'], $token, time(), $duration);
        if (isset($_POST['rememberme'])) {
            setcookie('auth', $token, time() + $duration, '/');
        } else {
            setcookie('auth', $token, 0, '/');
        }
        echo '
                    <div class="alert alert-success">
                      <label>Valid use name and password</label>
                    </div>
                  ';
        if ($business->get_user_type($_POST['username']) == "student") {
            header('Location: .\\..\\root.student\\student.php');
            exit;
        } else {
            if ($business->get_user_type($_POST['username']) == "company") {
                header('Location: .\\..\\root.company\\company.php?company=' . $_POST['username']);
                exit;
            } else {
                if ($business->get_user_type($_POST['username']) == "admin") {
                    header('Location: .\\..\\root.admin\\admin.php');
                    exit;
                } else {
                    echo '
                      <div class="alert alert-danger">
                        <label>Unknown error</label>
                      </div>