Skip to content

Commit f694209

Browse files
committed
account settings, delete-account page update
1 parent 07a188e commit f694209

File tree

8 files changed

+358
-33
lines changed

8 files changed

+358
-33
lines changed

new-g4o2-chat/account-settings.php

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
<?php
2+
require_once "pdo.php";
3+
require_once "head.php";
4+
date_default_timezone_set('Asia/Taipei');
5+
6+
if (!isset($_SESSION["email"])) {
7+
echo "<p align='center'>PLEASE LOGIN</p>";
8+
echo "<br />";
9+
echo "<p align='center'>Redirecting in 3 seconds</p>";
10+
header("refresh:3;url=login.php");
11+
die();
12+
}
13+
if ($_SESSION['email'] == 'guest@guest.com') {
14+
echo "<p align='center'>LOGGED IN AS GUEST ACCOUNT</p>";
15+
echo "<p align='center'>EDIT ACCOUNT DETAILS NOT ALLOWED</p>";
16+
echo "<br />";
17+
echo "<p align='center'>Redirecting in 3 seconds</p>";
18+
header("refresh:3;url=index.php");
19+
die();
20+
}
21+
22+
if (isset($_SESSION["email"])) {
23+
$statement = $pdo->prepare("SELECT * FROM account where user_Id = :usr");
24+
$statement->execute(array(':usr' => $_SESSION['user_id']));
25+
$response = $statement->fetch();
26+
$pfpsrc_default = './img/default-pfp.png';
27+
28+
if ($response['pfp'] != null) {
29+
$userpfp = $response['pfp'];
30+
} else {
31+
$userpfp = $pfpsrc_default;
32+
}
33+
}
34+
35+
if (isset($_POST["submit"])) {
36+
if (!file_exists($_FILES['fileToUpload']['tmp_name']) || !is_uploaded_file($_FILES['fileToUpload']['tmp_name'])) {
37+
$stmta = $pdo->prepare("SELECT pfp FROM account WHERE name=?");
38+
$stmta->execute([$_SESSION['name']]);
39+
$pfptemp = $stmta->fetchAll(PDO::FETCH_ASSOC);
40+
41+
foreach ($pfptemp as $test) {
42+
if ($test['pfp'] != null) {
43+
$base64 = $test['pfp'];
44+
}
45+
}
46+
} else {
47+
$target_dir = "uploads/";
48+
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
49+
$uploadOk = 1;
50+
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
51+
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
52+
$uploadOk = 1;
53+
$path = $_FILES["fileToUpload"]["tmp_name"];
54+
$type = pathinfo($path, PATHINFO_EXTENSION);
55+
$data = file_get_contents($path);
56+
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
57+
}
58+
if ($check !== false) {
59+
$statement = $pdo->prepare("SELECT user_id FROM account where email = :em");
60+
$statement->execute(array(':em' => $_POST['email']));
61+
$checkEmail = $statement->fetch();
62+
63+
if ($checkEmail['user_id'] == $_SESSION['user_id'] || $checkEmail['user_id'] == "") {
64+
$emailCheck = true;
65+
} else {
66+
$emailCheck = false;
67+
}
68+
69+
if ($emailCheck != false) {
70+
if (isset($_POST['password'])) {
71+
$salt = getenv('SALT');
72+
$newPassword = $_POST['password'];
73+
$hash = hash("md5", $salt . $newPassword);
74+
}
75+
if ($_POST["show_email"] == "on") {
76+
$show_email = "True";
77+
} else {
78+
$show_email = "False";
79+
}
80+
81+
$sql = "UPDATE account SET pfp = :pfp,
82+
name = :newName,
83+
email = :email,
84+
password = :password,
85+
about = :about,
86+
show_email = :showEmail
87+
WHERE user_id = :usrid";
88+
$stmt = $pdo->prepare($sql);
89+
$stmt->execute(array(
90+
':pfp' => $base64,
91+
':usrid' => $_SESSION['user_id'],
92+
':newName' => str_replace('<', ' ¯\_(ツ)_/¯ ', $_POST['name']),
93+
':email' => str_replace('<', ' ¯\_(ツ)_/¯ ', $_POST['email']),
94+
':password' => $hash,
95+
':about' => str_replace('<', ' ¯\_(ツ)_/¯ ', $_POST['about']),
96+
':showEmail' => $show_email
97+
));
98+
$_SESSION['success'] = 'Account details updated.';
99+
} else {
100+
$_SESSION['error'] = 'Email taken';
101+
}
102+
} else {
103+
$_SESSION['error'] = "File is not an image.";
104+
$uploadOk = 0;
105+
}
106+
header("Location: ./index.php");
107+
}
108+
?>
109+
<!DOCTYPE html>
110+
<html>
111+
112+
<head>
113+
<title>Account Settings</title>
114+
<style>
115+
html,
116+
body {
117+
height: 100%;
118+
}
119+
120+
body {
121+
display: -ms-flexbox;
122+
display: -webkit-box;
123+
display: flex;
124+
-ms-flex-align: center;
125+
-ms-flex-pack: center;
126+
-webkit-box-align: center;
127+
align-items: center;
128+
-webkit-box-pack: center;
129+
justify-content: center;
130+
padding-top: 40px;
131+
padding-bottom: 40px;
132+
background-color: #f5f5f5;
133+
}
134+
135+
.form-signin {
136+
width: 100%;
137+
max-width: 330px;
138+
padding: 15px;
139+
margin: 0 auto;
140+
}
141+
142+
.form-signin .checkbox {
143+
font-weight: 400;
144+
}
145+
146+
.form-signin .form-control {
147+
position: relative;
148+
box-sizing: border-box;
149+
height: auto;
150+
padding: 10px;
151+
font-size: 16px;
152+
}
153+
154+
.form-signin .form-control:focus {
155+
z-index: 2;
156+
}
157+
158+
.form-signin input[type="email"] {
159+
margin-bottom: -1px;
160+
border-bottom-right-radius: 0;
161+
border-bottom-left-radius: 0;
162+
}
163+
164+
.form-signin input[type="password"] {
165+
margin-bottom: 10px;
166+
border-top-left-radius: 0;
167+
border-top-right-radius: 0;
168+
}
169+
</style>
170+
</head>
171+
172+
<body>
173+
<form class="form-signin" action="account-settings.php" method="post" enctype="multipart/form-data" autocomplete="off">
174+
<h1 class="h3 mb-3 font-weight-normal">Account Settings</h1>
175+
Select image to upload for <?= $_SESSION['name'] ?>
176+
<input type="file" name="fileToUpload" id="fileToUpload">
177+
<label for="name" class="sr-only">Name</label>
178+
<input type="text" name="name" class="form-control" placeholder="" required="" autofocus="" value="<?= $response['name'] ?>">
179+
<label for="email" class="sr-only">Email</label>
180+
<input type="email" name="email" class="form-control" placeholder="" required="" value="<?= $response['email'] ?>">
181+
<label for="about" class="sr-only">About</label>
182+
<input type="text" name="about" class="form-control" placeholder="" required="" value="<?= $response['about'] ?>">
183+
<label for="password" class="sr-only">New Password</label>
184+
<input type="password" name="password" class="form-control" placeholder="Password" required="">
185+
<div class="checkbox mb-3">
186+
<label>
187+
<input type="checkbox" name="show_email" <?php echo ($response['show_email'] == 'True') ? 'checked' : '' ?>> Show Email
188+
</label>
189+
</div>
190+
<input class="btn btn-lg btn-primary btn-block" type="submit" name="submit" value="Save Changes">
191+
<br />
192+
<a href="./index.php">Cancel</a> | <a href="./delete-account.php">Delete Account</a>
193+
</form>
194+
</div>
195+
</body>
196+
197+
</html>

