-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.php
97 lines (85 loc) · 2.85 KB
/
User.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
91
92
93
94
95
96
97
<?php
use Firebase\JWT\JWT;
require "General.php";
use OpenApi\Annotations as OA;
class User extends General{
protected $table = "user";
/**
*@OA\Get(
* path="/users",
* @OA\Response(
* response="200",
* description="Liste des utilisateurs",
* @OA\JsonContent(type="array", description="", @OA\Items(ref="#/components/schemas/User")),
*
*),
*@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="/users",
* @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"
* )
* ),
* )
* )
*/
/**
* Save user
*
* @param array $param
* @return void
*/
public function save($param){
$statement = "INSERT INTO user (nom, prenom, email, password)
VALUES (:nom, :prenom, :email, :password)";
$param["nom"]= htmlspecialchars($param["nom"]);
$param["prenom"]= htmlspecialchars($param["prenom"]);
$param["email"]= htmlspecialchars($param["email"]);
$param["password"]= password_hash($param["password"], PASSWORD_DEFAULT);
$this->db->prepare($statement, 'save', $param);
}
public function connexion ($param){
$statement = "SELECT * FROM user WHERE email='".$param["email"]."'";
$user = $this->db->queryReturn($statement, true);
if (password_verify($param["password"], $user->password)) {
$key = "demo";
$payload = array(
"exp" => time() * 600,
"email" => $user->email,
);
$jwt = JWT::encode($payload, $key);
$this->app->sendData("connexion réussie", true, $jwt);
}
else{
$this->app->sendData("erreur de connexion");
}
}
}