-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.php
133 lines (118 loc) Β· 6.22 KB
/
edit.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
define('APPLICATION', true);
session_start();
require_once('php/class/Autoloader.php');
Autoloader::Register();
if(Toolbox::IsConnected()) {
// Get the success message by $_GET
$message = new Message();
if(isset($_GET['message'])) {
$message->SetSuccess($_GET['message']);
}
$db = new Database();
$res = $db->Execute('SELECT users.password, weights.weight FROM users LEFT OUTER JOIN weights ON weights.id_users = :id AND weights.day = CURDATE() WHERE users.id = :id', array(':id' => Toolbox::GetUser()->ID));
$res = $res->fetch(PDO::FETCH_OBJ);
if(isset($_POST['changeWeight'])) {
$message = $db->InsertUpdateWeight($_POST['valueWeight'], isset($res->weight));
if($message->Status >= 1){
Toolbox::Redirect('edit.php', array('message' => $message->Message));
}
}
// Change password tests
if(isset($_POST['changePassword'])) {
if(Toolbox::ArrayHasValue($_POST, ['oldPassword', 'newPassword', 'confirmPassword'])) {
if(password_verify($_POST['oldPassword'], $res->password)) {
if($_POST['newPassword'] == $_POST['confirmPassword']) {
if(strlen($_POST['newPassword']) >= 4) {
$db->Execute('UPDATE users SET password = ? WHERE id = ?', array(password_hash($_POST['newPassword'], PASSWORD_BCRYPT), Toolbox::GetUser()->ID));
Toolbox::Redirect('edit.php', array('message' => 'Your passdword has been changed'));
} else {
$message->SetError('Your password is too short');
}
} else {
$message->SetError('Passwords do not match');
}
} else {
$message->SetError('Your old password doesn\'t match');
}
} else {
$message->SetError('Fill all fields');
}
}
// Delete weight of today
if(isset($_POST['deleteWeight'])) {
$db->Execute('DELETE FROM weights WHERE id_users = ? AND day = CURDATE()', array(Toolbox::GetUser()->ID));
Toolbox::Redirect('edit.php', array('message' => 'Your weight has been deleted'));
}
require_once('php/inc/header.inc.php');
if(isset($message)) {
$message->Show();
}
?>
<h1 class="text-center">Setting</h1>
<div class="container-fluid weighty-form">
<div class="row justify-content-md-center">
<div class="col-md-3">
<form action="<?= $_SERVER['PHP_SELF'] ?>" method="POST">
<h3>Change your weight of today (kg)</h3>
<div class="form-group">
<input type="text" class="form-control" maxlength="4" placeholder="Enter your weight" name="valueWeight" value="<?= $res ? $res->weight : "" ?>">
</div>
<div class="form-group">
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-4">
<button type="submit" class="btn btn-primary btn-block" name="changeWeight">Change</button>
</div>
<div class="col-md-4">
<button type="button" class="btn btn-secondary btn-block" data-toggle="modal" data-target="#deleteModal">Delete</button>
</div>
<div class="col-md-2"></div>
</div>
</div>
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteModalLabel">Delete</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
You wan't to delete your weight of today ?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
<form action="<?= $_SERVER['PHP_SELF'] ?>" method="POST" class="no-margin-top">
<button type="submit" class="btn btn-danger" name="deleteWeight">Yes, delete</button>
</form>
</div>
</div>
</div>
</div>
</form>
<form action="<?= $_SERVER['PHP_SELF'] ?>" method="POST">
<h3>Change your password</h3>
<div class="form-group">
<input type="password" class="form-control" placeholder="Old password" name="oldPassword">
</div>
<div class="form-group">
<input type="password" class="form-control" placeholder="New password" name="newPassword">
</div>
<div class="form-group">
<input type="password" class="form-control" placeholder="Confirm" name="confirmPassword">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary form-group-center" name="changePassword">Change</button>
</div>
</form>
</div>
</div>
</div>
<?php
require_once('php/inc/end.inc.php');
} else {
Toolbox::Redirect('sign_up.php');
}
?>