Skip to content

Commit 07a188e

Browse files
committed
new g4o2 chat login page
1 parent 469dfbf commit 07a188e

File tree

6 files changed

+268
-57
lines changed

6 files changed

+268
-57
lines changed

new-g4o2-chat/css/style.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
body {
22
padding-top: 65px;
3+
background-color: black !important;
4+
}
5+
6+
main {
7+
padding: 35px;
38
}

new-g4o2-chat/index.php

Lines changed: 63 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -81,79 +81,85 @@
8181
<a class="nav-link disabled">Private Messaging (coming soon)</a>
8282
</li>
8383
</ul>
84-
<a class="btn btn-outline-success" href="./login.php"><?= isset($_SESSION['user_id']) ? 'Logout' : 'Login' ?></a>
84+
<?= isset($_SESSION['user_id']) ? '<a class="btn btn-outline-success" href="./logout.php">Logout</a>' : '<a class="btn btn-outline-success" href="./login.php">Login</a>' ?>
8585
</div>
8686
</div>
8787
</nav>
8888
<main>
89-
<?php
90-
echo '
91-
<table class="table">
89+
<div class="w-75 p-2" style="background-color: #eee;margin: auto;">
90+
<?php
91+
if (isset($_SESSION['user_id'])) {
92+
echo '
93+
<table class="table table-light table-hover">
9294
<thead class="thead-dark">
9395
<tr>
94-
<th scope="col">#</th>
95-
<th scope="col">Name</th>
96-
<th scope="col">Email</th>
97-
<th scope="col">Last active</th>
96+
<th scope="col" style="background-color: #eee;">#</th>
97+
<th scope="col" style="background-color: #eee;">Name</th>
98+
<th scope="col" style="background-color: #eee;">Email</th>
99+
<th scope="col" style="background-color: #eee;">Last active</th>
98100
</tr>
99101
</thead>
100102
<tbody>';
101-
foreach ($accounts as $account) {
102-
if ($account['pfp'] != null) {
103-
$pfpsrc = $account['pfp'];
104-
} else {
105-
$pfpsrc = $pfpsrc_default;
106-
}
103+
foreach ($accounts as $account) {
104+
if ($account['pfp'] != null) {
105+
$pfpsrc = $account['pfp'];
106+
} else {
107+
$pfpsrc = $pfpsrc_default;
108+
}
107109

108-
$pfp = "<a class='pfp-link' href='./profile.php?user={$account['user_id']}'><img style='border-radius: 100px; margin-left: 10px; ' height='20px' width='20px' src='$pfpsrc'></a>";
110+
$pfp = "<a class='pfp-link' href='./profile.php?user={$account['user_id']}'><img style='border-radius: 100px; margin-left: 10px; ' height='20px' width='20px' src='$pfpsrc'></a>";
109111

110-
$statement = $pdo->prepare("SELECT * FROM user_status_log where user_Id = :usr");
111-
$statement->execute(array(':usr' => $account['user_id']));
112-
$user_status_log = $statement->fetch();
113-
$userStatus = ($user_status_log != null) ? $user_status_log['last_active_date_time'] : "Undefined";;
112+
$statement = $pdo->prepare("SELECT * FROM user_status_log where user_Id = :usr");
113+
$statement->execute(array(':usr' => $account['user_id']));
114+
$user_status_log = $statement->fetch();
115+
$userStatus = ($user_status_log != null) ? $user_status_log['last_active_date_time'] : "Undefined";;
114116

115-
if ($userStatus === "Undefined") {
116-
$diff = "<p class='text-danger'>Null</p>";
117-
} else {
118-
$last_online = $userStatus;
119-
$current_date_time = date(DATE_RFC2822);
120-
$last_online = new DateTime($last_online);
121-
$current_date_time = new DateTime($current_date_time);
117+
if ($userStatus === "Undefined") {
118+
$diff = "<p class='text-danger'>Null</p>";
119+
} else {
120+
$last_online = $userStatus;
121+
$current_date_time = date(DATE_RFC2822);
122+
$last_online = new DateTime($last_online);
123+
$current_date_time = new DateTime($current_date_time);
122124

123-
$diff = $current_date_time->diff($last_online)->format("last online %a days %h hours and %i minutes ago");
124-
$exploded = explode(" ", $diff);
125+
$diff = $current_date_time->diff($last_online)->format("last online %a days %h hours and %i minutes ago");
126+
$exploded = explode(" ", $diff);
125127

126-
if ($exploded[2] == "1") {
127-
$diff = "<p class='text-warning'>$exploded[2]&nbsp;day&nbsp;ago</p>";
128-
} elseif ($exploded[4] == "1") {
129-
$diff = "<p class='text-warning''>$exploded[4]&nbsp;hour&nbsp;ago</p>";
130-
} elseif ($exploded[7] == "1") {
131-
$diff = "<p class='text-warning''>$exploded[7]&nbsp;minute&nbsp;ago</p>";
132-
} elseif ($exploded[2] !== "0") {
133-
$diff = "<p class='text-warning''>$exploded[2]&nbsp;days&nbsp;ago</p>";
134-
} elseif ($exploded[4] !== "0") {
135-
$diff = "<p class='text-warning''>$exploded[4]&nbsp;hours&nbsp;ago</p>";
136-
} elseif ($exploded[7] !== "0") {
137-
$diff = "<p class='text-warning''>$exploded[7]&nbsp;minutes&nbsp;ago</p>";
138-
} else {
139-
$diff = "<p class='text-success'>Online</p>";
128+
if ($exploded[2] == "1") {
129+
$diff = "<p class='text-warning'>$exploded[2]&nbsp;day&nbsp;ago</p>";
130+
} elseif ($exploded[4] == "1") {
131+
$diff = "<p class='text-warning''>$exploded[4]&nbsp;hour&nbsp;ago</p>";
132+
} elseif ($exploded[7] == "1") {
133+
$diff = "<p class='text-warning''>$exploded[7]&nbsp;minute&nbsp;ago</p>";
134+
} elseif ($exploded[2] !== "0") {
135+
$diff = "<p class='text-warning''>$exploded[2]&nbsp;days&nbsp;ago</p>";
136+
} elseif ($exploded[4] !== "0") {
137+
$diff = "<p class='text-warning''>$exploded[4]&nbsp;hours&nbsp;ago</p>";
138+
} elseif ($exploded[7] !== "0") {
139+
$diff = "<p class='text-warning''>$exploded[7]&nbsp;minutes&nbsp;ago</p>";
140+
} else {
141+
$diff = "<p class='text-success'>Online</p>";
142+
}
143+
}
144+
echo "<tr><th scope='row'>";
145+
echo ($account['user_id']);
146+
echo $pfp;
147+
echo ("</th><td>");
148+
echo "<a href='./profile.php?user={$account['user_id']}' >" . $account['name'] . "</a>";
149+
echo "<td>";
150+
echo ($account['show_email'] === "True") ? "<p class=''>" . $account['email'] . "</p>" : "<p class='text-warning'>Hidden</p>";
151+
echo ("</td><td>");
152+
echo $diff;
153+
echo ("</td></tr>\n");
154+
echo ("</td></tr>\n");
140155
}
156+
echo "<tbody></table>";
157+
echo $_SESSION['user_id'];
158+
} else {
159+
echo '<p>Please login</p>';
141160
}
142-
echo "<tr><th scope='row'>";
143-
echo ($account['user_id']);
144-
echo $pfp;
145-
echo ("</th><td>");
146-
echo "<a href='./profile.php?user={$account['user_id']}' >" . $account['name'] . "</a>";
147-
echo "<td>";
148-
echo ($account['show_email'] === "True") ? "<p class='text-black'>" . $account['email'] . "</p>" : "<p class='text-warning'>Hidden</p>";
149-
echo ("</td><td>");
150-
echo $diff;
151-
echo ("</td></tr>\n");
152-
echo ("</td></tr>\n");
153-
}
154-
echo "<tbody></table>";
155-
156-
?>
161+
?>
162+
</div>
157163
</main>
158164
<footer class="text-center text-lg-start bg-light text-muted">
159165
<section class="d-flex justify-content-center justify-content-lg-between p-4 border-bottom">

new-g4o2-chat/login.php

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
<?php
2+
require_once "pdo.php";
3+
require_once "head.php";
4+
5+
date_default_timezone_set('Asia/Taipei');
6+
7+
$host = $_SERVER['HTTP_HOST'];
8+
$ruta = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
9+
$url = "http://$host$ruta";
10+
11+
if (isset($_POST["cancel"])) {
12+
header("Location: $url/index.php");
13+
die();
14+
}
15+
16+
if (isset($_POST["email"]) && isset($_POST["pass"])) {
17+
unset($SESSION["name"]);
18+
unset($SESSION["user_id"]);
19+
session_destroy();
20+
session_start();
21+
$salt = getenv('SALT');
22+
$check = hash("md5", $salt . $_POST["pass"]);
23+
24+
$stmt = $pdo->prepare(
25+
'SELECT user_id, name, email, disabled
26+
FROM account
27+
WHERE
28+
email = :em AND
29+
password = :pw'
30+
);
31+
$stmt->execute(array(':em' => $_POST['email'], ':pw' => $check));
32+
$row = $stmt->fetch(PDO::FETCH_ASSOC);
33+
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
34+
35+
if ($row !== false) {
36+
if ($row['disabled'] === "True") {
37+
$_SESSION["error"] = "Account disabled";
38+
error_log("Login fail disabled account " . $_POST['email'] . " " . $ip . " (" . date(DATE_RFC2822) . ")\n", 3, "./logs/logs.log");
39+
header("Location: $url/login.php");
40+
die();
41+
}
42+
if ($_POST["email"] == 'g4o2@protonmail.com' || $_POST["email"] == 'g4o3@protonmail.com' || $_POST["email"] == 'maxhu787@gmail.com') {
43+
// error_log("Login success admin account (" . date(DATE_RFC2822) . ")\n", 3, "./logs/logs.log");
44+
} else {
45+
error_log("Login success " . $_POST['email'] . " " . $ip . " (" . date(DATE_RFC2822) . ")\n", 3, "./logs/logs.log");
46+
}
47+
$_SESSION["user_id"] = $row["user_id"];
48+
$_SESSION["name"] = $row["name"];
49+
$_SESSION['email'] = $row['email'];
50+
$_SESSION["success"] = "Logged in.";
51+
header("Location: $url/index.php");
52+
die();
53+
} else {
54+
$_SESSION["error"] = "Incorrect email or password";
55+
error_log("Login fail wrong password " . $_POST['email'] . " " . $check . " " . $ip . " (" . date(DATE_RFC2822) . ")\n", 3, "./logs/logs.log");
56+
header("Location: $url/login.php");
57+
die();
58+
}
59+
}
60+
?>
61+
<!DOCTYPE html>
62+
<html lang="en">
63+
64+
<head>
65+
<title>Login</title>
66+
<style>
67+
html,
68+
body {
69+
height: 100%;
70+
background-color: #fff !important;
71+
}
72+
73+
body {
74+
display: -ms-flexbox;
75+
display: -webkit-box;
76+
display: flex;
77+
-ms-flex-align: center;
78+
-ms-flex-pack: center;
79+
-webkit-box-align: center;
80+
align-items: center;
81+
-webkit-box-pack: center;
82+
justify-content: center;
83+
padding-top: 40px;
84+
padding-bottom: 40px;
85+
background-color: #f5f5f5;
86+
}
87+
88+
.form-signin {
89+
width: 100%;
90+
max-width: 330px;
91+
padding: 15px;
92+
margin: 0 auto;
93+
}
94+
95+
.form-signin .checkbox {
96+
font-weight: 400;
97+
}
98+
99+
.form-signin .form-control {
100+
position: relative;
101+
box-sizing: border-box;
102+
height: auto;
103+
padding: 10px;
104+
font-size: 16px;
105+
}
106+
107+
.form-signin .form-control:focus {
108+
z-index: 2;
109+
}
110+
111+
.form-signin input[type="email"] {
112+
margin-bottom: -1px;
113+
border-bottom-right-radius: 0;
114+
border-bottom-left-radius: 0;
115+
}
116+
117+
.form-signin input[type="password"] {
118+
margin-bottom: 10px;
119+
border-top-left-radius: 0;
120+
border-top-right-radius: 0;
121+
}
122+
</style>
123+
</head>
124+
125+
<body class="text-center">
126+
<form class="form-signin" method="post">
127+
<img class="mb-4" src="./assets/images/g4o2.jpeg" alt="" width="72" height="72">
128+
<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
129+
<p>
130+
<?php
131+
if (isset($_SESSION["error"])) {
132+
echo ('<p style="color: red;">' . htmlentities($_SESSION["error"]) . "</p>");
133+
unset($_SESSION["error"]);
134+
}
135+
if (isset($_SESSION["success"])) {
136+
echo ('<p style="color: green">' . htmlentities($_SESSION["success"]) . "</p>");
137+
unset($_SESSION["success"]);
138+
}
139+
?>
140+
</p>
141+
<label for="inputEmail" class="sr-only">Email address</label>
142+
<input type="email" id="id_email" class="form-control" name="email" placeholder="Email address" required="" autofocus="">
143+
<label for="inputPassword" class="sr-only">Password</label>
144+
<input type="password" id="id_pass" class="form-control" name="pass" placeholder="Password" required="">
145+
<div class="checkbox mb-3">
146+
<label>
147+
<input type="checkbox" value="remember-me"> Remember me
148+
</label>
149+
</div>
150+
<button class="btn btn-lg btn-primary btn-block" type="submit" onclick="return doValidate();">Sign in</button>
151+
<p class="mt-5 mb-3 text-muted">© <?= date("Y") ?></p>
152+
<p>Don't have an account yet? <a href='./signup.php'>register</a></p>
153+
</form>
154+
</form>
155+
<script>
156+
function doValidate() {
157+
console.log("Validating...");
158+
try {
159+
email = document.getElementById("id_email").value;
160+
pw = document.getElementById("id_pass").value;
161+
console.log("Validating email=" + email);
162+
console.log("Validating pw=" + pw);
163+
if (pw == null || pw == "" || email == null || email == "") {
164+
alert("Both fields must be filled out");
165+
return false;
166+
}
167+
if (email.search("@") === -1) {
168+
alert("Email address must contain @");
169+
return false;
170+
}
171+
return true;
172+
} catch (e) {
173+
return false;
174+
}
175+
return false;
176+
}
177+
</script>
178+
</body>
179+
180+
</html>

new-g4o2-chat/logout.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
session_start();
3+
date_default_timezone_set('Asia/Taipei');
4+
5+
if ($_POST["email"] == 'g4o2@protonmail.com' || $_POST["email"] == 'g4o3@protonmail.com' || $_POST["email"] == 'maxhu787@gmail.com') {
6+
// error_log("Logout success admin account " . $_SESSION['email'] . " (" . date(DATE_RFC2822) . ")\n", 3, "./logs/logs.log");
7+
} else {
8+
error_log("Logout success " . $_SESSION['email'] . " (" . date(DATE_RFC2822) . ")\n", 3, "./logs/logs.log");
9+
}
10+
unset($_SESSION['name']);
11+
unset($_SESSION['user_id']);
12+
unset($_SESSION['email']);
13+
session_start();
14+
session_destroy();
15+
16+
header('Location: index.php');

new-g4o2-chat/logs/logs.log

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Login fail wrong password g4o2@praweaweotonmail.com 45c4fd97cdd8eb4e85749cf13b518cea (Thu, 02 Feb 2023 09:51:58 +0800)
2+
Login fail wrong password g4o2@protonmaawdawdil.com 45c4fd97cdd8eb4e85749cf13b518cea (Thu, 02 Feb 2023 09:52:23 +0800)
3+
Logout success g4o2@protonmail.com (Thu, 02 Feb 2023 09:54:59 +0800)

new-g4o2-chat/pdo.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
session_start();
23
ob_start();
34
ini_set('display_errors', 0);
45

0 commit comments

Comments
 (0)