-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount.php
214 lines (197 loc) · 6.25 KB
/
account.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
include ('dbc.php');
session_start();
$msg='';
if(!isset($_SESSION["user_id"])){
header("location:login.php");
}else{
$id = $_SESSION['user_id'];
$dataQuery = "SELECT * FROM users WHERE user_id=:id";
$dataStatement = $dbc->prepare($dataQuery);
$dataStatement->execute(array(":id"=>$id));
$row = $dataStatement->fetch(PDO::FETCH_ASSOC);
$email = $row['email'];
$username = $row['userName'];
}
if(isset($_POST['resetpass'])){
$id = $_SESSION['user_id'];
$password1 = $_POST['pass'];
$password2 = $_POST['confirm-pass'];
$passwordHashed = password_hash($password2, PASSWORD_DEFAULT);
$uppercase = preg_match('@[A-Z]@', $password1);
$lowercase = preg_match('@[a-z]@', $password1);
$number = preg_match('@[0-9]@', $password1);
if(!$uppercase || !$lowercase || !$number || strlen($password2) < 8) {
echo "<br>Password should have at least 8 characters in length and should include at least one upper case letter and one number.";
}elseif($password1 != $password2){
echo "<br>The passwords do not match!";
}else{
$query ="UPDATE users SET password=:upass WHERE user_id=:uid";
$stmt = $dbc->prepare($query);
$stmt->execute(array(":upass"=>$passwordHashed, ":uid"=>$id));
echo "Password changed successfully!";
header("refresh:5;");
}
}elseif(isset($_POST['newusername'])){
$id = $_SESSION['user_id'];
$newName = $_POST['newUsername'];
$username = get_user_name($id, $dbc);
$uNameCheck = "SELECT * FROM users WHERE userName=:username";
$statement1 = $dbc->prepare($uNameCheck);
$statement1->execute(array(':username'=> $newName));
$rowcount = $statement1->rowCount();
if($rowcount == 0){
$query ="UPDATE users SET userName=:uname WHERE user_id=:uid";
$stmt = $dbc->prepare($query);
$stmt->execute(array(":uname"=>$newName, ":uid"=>$id));
echo "Username changed successfully!";
//header("refresh:5;");
}elseif($rowcount > 0){
echo "Sorry, the username is already used!";
}
}/*elseif(isset($_POST['newemail'])){
$id = $_SESSION['user_id'];
$newEmail = $_POST['newEmail'];
$username = get_user_name($id, $dbc);
$uNameCheck = "SELECT * FROM users WHERE email=:email";
$statement1 = $dbc->prepare($uNameCheck);
$statement1->execute(array(':email'=> $newEmail));
$rowcount = $statement1->rowCount();
if($rowcount == 0){
$query ="UPDATE users SET email=:email WHERE user_id=:uid";
$stmt = $dbc->prepare($query);
$stmt->execute(array(":email"=>$newEmail, ":uid"=>$id));
echo "One last step confirm the email adress!";
header("refresh:5;");
}else{
echo "Email is being used by another account please try different email adress!";
}
}*/
?>
<html>
<head>
<title>Account</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
</head>
<body>
<div align="center" class="menu">
<h1>SPECIAL SOCIAL</h1>
<h3>Account</h3>
<ul>
<li><a href="./home.php">Home</a></li>
<li><a href="./newgroup.php">New group</a></li>
<li ><a class="active" href="./account.php">Account</a></li>
<li style="float: right;"><a href="./logout.php">Logout</a></li>
</ul>
</div>
<table align="center"class="udaje">
<tr>
<th>Username:</th>
<td><?php echo $username;?></td>
</tr>
<tr>
<th>Email:</th>
<td><?php echo $email ?></td>
</tr>
</table>
<p class="forms">
<details>
<summary>Change the password</summary>
<form method="POST">
<br><input type="password" name="pass" placeholder="Password">
<br><input type="password" name="confirm-pass" placeholder="Confirm password">
<br><button type="submit" name="resetpass">Change</button>
</form>
</details>
<details>
<summary>Change the username</summary>
<form method="POST">
<br><input type="text" name="newUsername" placeholder="New username">
<br><button type="submit" name="newusername">Change</button>
</form>
</details>
<!--<details>
<summary>To change email adress *CLICK*</summary>
<form method="POST">
<br><input type="email" name="newEmail" placeholder="New email">
<br><button type="submit" name="newemail">Change</button>
</form>
</details>-->
</p>
</body>
</html>
<style>
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@300&display=swap');
th{
color: #6fe0d1;;
}
body{
background-color: #2b3146;
font-family: "Montserrat", sans-serif;
font-size: 16px;
text-align:center;
color: white;
}
.udaje{
color:white;
text-align: left;
padding: 20px;
}
.forms{
color:white;
}
input{
width: 300px;
height: 35px;
border-radius: 5px;
text-align: center;
background-color: #f45b69;
margin: 5px;
color: #fff;
border: none;
}
button {
color: #fff;
font-size: 16px;
margin-left: 10px;
padding: 10px ;
border-radius: 5px;
background-color: #6fe0d1;
text-decoration: none;
text-align: center;
float: center;
border: none;
}
button:hover {
background-color: #ff616f;
border: none;
}
.menu ul {
display: inline-block;
list-style-type: none;
padding: 0;
background-color:rgba(69, 105, 144, 0.73);
top: 75;
width: 80%;
border: 20px #232f5a;
border-radius: 15px 15px 15px 15px;
}
.menu li {
float: left;
}
.menu li a {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.menu li a:hover:not(.active) {
background-color: #6fe0d1;
border-radius: 15px 15px 15px 15px;
}
.menu .active {
background-color: #f45b69;
border-radius: 15px 15px 15px 15px;
}
</style>