-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.php
87 lines (82 loc) · 1.98 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
<?php
class User
{
protected $name;
protected $phone;
protected $pin;
protected $balance;
function __construct($phone)
{
$this->phone = $phone;
}
//setters and getter
public function setName($name)
{
$this->name = $name;
}
public function getName()
{
return $this->name;
}
public function getPhone()
{
return $this->phone;
}
public function setPin($pin)
{
$this->pin = $pin;
}
public function getPin()
{
return $this->pin;
}
public function setBalance($balance)
{
$this->balance = $balance;
}
public function getBalance()
{
return $this->balance;
}
public function register($pdo)
{
try {
//hash pin
$hashedPin = password_hash($this->getPin(), PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO user (name, pin, phone, balance) values(?,?,?,?)");
$stmt->execute([$this->getName(), $hashedPin, $this->getPhone(), $this->getBalance()]);
} catch (PDOException $e) {
echo $e->getMessage();
}
}
public function isUserRegistered($pdo)
{
$stmt = $pdo->prepare("SELECT * FROM user WHERE phone=?");
$stmt->execute([$this->getPhone()]);
if (count($stmt->fetchAll()) > 0) {
return true;
} else {
return false;
}
}
public function readName($pdo)
{
$stmt = $pdo->prepare("SELECT * FROM user WHERE phone=?");
$stmt->execute([$this->getPhone()]);
$row = $stmt->fetch();
return $row['name'];
}
public function readUserId($pdo)
{
$stmt = $pdo->prepare("SELECT uid FROM user where phone=?");
$stmt->execute([$this->getPhone()]);
$row = $stmt->fetch();
return $row['uid'] ?? 'default value';
}
public function correctPin($pdo)
{
}
public function checkBalance($pdo)
{
}
}