Files
OpenDRS/distfiles/login.php

126 lines
3.9 KiB
PHP

<?php
/*
login.php
OpenDRS Online Discrepancy Reporting System
Copyright (C) 2022 Rod Wright
SPDX-License-Identifier: GPL-2.0
*/
include("common.php");
$print=$_REQUEST['print'];
$userid=$_REQUEST['userid'];
$userlogin=$_REQUEST['userlogin'];
$pass=$_REQUEST['pass'];
$login=$_REQUEST['login'];
$cancel=$_REQUEST['cancel'];
if ($cancel) {
session_destroy();
}
$appname=APP_NAME;
if ($print) {
$mbgcolor=P_MENUBG_COLOR;
} else {
$mbgcolor=MENUBG_COLOR;
}
framework("begin","$appname","Login Page",$print);
//echo "_REQUEST array <br>";
//var_dump($_REQUEST);
//echo "<br><hr> incoming array <br>";
//var_dump($incoming);
pagetable("begin");
if(!$print){
pageblock("left","begin");
$printable=false;
sidemenu($printable);
pageblock("left","end");
}
pageblock("right","begin");
if ($login) {
// get the id from the userlogin
$userid=dblookup($drs_db,"users","login","id",$userlogin);
$useractive=dblookup($drs_db,"users","id","active",$userid);
// log me in
$pwhash=mysqli_fetch_row(mysqli_query($drs_db,"select password_hash from users where id=\"$userid\""))[0];
if ($userid) {
if ($useractive) {
if (password_verify($pass, $pwhash)) {
$_SESSION['userid']=$userid;
echo "
<script>location.assign(\"login.php\");</script>
";
} else {
$admins=mysqli_query($drs_db,"select firstname,lastname from users where active is true and role=\"".ADMIN."\"");
echo "
Incorrect password. Please <a href=\"login.php\">try again</a>.<br><br>
Forgot your password? Contact an administrator:<br><br>
";
while ($adminrow=mysqli_fetch_assoc($admins)) {
$firstname=$adminrow["firstname"];
$lastname=$adminrow["lastname"];
echo "$firstname $lastname <br>";
}
}
} else {
$admins=mysqli_query($drs_db,"select firstname,lastname from users where active is true and role=\"".ADMIN."\"");
echo "
Your account is inactive. Please contact one of these administrators:<br><br>
";
while ($adminrow=mysqli_fetch_assoc($admins)) {
$firstname=$adminrow["firstname"];
$lastname=$adminrow["lastname"];
echo "$firstname $lastname <br>";
}
}
} else {
$admins=mysqli_query($drs_db,"select firstname,lastname from users where active is true and role=\"".ADMIN."\"");
echo "
Incorrect password. Please <a href=\"login.php\">try again</a>.<br><br>
Forgot your password? Contact an administrator:<br><br>
";
while ($adminrow=mysqli_fetch_assoc($admins)) {
$firstname=$adminrow["firstname"];
$lastname=$adminrow["lastname"];
echo "$firstname $lastname <br>";
}
}
} else if ($cancel) {
echo "
<script>location.assign(\"login.php\");</script>
";
} else {
if (!isset($_SESSION['userid'])) {
// show the login form
echo "
<form method=\"post\" action=\"login.php\">
Login: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"text\" name=\"userlogin\" size=\"40\">
<br><br>
Password: &nbsp;<input type=\"password\" name=\"pass\" size=\"40\"><br><br>
<input type=\"submit\" name=\"login\" value=\"Log In\">&nbsp;&nbsp;&nbsp;&nbsp;
<input type=\"submit\" name=\"cancel\" value=\"Cancel\"><br>
</form>
<br><hr>
";
} else {
$userid=$_SESSION['userid'];
$firstname=mysqli_fetch_row(mysqli_query($drs_db,"select firstname from users where id=\"$userid\""))[0];
echo "
Welcome $firstname. Please select a menu option at the left to continue.<br><hr>
";
}
}
pageblock("right","end");
pagetable("end");
framework("end","","",$print);
?>