-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient.php
90 lines (79 loc) · 2.66 KB
/
Client.php
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
require "General.php";
use OpenApi\Annotations as OA;
class Client extends General{
/**
*@OA\Get(
* path="/clients",
* @OA\Response(
* response="200",
* description="Connecté",
* @OA\JsonContent(type="array", description="", @OA\Items(ref="#/components/schemas/Client")),
*
*),
*@OA\Response(
* response="404",
* description="Erreur 404",
* @OA\JsonContent(
* @OA\Property(
* property="message",
* type="string",
* example="Utilisateur ou mots de passe incorrecte"
* )
* ),
* )
*)
* @OA\Post(
* path="/clients",
* @OA\Response(
* response="200",
* description="Compte enregistré",
* @OA\JsonContent(
* @OA\Property(
* property="message",
* type="string",
* example="Données sauvegardées"
* )
* )
* ),
* @OA\Response(
* response="404",
* description="Erreur 404",
* @OA\JsonContent(
* @OA\Property(
* property="message",
* type="string",
* example="Il y a eux un problème lors de la création"
* )
* ),
* )
*)
*/
/**
* Client connexion
*
* @param array $param
*/
public function connexion($param)
{
$statement = ("SELECT * FROM client WHERE nom='". $param["nom"] ."'");
$client = $this->db->queryReturn($statement, true);
if (password_verify($param["password"], $client["password"])) {
$this->app->sendData("connexion ok", true, $client["secret_api_key"]);
}
}
/**
* Save client in Db
*
* @param array $param
* @return void
*/
public function save($param){
$statement = "INSERT INTO $this->table (api_key, role, nom, password)
VALUES (:api_key, :role, :nom, :password )";
$param["password"] = password_hash($param["password"], PASSWORD_DEFAULT);
$param["role"] = json_encode(["EXTERNE"]);
$param["secret_api_key"] = md5(uniqid());
$this->db->prepare($statement, "save", $param);
}
}