-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.php
113 lines (99 loc) · 3.17 KB
/
settings.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
<?php
session_start();
$mysqli = new mysqli("mysql.cis.ksu.edu", "markloev", "pcEkhG5B5kg8XExJ%RD", "markloev");
if(isset($_GET['username'])){
echo "<div class='alert alert-success'>
<strong>Success! </strong>You have successfully updated your username.
</div>";
}
if(isset($_POST['confirmNewUsername'])){
$username = $_POST['newUsername'];
$query = "SELECT username FROM Users";
$result = $mysqli->query($query);
$array = r2aSettings($result);
$taken = false;
foreach($array as $a){
if($username == $a['username']){
$taken = true;
}
}
if(!$taken){
$query = "UPDATE Users SET username='".$username."' WHERE username='".$_SESSION['user']['username']."'";
$mysqli->query($query);
$_SESSION['user']['username'] = $username;
header("settings.php?username=true");
}
}
if(isset($_POST['confirmNewPassword'])){
$password = $_POST['confirmPassword'];
$query = "UPDATE Users SET password='".$password."' WHERE username='".$_SESSION['user']['username']."'";
$mysqli->query($query);
echo "<div class='alert alert-success'>
<strong>Success! </strong>You have successfully updated your password.
</div>";
}
include('includes/header.php');
?>
<style>
.btn{
width: 15%;
}
#usernameSection, #passwordSection{
display: none;
}
input[type="text"], input[type="password"]{
width: 300px;
}
</style>
<button class='btn btn-primary' id="changeUsername" name="changeUsername">Change Username</button>
<button class='btn btn-primary' id="changePassword" name="changePassword">Change Password</button>
<br><br>
<form method="post">
<div id="usernameSection">
<label>New Username</label>
<input type="text" class="form-control" id="newUsername" name="newUsername"><br>
<input type="submit" class="btn btn-primary form-control" id="confirmNewUsername" name="confirmNewUsername">
</div>
<div id="passwordSection">
<label>New Password</label>
<input type="password" class="form-control" id="password" name="password">
<label>Confirm New Password</label>
<input type="password" class="form-control" id="confirmPassword" name="confirmPassword">
<label id="match"></label><br><br>
<input type="submit" disabled class="btn btn-primary" id="confirmNewPassword" name="confirmNewPassword">
</div>
</form>
<?php
include('includes/footer.php');
function r2aSettings($r) {
$a = array();
while($row = mysqli_fetch_assoc($r)) {
$a[] = $row;
}
return $a;
}
?>
<script>
$("#changeUsername").click(function(){
$("#usernameSection").css("display", "block");
$("#passwordSection").css("display", "none");
})
$("#changePassword").click(function(){
$("#passwordSection").css("display", "block");
$("#usernameSection").css("display", "none");
})
$("#confirmPassword").on('input', function(){
var password = $("#password").val();
var confirmPassword = $("#confirmPassword").val();
if(password==confirmPassword){
$("#match").css("color", "green");
$("#match").text("Passwords match");
$("#confirmNewPassword").removeAttr("disabled");
}
else{
$("#match").css("color", "red");
$("#match").text("Passwords do not match");
$("#confirmNewPassword").attr("disabled","disabled");
}
});
</script>