-
Notifications
You must be signed in to change notification settings - Fork 62
/
account.php
321 lines (292 loc) · 12.6 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<?php
session_start;
include("Assets/php/dbconfig.php");
function alert($msg) {
echo "<script type='text/javascript'>alert('$msg');</script>";
}
function check_pass($i,$dbconfig,$password){
$password=crypt($password, '$2a$07$CCSCodersUnderSiegelul$');
$query=$dbconfig->prepare("SELECT * from {$i}_login where email=? and password=?");
$query->bind_param("ss",$_SESSION['email'],$password);
$query->execute();
$query=$query->get_result();
return $query->num_rows;
}
if(!isset($_SESSION['email']))
header("location:redirect.php");
else
{
{
if($_SERVER['REQUEST_METHOD']=="POST")
{
{
if($_SESSION['user']==1)
$i='user';
else if($_SESSION['admin']==1)
$i='admin';
}
{
if($_POST['submit']=='name')
{
$j=check_pass($i,$dbconfig,$_POST['password']);
if($j==1)
{
$name=mysqli_real_escape_string($dbconfig,$_POST['name']);
$query=$dbconfig->prepare("UPDATE {$i}_login SET name=? where email=?");
$query->bind_param("ss",$name,$_SESSION['email']);
$query->execute();
alert("Name Updated Successfully.");
}
else
alert("Incorrect Password.");
}
else if($_POST['submit']=='enumber')
{
$j=check_pass($i,$dbconfig,$_POST['password']);
if($j==1)
{
$enrollment_number=mysqli_real_escape_string($dbconfig,$_POST['enumber']);
$query=$dbconfig->prepare("UPDATE {$i}_login SET enrollment_number=? where email=?");
$query->bind_param("ss",$enrollment_number,$_SESSION['email']);
$query->execute();
alert("Enrollment Number Updated Successfully.");
}
else
alert("Incorrect Password.");
}
else if($_POST['submit']=='number')
{
$j=check_pass($i,$dbconfig,$_POST['password']);
if($j==1)
{
$number=mysqli_real_escape_string($dbconfig,$_POST['number']);
$query=$dbconfig->prepare("UPDATE {$i}_login SET mobile=? where email=?");
$query->bind_param("ss",$number,$_SESSION['email']);
$query->execute();
alert("Mobile Number Updated Successfully.");
}
else
alert("Incorrect Password.");
}
else if($_POST['submit']=='password')
{
$j=check_pass($i,$dbconfig,$_POST['password']);
if($j==1)
{
$npassword=mysqli_real_escape_string($dbconfig,$_POST['npassword']);
$npassword=crypt($npassword, '$2a$07$CCSCodersUnderSiegelul$');
$query=$dbconfig->prepare("UPDATE {$i}_login SET password=? where email=?");
$query->bind_param("ss",$npassword,$_SESSION['email']);
$query->execute();
alert("Password Updated Successfully.");
}
else
alert("Incorrect Password.");
}
}
}
}
{
if($_SESSION['user']==1)
{
$query=$dbconfig->prepare("SELECT name,enrollment_number,mobile,email FROM user_login WHERE email=?");
}
else
{
$query=$dbconfig->prepare("SELECT name,enrollment_number,mobile,email FROM admin_login WHERE email=?");
}
$query->bind_param("s",$_SESSION['email']);
$query->execute();
$query=$query->get_result();
$row=$query->fetch_assoc();
}
}
?>
<html>
<head>
<meta charset="utf-8">
<title>Creative Computing Society</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
</head>
<body>
<nav class="navbar display-fixed navbar-toggleable-md navbar-inverse navbar-dark bg-dark text-white navbar-expand-lg">
<a class="navbar-brand">HelloWorld</a>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="dashboard.php">Home <span class="sr-only">(current)</span></a>
</li>
<?php
if($_SESSION['user']==1)
{ echo '
<li class="nav-item">
<a class="nav-link" href="attempted_contests.php">Attempted Contests</a>
</li>';}
if($_SESSION['admin']==1)
{ echo '
<li class="nav-item">
<a class="nav-link" href="create_contest.php">Create Contest</a>
</li><li class="nav-item">
<a class="nav-link" href="manage_contests.php">Manage Contests</a>
</li>';}
?></ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item dropdown hidden-md-down">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<?php echo $_SESSION['name'] ?>
</a>
<div class="dropdown-menu position-absolute dropdown-menu-right text-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item active" href="account.php">Account</a>
<a class="dropdown-item" href="notification.php">Notifications</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="logout.php">Logout</a>
</div>
</li>
</ul>
</div>
</nav><br><br><br><div class="row"><div class="col-sm-1"></div><h1 class="display-3">Account Details</h1></div><br>
<div id="accordion" class="accordion " >
<div class="card">
<div class="card-header" id="headingOne">
<div class="row"><div class="col-sm-1"></div><div class="col-sm-2 h5 font-weight-bolder">Name:</div><div class="col-sm-7 h6"><?php echo $row['name']; ?></div><div class="col-sm-2">
<button class="btn btn-dark collapsed" data-toggle="collapse" data-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
Change
</button>
</div></div>
</div>
<div id="collapseOne" class="collapse" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
<form method="post" action="account.php">
<div class="form-group">
<label for="exampleInputEmail1">Name</label>
<input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter Name" name="name" required>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password" name="password" required>
</div>
<button type="submit" class="btn btn-primary" name="submit" value="name">Update</button>
</form>
</div>
</div> </div>
<div class="card">
<div class="card-header" id="headingTwo">
<div class="row"><div class="col-sm-1"></div><div class="col-sm-2 h5 font-weight-bolder">Enrollment Number:</div><div class="col-sm-7 h6"><?php echo $row['enrollment_number']; ?></div><div class="col-sm-2">
<button class="btn collapsed btn-dark" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Change
</button>
</div></div>
</div>
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordion">
<div class="card-body">
<form method="post" action="account.php">
<div class="form-group">
<label for="exampleInputEmail1">Enrollment Number</label>
<input type="text" class="form-control" id="enumber" aria-describedby="emailHelp" placeholder="Enrollment-Number" name="enumber" onKeyUp="check2();" required>
</div><span id="message2"></span>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password" name="password" required>
</div>
<button type="submit" class="btn btn-primary" name="submit" value="enumber">Update</button>
</form>
</div>
</div> </div>
<div class="card">
<div class="card-header" id="headingThree">
<div class="row"><div class="col-sm-1"></div><div class="col-sm-2 h5 font-weight-bolder">Mobile Number:</div><div class="col-sm-7 h6"><?php echo $row['mobile']; ?></div><div class="col-sm-2">
<button class="btn btn-dark collapsed" data-toggle="collapse" data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
Change
</button>
</div></div>
</div>
<div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordion">
<div class="card-body">
<form method="post" action="account.php">
<div class="form-group">
<label for="exampleInputEmail1">Mobile Number</label>
<input type="text" class="form-control" id="number" aria-describedby="emailHelp" placeholder="Mobile Number" name="number" onKeyUp="check();" required>
</div><span id="message"></span>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password" name="password" required>
</div>
<button type="submit" class="btn btn-primary" name="submit" value="number">Update</button>
</form>
</div>
</div> </div>
<div class="card">
<div class="card-header" id="headingFour">
<div class="row"><div class="col-sm-1"></div><div class="col-sm-2 h5 font-weight-bolder">Email:</div><div class="col-sm-7 h6"><?php echo $row['email']; ?></div><div class="col-sm-2">
<button class="btn btn-dark collapsed" data-toggle="collapse" data-target="#collapseFour" aria-expanded="false" aria-controls="collapseFour">
Change
</button>
</div></div>
</div>
<div id="collapseFour" class="collapse" aria-labelledby="headingFour" data-parent="#accordion">
<div class="card-body">
This facility isn't currently available.
</div>
</div> </div>
<div class="card">
<div class="card-header" id="headingFive">
<div class="row"><div class="col-sm-1"></div><div class="col-sm-2 h5 font-weight-bolder">Password:</div><div class="col-sm-7 h6">As if we'll tell you that.</div><div class="col-sm-2">
<button class="btn btn-dark collapsed" data-toggle="collapse" data-target="#collapseFive" aria-expanded="false" aria-controls="collapseFive">
Change
</button>
</div></div>
</div>
<div id="collapseFive" class="collapse" aria-labelledby="headingFive" data-parent="#accordion">
<div class="card-body">
<form method="post" action="account.php">
<div class="form-group">
<label for="exampleInputEmail1">Current Password</label>
<input type="password" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter Current Password" name="password" required>
</div>
<div class="form-group">
<label for="exampleInputPassword1">New Password</label>
<input type="password" class="form-control" id="password" placeholder="New Password" name="npassword" required>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Confirm Password</label>
<input type="password" class="form-control" id="confirm_password" placeholder="Re-Enter New Password" onKeyUp="check1();" required >
</div><span id="message1"></span><br>
<button type="submit" class="btn btn-primary" name="submit" value="password">Update</button>
</form>
</div>
</div> </div>
</div>
</div>
</body>
</html>
<script type="text/javascript">
var check = function(){var val = document.getElementById('number').value
if (val.match(/^\d{10}$/)) {
document.getElementById('message').innerHTML = '';
return false;
} else {
document.getElementById('message').style.color = 'red';
document.getElementById('message').innerHTML = 'Please enter a 10 digit Mobile Number.';
return false;
}}
var check1 = function() {
if (document.getElementById('password').value ==
document.getElementById('confirm_password').value) {
document.getElementById('message1').innerHTML = '';
} else {
document.getElementById('message1').style.color = 'red';
document.getElementById('message1').innerHTML = 'Passwords Do Not Match';
}
}
var check2 = function(){var val = document.getElementById('enumber').value
if (val.match(/^\d{9}$/)) {
document.getElementById('message2').innerHTML = '';
return false;
} else {
document.getElementById('message2').style.color = 'red';
document.getElementById('message2').innerHTML = 'Please enter a 9 digit Enrollment Number.';
return false;
}}</script>