PHP Classes

File: app/UserRouter.php

Recommend this page to a friend!
  Classes of Rodrigo Faustino   Back FaceX   app/UserRouter.php   Download  
File: app/UserRouter.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Back FaceX
Recognize students using their face pictures
Author: By
Last change:
Date: 4 months ago
Size: 2,301 bytes
 

Contents

Class file image Download
<?php

namespace App;

require
"../vendor/autoload.php";

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST, DELETE, PUT, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
if (
$_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    exit(
0);
}

use
App\Database\Conexao;
use
App\Database\UserDAO;
use
App\Model\User;
use
App\Controller\UserController;

$conexao = Conexao::getConexao();
$userDAO = new UserDAO($conexao);
$userController = new UserController($userDAO);

$body = json_decode(file_get_contents('php://input'), true);

switch (
$_SERVER["REQUEST_METHOD"]) {
    case
"POST":
       
$resultado = '';
        if (isset(
$body['acao'])) {
           
$user = new User();
            switch (
$body['acao']) {
                case
'cadastrar':
                   
$user->setNome($body['nome']);
                   
$user->setRegistro($body['registro']);
                   
$user->setRostos($body['rosto']);
                   
$resultado = $userController->inserir($user);
                    break;
                case
'registrar':
                   
$user->setNome($body['nome']);
                   
$user->setRegistro($body['registro']);
                   
$user->setEmail($body['email']);
                   
$user->setSenha($body['senha']);
                   
$resultado = $userController->registrar($user);
                    break;
                case
'login':
                   
$user->setEmail($body['email']);
                   
$user->setSenha($body['senha'],'S');
                   
$resultado = $userController->login($user);
                    break;
            }
        }
        echo
json_encode($resultado);
        break;
    case
"GET":
        if (isset(
$_GET['relatorio'])) {
           
$resultado = $userController->buscarTodos();
            echo
json_encode(["usuarios" => $resultado]);
        } else {
           
$id = $_GET['id'] ?? null;
           
$resultado = $userController->buscarPorId($id);
            echo
json_encode(["usuarios" => $resultado]);
        }
        break;
    case
"DELETE":
       
$id = $_GET['id'] ?? '';
       
$resultado = $userController->excluir($id);
        echo
json_encode($resultado);
        break;
}