new-g4o2-chat/css/style.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
body {
22
padding-top: 65px;
3-
background-color: black !important;
43
}
54

65
main {

new-g4o2-chat/delete-account.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
require_once "pdo.php";
3+
require_once "head.php";
4+
date_default_timezone_set('Asia/Taipei');
5+
6+
if (!isset($_SESSION["email"])) {
7+
echo "<p class='die-msg'>PLEASE LOGIN</p>";
8+
echo '<link rel="stylesheet" href="./style.css?v=<?php echo time(); ?>">';
9+
echo "<br />";
10+
echo "<p class='die-msg'>Redirecting in 3 seconds</p>";
11+
header("refresh:3;url=index.php");
12+
die();
13+
}
14+
if ($_SESSION['email'] == 'guest@guest.com') {
15+
echo "<p class='die-msg'>LOGGED IN AS GUEST ACCOUNT</p>";
16+
echo "<p class='die-msg'>EDIT ACCOUNT DETAILS NOT ALLOWED</p>";
17+
echo '<link rel="stylesheet" href="./style.css?v=<?php echo time(); ?>">';
18+
echo "<br />";
19+
echo "<p class='die-msg'>Redirecting in 3 seconds</p>";
20+
header("refresh:3;url=index.php");
21+
die();
22+
}
23+
24+
if (isset($_POST['delete'])) {
25+
$sql = "DELETE FROM account WHERE user_id = :uid";
26+
$stmt = $pdo->prepare($sql);
27+
$stmt->execute(array(':uid' => $_SESSION['user_id']));
28+
$_SESSION['success'] = 'Account deleted';
29+
session_destroy();
30+
header('Location: ./login.php');
31+
return;
32+
}
33+
?>
34+
<!DOCTYPE html>
35+
<html>
36+
37+
<head>
38+
<title>Delete Account</title>
39+
<style>
40+
form {
41+
width: 100%;
42+
max-width: 330px;
43+
padding: 15px;
44+
margin: 0 auto;
45+
}
46+
</style>
47+
</head>
48+
49+
<body>
50+
<form class="form-signin" action="delete-account.php" method="post" enctype="multipart/form-data">
51+
<h1 class="h3 mb-3 font-weight-normal">Delete Account</h1>
52+
<input class="btn btn-lg btn-primary btn-block" type="submit" value="Delete Account" name="delete">
53+
<br />
54+
<a href="./index.php">Cancel</a>
55+
</form>
56+
</body>
57+
58+
</html>

new-g4o2-chat/head.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
1616
<link rel="stylesheet" href="./css/style.css?v=<?php echo time(); ?>">
17-
<link rel="stylesheet" href="https://kit.fontawesome.com/b60596f9d0.css" crossorigin="anonymous">
17+
<!-- <link rel="stylesheet" href="https://kit.fontawesome.com/b60596f9d0.css" crossorigin="anonymous"> -->
1818

1919
<link rel="apple-touch-icon" sizes="180x180" href="favicon/apple-touch-icon.png">
2020
<link rel="icon" type="image/png" sizes="32x32" href="favicon/favicon-32x32.png">

0 commit comments

Comments
 (0)