-
Notifications
You must be signed in to change notification settings - Fork 0
/
checklogin.php
66 lines (57 loc) · 2.3 KB
/
checklogin.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
<?php
$host="localhost";
$user="ayoub";
$passwd="secret";
$db="pi";
$dbconn = pg_connect("host=$host dbname=$db user=$user password=$passwd")
or die('Could not connect: ' . pg_last_error());
$username = pg_escape_string(utf8_encode($_POST['username']));
$password = pg_escape_string(utf8_encode($_POST['password']));
$query = "SELECT * FROM active_user WHERE active_email = '$username' and passwd='$password'";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
$count = pg_num_rows($result);
$query_suspended = "SELECT * FROM suspended_user WHERE suspended_email = '$username' and passwd='$password'";
$result_sus = pg_query($query_suspended) or die('Query failed: ' . pg_last_error());
$count_suspended = pg_num_rows($result_sus);
if($count == 1) {
$query_access = "INSERT INTO access VALUES(date_trunc('second', current_timestamp), '$username')";
$result = pg_query($query_access) or die('Query failed: ' . pg_last_error());
shell_exec("nodejs /home/ayoub/PiTank/app.js");
}
else if($count_suspended == 1){
echo '<script language=javascript>document.location.href="suspended.html"</script>';
}
else {
echo '<script language=javascript>document.location.href="index.html"</script>';
}
?>
<html>
<head>
<title>Loading</title>
<link rel="stylesheet" type="text/css" href="css/demo.css" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script type="text/javascript">
function sleep(milliseconds) {
var start = new Date().getTime();
for(var i = 0; i < 1e7; i++) {
if((new Date().getTime() - start) > milliseconds){
break;
}
}
}
</script>
</head>
<body>
<div class="container">
<header>
<h1> Loading the node.js server, <span> please wait... </span></h1>
</header>
<script type="text/javascript">
setTimeout('Redirect()',5000);
function Redirect() {
location.href = 'http://localhost:3000';
}
</script>
</div>
</body>
</html>