Skip to content

Commit

Permalink
project final
Browse files Browse the repository at this point in the history
  • Loading branch information
rmdaw00 committed May 21, 2021
1 parent 2d334dd commit 270c7ea
Show file tree
Hide file tree
Showing 25 changed files with 1,885 additions and 0 deletions.
101 changes: 101 additions & 0 deletions Login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
session_start();
$error = '';
If (isset($_POST['email']) && isset($_POST['email'])){
try {
$email = $password = '';
if (empty($_POST['email']))
throw new Exception("empty Email");
else
$email = $_POST['email'];
if (empty($_POST['password']))
throw new Exception("empty password");
else
$password = $_POST['password'];

$dns = "mysql:host=localhost;dbname=ExamApp";
$db = new PDO($dns, 'root', '');


$hash = sha1($email.$password);
$returnSelect = $db->query("SELECT * FROM Users WHERE email = '" . $email. "' AND password = '" . $hash ."'");

$error = "No User/Password matching";
while($rowArray = $returnSelect->fetch())
{
$error = '';
$_SESSION['userName'] = $rowArray['name'];
$_SESSION['userType'] = $rowArray['isTeacher']?'teacher':'student';
$_SESSION['userID'] = $rowArray['id'];

if ($rowArray['isTeacher']) {
header("Location: ./teacher/home.php");
die();
} else {
header("Location: ./student/home.php");
die();
}
}




} catch(Exception $e){

$error = $e->getMessage();
$_SESSION['email'] = $_POST['email'];
$_SESSION['password'] = $_POST['password'];
}
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
<script src="scripts.js"></script>
<link rel="stylesheet" href="style.css" />
<title>Quiz Portal</title>
</head>
<body style="scroll-behavior: auto !important;">
<?php include("header.php")?>

<div id="main">

<h1>Login </h1>
<form action="Login.php" method="POST">
<div class="question">
<label for="email">E-Mail:</label>
<input id="email" name="email" type="email"/>
</div>
<div class="question">
<label for="password">Password:</label>
<input id="password" name="password" type="password"/>
</div>

<div class="question">
<input type="submit" value="Login" /> <?php if (!empty($error)) echo '<span class="error">' . $error . '</span>' ?>
</div>

</form>
</div>
<div id="sidebar">
<i class="fa fa-trash" onclick="hideSideBar()"></i>
<h3>Info</h3>
<li>John is a Student, email is: [email protected]</li>
<li>Mark is a Teacher, email is: [email protected]</li>
<li>both their passwords are 1234</li>
</div>
</div>

<?php include("footer.php")?>

</div>


</body>
</html>
8 changes: 8 additions & 0 deletions Logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
session_start();
session_destroy() ;

header("Location: home.php");
die();
?>

128 changes: 128 additions & 0 deletions Register.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php
session_start();
$errEmail= $email = $password = $name = $errPassword = $errVerPassword = $errName = "";

function validate(String $type,String $value) {
switch ($type) {
case "email":
return (preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $value)) ? "" : "invalid Email";

case "password":
return (preg_match("/(?=.*[\d])(?=.*[[:upper:]])(?=.*[[:lower:]])(?=.*[-_])/", $value)) ? "" : "invalid password format";

case "verPassword":
return ($value == $_POST['password']) ? "" : "Passwords Dont Match";

case "name":
return (!empty($value)) ? "" : "Required";

}


}

if (isset($_POST['email'])) {

$errEmail = validate("email", $_POST['email']);
$errPassword = validate("password", $_POST['password']);
$errVerPassword = validate("verPassword", $_POST['verPassword']);
$errName = validate("name", $_POST['name']);


$combinedError = $errEmail. $errPassword . $errVerPassword . $errName;

if ($combinedError == "") {
//Register
$email = $_POST['email'];
$password = $_POST['password'];
$name = $_POST['name'];

$dns = "mysql:host=localhost;dbname=ExamApp";
$db = new PDO($dns, 'root', '');


$hash = sha1($_POST['email'].$_POST['password']);
$statement = "insert into Users(email, password, name) values('" .$email ."','" . $hash . "','" . $name . "')";
$resRows = $db->exec($statement);


if ($resRows >= 1) {
include('Registered.php');
exit();
;}

}
}








?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
<script src="scripts.js"></script>
<title>Registration</title>
<link rel="stylesheet" href="style.css" />
</head>
<body style="scroll-behavior: auto !important;">
<?php include("header.php")?>

