-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.php
148 lines (140 loc) · 4.6 KB
/
profile.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
use Pico\Data\Entity\User;
use Pico\Request\PicoFilterConstant;
use Pico\Request\PicoRequest;
use Pico\Utility\UserUtil;
require_once "inc/auth-with-login-form.php";
$inputGet = new PicoRequest(INPUT_GET);
$inputPost = new PicoRequest(INPUT_POST);
if($inputGet->equalsAction(PicoRequest::ACTION_EDIT) && $inputPost->getSave() == 'save')
{
$inputPost->filterName(PicoFilterConstant::FILTER_SANITIZE_SPECIAL_CHARS);
$inputPost->filterUsername(PicoFilterConstant::FILTER_SANITIZE_ALPHANUMERICPUNC);
$inputPost->filterEmail(PicoFilterConstant::FILTER_SANITIZE_EMAIL);
$userId = $currentLoggedInUser->getUserId();
$user = new User(null, $database);
$user->setUserId($userId);
$password = $inputPost->getPassword();
if(!empty($password))
{
$hashPassword = hash('sha256', $inputPost->getPassword());
$user->setPassword($hashPassword);
$_SESSION['spass'] = $hashPassword;
}
$user->setName($inputPost->getName());
$user->setBirthDay($inputPost->getBirthDay());
$user->setGender($inputPost->getGender());
$username = $inputPost->getUsername();
if(!empty($username) && !UserUtil::isDuplicatedUsername($database, $userId, $username))
{
$user->setUsername($username);
$_SESSION['suser'] = $username;
}
$email = $inputPost->getEmail();
if(!empty($email) && !UserUtil::isDuplicatedEmail($database, $userId, $email))
{
$user->setEmail($email);
}
$user->setTimeEdit(date('Y-m-d H:i:s'));
$user->setAdminEdit($userId);
$user->setIpEdit($_SERVER['REMOTE_ADDR']);
$user->update();
header('Location: '.basename(($_SERVER['PHP_SELF'])));
}
if($inputGet->equalsAction(PicoRequest::ACTION_EDIT))
{
require_once "inc/header.php";
$user = new User(null, $database);
try
{
$user->findOneByUserId($currentLoggedInUser->getUserId());
?>
<form action="" method="post">
<table class="table table-responsive">
<tbody>
<tr>
<td>Name</td>
<td><input type="text" class="form-control" name="name" id="name" value="<?php echo $user->getName();?>" autocomplete="off"></td>
</tr>
<tr>
<td>Gender</td>
<td><select class="form-control" name="gender" id="gender">
<option value="M"<?php echo $user->getGender() == 'M' ? ' selected':'';?>>Man</option>
<option value="W"<?php echo $user->getGender() == 'W' ? ' selected':'';?>>Woman</option>
</select></td>
</tr>
<tr>
<td>Birth Day</td>
<td><input type="date" class="form-control" name="birth_day" id="birth_day" value="<?php echo $user->getBirthDay();?>" autocomplete="off"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="email" class="form-control" name="email" id="email" value="<?php echo $user->getEmail();?>" autocomplete="off"></td>
</tr>
<tr>
<td>Username</td>
<td><input type="text" class="form-control" name="username" id="username" value="<?php echo $user->getUsername();?>" autocomplete="off"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" class="form-control" name="password" id="password" value="" autocomplete="off"></td>
</tr>
</tbody>
</table>
<input type="hidden" name="save" value="save">
<button type="submit" class="btn btn-success">Update</button>
<button type="button" class="btn btn-primary" onclick="window.location='profile.php'">Cancel</button>
</form>
<?php
}
catch(Exception $e)
{
// do something here
}
require_once "inc/footer.php";
}
else
{
require_once "inc/header.php";
$user = new User(null, $database);
try
{
$user->findOneByUserId($currentLoggedInUser->getUserId());
?>
<table class="table table-responsive">
<tbody>
<tr>
<td>User ID</td>
<td><?php echo $user->getUserId();?></td>
</tr>
<tr>
<td>Username</td>
<td><?php echo $user->getUsername();?></td>
</tr>
<tr>
<td>Name</td>
<td><?php echo $user->getName();?></td>
</tr>
<tr>
<td>Gender</td>
<td><?php echo $user->getGender() == 'M' ? 'Man' : 'Woman';?></td>
</tr>
<tr>
<td>Birth Day</td>
<td><?php echo $user->getBirthDay();?></td>
</tr>
<tr>
<td>Email</td>
<td><?php echo $user->getEmail();?></td>
</tr>
</tbody>
</table>
<button type="button" class="btn btn-primary" onclick="window.location='profile.php?action=edit'">Edit</button>
<?php
}
catch(Exception $e)
{
// do something here
}
require_once "inc/footer.php";
}