-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignup.php
More file actions
56 lines (45 loc) · 1.59 KB
/
signup.php
File metadata and controls
56 lines (45 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
// required headers
// header("Access-Control-Allow-Origin: http://localhost/FastshopApiProvider/");
header("Access-Control-Allow-Origin: https://aqueous-fjord-12024.herokuapp.com/");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
//Obtener archivos para la conexion
include_once 'config/database.php';
include_once 'objects/cliente.php';
//Obtener datos de POST desde un JSON
$data = json_decode(file_get_contents("php://input"));
//Corroboramos primero que se haya especificado cliente and pass
if($data->email && $data->password){
//Obtener conexion con DB
$database = new Database();
$db = $database->getConnection();
//Instanciar cliente
$cliente = new Cliente($db);
// Setear valored de cliente
$cliente->nombre = $data->nombre;
$cliente->apellido = $data->apellido;
$cliente->email = $data->email;
$cliente->password = $data->password;
//Creamos el cliente
if($cliente->create()){
// set response code
http_response_code(200);
//Mostramos mensaje
echo json_encode(array("message" => "Cliente creado!"));
}
//Mensaje sino se pudo crear
else{
//Seteamos estado
http_response_code(400);
echo json_encode(array("message" => "El cliente ya existe"));
}
}
else{
//Seteamos estado
http_response_code(400);
echo json_encode(array("message" => "Se requieren datos"));
}
?>