<div id="main">

<h1>Register for an Account</h1>


<form action="Register.php" method="POST">

<div class="question">
<label for="email">E-Mail:</label>
<input id="email" name="email" type="email" value="<?php if (isset($_POST['email'])) echo $_POST['email']?>"/>
<span class="error" id="errEmail"><?php echo $errEmail?></span>
</div>
<div class="question">
<label for="password">Password:</label>
<input id="password" name="password" type="password" />
<span class="error" id="errPassword"><?php echo $errPassword?></span>
</div>
<div class="question">
<label for="verPassword">Verify Password:</label>
<input id="verPassword" name="verPassword" type="password"/>
<span class="error" id="errVerPassword"><?php echo $errVerPassword?></span>
</div>

<div class="question">
<label for="name">Name:</label>
<input id="name" name="name" type="text" value="<?php if (isset($_POST['name'])) echo $_POST['name']?>"/>
<span class="error" id="errName"><?php echo $errName?></span>
</div>

<input type="submit" value="Register" />


</form>
</div>
<div id="sidebar">
<i class="fa fa-trash" onclick="hideSideBar()"></i>
<h3>Tips</h3>
<li>You Register as student, get promoted as teacher</li>
<li>Passwords must have one each of upper, lower, digit and (-_)</li>

</div>
</div>

<?php include("footer.php")?>



</body>
</html>
31 changes: 31 additions & 0 deletions Registered.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html ml-update="aware">
<head>
<link rel="stylesheet" href="style.css"/>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
<title>Quiz Portal</title>
</head>
<body style="scroll-behavior: auto !important;">
<?php include("header.php")?>

<div id="main">
<h1>Registered</h1>
<p>Welcome Aboard <?php if (isset($name)) echo $name;?>, Please Login!</p>
</div>
<div id="sidebar">
<i class="fa fa-trash" onclick="hideSideBar()"></i>
<h3>Tip</h3>
<li>good people sign in again</li>

</div>
</div>

<?php include("footer.php")?>

</div>





</body></html>
24 changes: 24 additions & 0 deletions footer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

?>

<!DOCTYPE html>
<html ml-update="aware">
<head>
<title>Quiz Portal</title>
</head>
<body style="scroll-behavior: auto !important;">



<div id="bottom">
Life is a blast, its moving really fast!
</div>
</div>






</body></html>
37 changes: 37 additions & 0 deletions header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html ml-update="aware">
<head>
<title>Quiz Portal</title>
<script>
const hideSideBar = () => {
document.getElementById("sidebar").parentElement.removeChild(document.getElementById("sidebar"))
}
</script>
</head>
<body style="scroll-behavior: auto !important;">

<div class="container wrapper">
<div id="top">
<h1>Welcome to RMD Quiz portal</h1>
<p>A place where you gracefully fail</p>
</div>
<div class="wrapper">
<div id="menubar">
<ul id="menulist">
<?php if (!isset($_SESSION['userName'])) {?>
<a href="Login.php"><li class="menuitem" >Login</li></a>
<a href="Register.php"><li class="menuitem" >Register</li></a>

<?php } else {?>
<li id="UserItem" >Hello <?php echo $_SESSION['userName']?>!</li>
<?php if ($_SESSION['userType']== 'teacher') {?>
<a href="home.php"><li class="menuitem" >Exams</li></a>
<a href="users.php"><li class="menuitem" >Users</li></a>
<?php }?>
<a href="../Logout.php"><li class="menuitem" >Logout</li></a>
<?php } ?>

</ul>
</div>

</body></html>
39 changes: 39 additions & 0 deletions home.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php session_start();



?>

<!DOCTYPE html>
<html ml-update="aware">
<head>
<link rel="stylesheet" href="style.css"/>
<script src="scripts.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
<title>Quiz Portal</title>
</head>
<body style="scroll-behavior: auto !important;">
<?php include("header.php")?>

<div id="main">
<?php if (isset($_GET['error'])) echo '<span class="error">' . $_GET['error'] . '</span>' ?>
<h1>Welcome to the Quiz Portal</h1>
<p>feel free to login!</p>
</div>
<div id="sidebar">
<i class="fa fa-trash" onclick="hideSideBar()"></i>
<h3>Updates</h3>
<li>Covid 19 is out and about</li>

</div>
</div>

<?php include("footer.php")?>

</div>





</body></html>
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading

0 comments on commit 270c7ea

Please sign in to comment.