redesigned code #119
@@ -4,5 +4,8 @@ function checkLoggedIn() {
|
|||||||
} else {
|
} else {
|
||||||
window.location.href = "profile.php";
|
window.location.href = "profile.php";
|
||||||
}
|
}
|
||||||
document.getElementById("demo").innerHTML = x;
|
}
|
||||||
|
|
||||||
|
function bannedAlert(){
|
||||||
|
alert("Your account is banned");
|
||||||
}
|
}
|
||||||
@@ -22,26 +22,11 @@
|
|||||||
|
|
||||||
// Trying to login
|
// Trying to login
|
||||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
// Empty username or password field
|
try{
|
||||||
if (empty($_POST["uname"]) || empty($_POST["psw"])) {
|
|
||||||
$loginErr = "Gebruikersnaam of wachtwoord is niet ingevuld";
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$uname = strtolower(test_input($_POST["uname"]));
|
$uname = strtolower(test_input($_POST["uname"]));
|
||||||
$psw = test_input($_POST["psw"]);
|
validateLogin($_POST["uname"], $_POST["psw"]);
|
||||||
$hash = getUser()["password"];
|
} catch(loginException $e) {
|
||||||
$userid = getUser()["userID"];
|
$loginErr = $e->getMessage();
|
||||||
|
|
||||||
// If there's an account, go to the profile page
|
|
||||||
if(password_verify($psw, $hash)) {
|
|
||||||
$_SESSION["userID"] = $userid;
|
|
||||||
header("location: profile.php");
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$loginErr = "Inloggegevens zijn niet correct";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$username = test_input(($_POST["username"]));
|
$username = str_replace(' ', '', test_input(($_POST["username"])));
|
||||||
checkInputChoice($username, "username");
|
checkInputChoice($username, "username");
|
||||||
} catch(usernameException $e){
|
} catch(usernameException $e){
|
||||||
$correct = false;
|
$correct = false;
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$password = test_input(($_POST["password"]));
|
$password = str_replace(' ', '', test_input(($_POST["password"])));
|
||||||
checkInputChoice($password, "longerEight");
|
checkInputChoice($password, "longerEight");
|
||||||
matchPassword();
|
matchPassword();
|
||||||
} catch(passwordException $e){
|
} catch(passwordException $e){
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
a.button {
|
a.button {
|
||||||
background-color: #C8CABD;
|
background-color: #C8CABD;
|
||||||
border-radius: 10px;
|
border-radius: 5px;
|
||||||
color: black;
|
color: black;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
height: 50%;
|
height: 50%;
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ function checkName($variable){
|
|||||||
if (empty($variable)) {
|
if (empty($variable)) {
|
||||||
throw new lettersAndSpacesException("Verplicht!");
|
throw new lettersAndSpacesException("Verplicht!");
|
||||||
} else if (!preg_match("/^[a-zA-Z ]*$/", $variable)) {
|
} else if (!preg_match("/^[a-zA-Z ]*$/", $variable)) {
|
||||||
throw new lettersAndSpacesException("Alleen letters en spaties zijn toegestaan!");
|
|
||||||
|
throw new lettersAndSpacesException("Alleen letters en spaties zijn toegestaan!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ function getUser() {
|
|||||||
$stmt = $GLOBALS["db"]->prepare("
|
$stmt = $GLOBALS["db"]->prepare("
|
||||||
SELECT
|
SELECT
|
||||||
`password`,
|
`password`,
|
||||||
`userID`
|
`userID`,
|
||||||
|
`role`
|
||||||
FROM
|
FROM
|
||||||
`user`
|
`user`
|
||||||
WHERE
|
WHERE
|
||||||
@@ -15,3 +16,40 @@ function getUser() {
|
|||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
return $stmt->fetch(PDO::FETCH_ASSOC);
|
return $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function validateLogin($username, $password){
|
||||||
|
// Empty username or password field
|
||||||
|
if (empty($username) || empty($password)) {
|
||||||
|
throw new loginException("Gebruikersnaam of wachtwoord is niet ingevuld");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$psw = test_input($password);
|
||||||
|
$hash = getUser()["password"];
|
||||||
|
$userID = getUser()["userID"];
|
||||||
|
$role = getUser()["role"];
|
||||||
|
|
||||||
|
// If there's an account, go to the profile page
|
||||||
|
if(password_verify($psw, $hash)) {
|
||||||
|
if ($role == "banned"){
|
||||||
|
echo "<script>
|
||||||
|
window.onload=bannedAlert();
|
||||||
|
</script>";
|
||||||
|
} else {
|
||||||
|
$_SESSION["userID"] = $userID;
|
||||||
|
header("location: profile.php");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new loginException("Inloggevens zijn niet correct");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class loginException extends Exception
|
||||||
|
{
|
||||||
|
public function __construct($message = "", $code = 0, Exception $previous = null)
|
||||||
|
{
|
||||||
|
parent::__construct($message, $code, $previous);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
<link rel="stylesheet"
|
<link rel="stylesheet"
|
||||||
type="text/css"
|
type="text/css"
|
||||||
href="styles/index.css">
|
href="styles/index.css">
|
||||||
<script src="/js/jqeury.js"></script>
|
<script src="js/jqeury.js"></script>
|
||||||
<script src="/js/registerAndLogin.js"></script>
|
<script src="js/registerAndLogin.js"></script>
|
||||||
<script src='https://www.google.com/recaptcha/api.js'></script>
|
<script src='https://www.google.com/recaptcha/api.js'></script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -96,7 +96,7 @@
|
|||||||
|
|
||||||
<!-- Register location -->
|
<!-- Register location -->
|
||||||
<div class="login_containerregister">
|
<div class="login_containerregister">
|
||||||
<label><b>Woonplaats</b></label>
|
<label><b>Locatie</b></label>
|
||||||
<input type="text"
|
<input type="text"
|
||||||
placeholder="Voer uw woonplaats in"
|
placeholder="Voer uw woonplaats in"
|
||||||
name="location"
|
name="location"
|
||||||
|
|||||||
Reference in New Issue
Block a user