Merge branch 'master' into lars-algemeen

This commit is contained in:
Lars van Hijfte
2017-01-20 12:26:22 +01:00
11 changed files with 168 additions and 136 deletions

View File

@@ -4,27 +4,34 @@
include("../views/login_head.php");
require_once("../queries/connect.php");
include_once("../queries/login.php");
include_once("../queries/checkInput.php")
?>
<body>
<?php
session_start();
if(isset($_SESSION["userID"])){
echo "<script>
window.onload=checkLoggedIn();
</script>";
}
// Define variables and set to empty values
$uname = $psw ="";
$loginErr ="";
// Trying to login
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$uname=strtolower($_POST["uname"]);
// Empty username or password field
if (empty($_POST["uname"]) || empty($_POST["psw"])) {
$loginErr = "Gebruikersnaam of wachtwoord is niet ingevuld";
}
else {
$psw=$_POST["psw"];
$hash=getUser()["password"];
$userid=getUser()["userID"];
$uname = strtolower(test_input($_POST["uname"]));
$psw = test_input($_POST["psw"]);
$hash = getUser()["password"];
$userid = getUser()["userID"];
// If there's an account, go to the profile page
if(password_verify($psw, $hash)) {
@@ -41,5 +48,18 @@
/* This view adds login view */
include("../views/login-view.php");
?>
<script>
function checkLoggedIn() {
if (confirm("You are already logged in!\Do you want to logout?\Press ok to logout.") == true) {
unset($_SESSION["userID"]);
header("Location: login.php");
} else {
header("location: profile.php");
}
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

View File

@@ -49,8 +49,8 @@ if(empty($_GET["username"])) {
$userID = getUserID($_GET["username"]);
$user = selectUser($userID);
$friends = selectAllFriends($userID);
$groups = selectAllUserGroups($userID);
$profile_friends = selectAllFriends($userID);
$profile_groups = selectAllUserGroups($userID);
$posts = selectAllUserPosts($userID);
?>

View File

@@ -4,7 +4,7 @@
include("../views/login_head.php");
require_once("../queries/connect.php");
include_once("../queries/register.php");
include_once("../queries/checkInput.php");
?>
<body>
<?php
@@ -17,127 +17,25 @@
// Trying to register an account
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Naam is verplicht!";
$correct = false;
checkInputChoice("name", "lettersAndSpace");
checkInputChoice("surname", "lettersAndSpace");
} else {
$name = test_input($_POST["name"]);
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Alleen letters en spaties zijn toegestaan!";
$correct = false;
}
}
if (empty($_POST["surname"])) {
$surnameErr = "Achternaam is verplicht!";
$correct = false;
} else {
$surname = test_input($_POST["surname"]);
if (!preg_match("/^[a-zA-Z ]*$/",$surname)) {
$surnameErr = "Alleen letters en spaties zijn toegestaan!";
$correct = false;
}
}
if (empty($_POST["bday"])) {
$bdayErr = "Geboortedatum is verplicht!";
$correct = false;
}
if (empty($_POST["username"])) {
$usernameErr = "Gebruikersnaam is verplicht!";
$correct = false;
} else {
$username = test_input($_POST["username"]);
if (strlen($username) < 6) {
$usernameErr = "Gebruikersnaam moet minstens 6 karakters bevatten";
$correct = false;
} else if (getExistingUsername() == 1){
$usernameErr = "Gebruikersnaam bestaat al";
$correct = false;
}
$bday = test_input($_POST["bday"]);
}
if (empty($_POST["password"])) {
$passwordErr = "Wachtwoord is verplicht!";
$correct = false;
} else {
$password = test_input($_POST["password"]);
if (strlen($password) < 8) {
$passwordErr = "Wachtwoord moet minstens 8 karakters bevatten";
$correct = false;
}
}
if (empty($_POST["confirmpassword"])) {
$confirmpasswordErr = "Herhaal wachtwoord!";
$correct = false;
}
if ($_POST["password"] != $_POST["confirmpassword"]) {
$confirmpasswordErr = "Wachtwoorden matchen niet";
$correct = false;
}
if (empty($_POST["location"])) {
$locationErr = "Straatnaam is verplicht!";
$correct = false;
} else {
$location = test_input($_POST["location"]);
if (!preg_match("/^[a-zA-Z ]*$/",$location)) {
$locationErr = "Alleen letters en spaties zijn toegestaan!";
$correct = false;
}
}
if (empty($_POST["email"])) {
$emailErr = "Email is verplicht!";
$correct = false;
} else {
$email = test_input($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Geldige email invullen!";
$correct = false;
} else if (getExistingEmail() == 1){
$emailErr = "Email bestaat al";
$correct = false;
}
}
// Checks if everything is filled in correctly
if ($correct == false){
$genericErr = "Bepaalde velden zijn verkeerd of niet ingevuld!";
} else {
registerAccount();
header("location: login.php");
}
checkInputChoice("username", "username");
checkInputChoice("password", "longerEight");
checkInputChoice("confirmpassword", "");
matchPassword();
checkInputChoice("location", "lettersAndSpace");
checkInputChoice("email", "email");
registerCheck();
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
/* This view adds register view */
include("../views/register-view.php");
?>