예제 #1
0
<?php

require_once 'app/start.php';
session_start();
$autenticacaoService = new AutenticacaoService();
if ($autenticacaoService->login_check($mysqli) == true) {
    $logged = 'in';
} else {
    $logged = 'out';
}
if ($logged == 'out') {
    header('Location: ' . '/projetosappataria');
    die;
}
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="" />
    <meta name="author" content="" />
    <!-- Favicon Icon -->
    <link rel="icon" href="" />
    <title>Sappataria</title>
    
    	<!-- css: bootstrap -->
	<link rel="stylesheet" href="plugins/bootstrap/css/bootstrap.min.css">
   	<link rel="stylesheet" href="plugins/bootstrap-datepicker/css/datepicker3.css" />
   	<link rel="stylesheet" href="plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css">
   	
<?php

require_once '../start.php';
$usuarioDAO = new UsuarioDAO();
$autenticacaoService = new AutenticacaoService();
if (isset($_POST['service'])) {
    if ($_POST['service'] == 'login') {
        if (isset($_POST['email'], $_POST['p'])) {
            $email = $_POST['email'];
            $password = $_POST['p'];
            // The hashed password.
            if ($autenticacaoService->login($email, $password, $mysqli) == true) {
                // header('Location: ../index.php');
                echo json_encode(array('retorno' => 'sucesso'));
            } else {
                // Login failed
                // header('Location: ../index.php');
                echo json_encode(array('retorno' => 'fracasso'));
            }
        } else {
            // The correct POST variables were not sent to this page.
            echo json_encode(array('retorno' => 'invalid Request'));
        }
    } else {
        if ($_POST['service'] == 'logout') {
            session_start();
            $_SESSION = array();
            if (ini_get("session.use_cookies")) {
                $params = session_get_cookie_params();
                setcookie(session_name(), '', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"]);
            }