Kevin prototype #82

Merged
11319801 merged 15 commits from kevin-prototype into master 2017-01-20 12:28:04 +01:00
3 changed files with 37 additions and 7 deletions

View File

@@ -4,11 +4,18 @@
include("../views/login_head.php"); include("../views/login_head.php");
require_once("../queries/connect.php"); require_once("../queries/connect.php");
include_once("../queries/login.php"); include_once("../queries/login.php");
include_once("../queries/checkInput.php")
?> ?>
<body> <body>
<?php <?php
session_start(); session_start();
if(isset($_SESSION["userID"])){
echo "<script>
window.onload=checkLoggedIn();
</script>";
}
// Define variables and set to empty values // Define variables and set to empty values
$uname = $psw =""; $uname = $psw ="";
$loginErr =""; $loginErr ="";
@@ -41,5 +48,18 @@
/* This view adds login view */ /* This view adds login view */
include("../views/login-view.php"); 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> </body>
</html> </html>

View File

@@ -29,7 +29,7 @@
} }
checkInputChoice("username", "username"); checkInputChoice("username", "username");
checkInputChoice("password", "longerEigth"); checkInputChoice("password", "longerEight");
checkInputChoice("confirmpassword", ""); checkInputChoice("confirmpassword", "");
matchPassword(); matchPassword();
checkInputChoice("location", "lettersAndSpace"); checkInputChoice("location", "lettersAndSpace");

View File

@@ -1,4 +1,10 @@
<?php <?php
/**
* Function for checking inputfields
* @param variable $variable Give name of the inputfield.
* @param string $option Give the name of the option.
* @return sets correct to false and gives value to error message if it doesn't pass the checks.
*/
function checkInputChoice($variable, $option){ function checkInputChoice($variable, $option){
if (empty($_POST[$variable])) { if (empty($_POST[$variable])) {
$GLOBALS[$variable . "Err"] = "Verplicht!"; $GLOBALS[$variable . "Err"] = "Verplicht!";
@@ -15,28 +21,28 @@ function checkInputChoice($variable, $option){
username($variable); username($variable);
break; break;
case "longerEigth"; case "longerEight";
longerEigth($variable); longerEight($variable);
break; break;
case "email"; case "email";
validateEmail($variable); validateEmail($variable);
break; break;
default: default:
break; break;
} }
} }
} }
/* Checks for only letters and spaces. */
function checkOnly($variable){ function checkOnly($variable){
if (!preg_match("/^[a-zA-Z ]*$/",$GLOBALS[$variable])) { if (!preg_match("/^[a-zA-Z ]*$/",$GLOBALS[$variable])) {
$GLOBALS[$variable . "Err"] = "Alleen letters en spaties zijn toegestaan!"; $GLOBALS[$variable . "Err"] = "Alleen letters en spaties zijn toegestaan!";
$correct = false; $correct = false;
} }
} }
/* checks if username exist and if its longer than 6 characters. */
function username($variable){ function username($variable){
if (strlen($GLOBALS[$variable]) < 6) { if (strlen($GLOBALS[$variable]) < 6) {
$GLOBALS[$variable . "Err"] = "Gebruikersnaam moet minstens 6 karakters bevatten"; $GLOBALS[$variable . "Err"] = "Gebruikersnaam moet minstens 6 karakters bevatten";
@@ -47,13 +53,15 @@ function username($variable){
} }
} }
function longerEigth($variable){ /* checks if an input is longer that 8 characters. */
function longerEight($variable){
if (strlen($GLOBALS[$variable]) < 8) { if (strlen($GLOBALS[$variable]) < 8) {
$GLOBALS[$variable . "Err"] = "Moet minstens 8 karakters bevatten"; $GLOBALS[$variable . "Err"] = "Moet minstens 8 karakters bevatten";
$correct = false; $correct = false;
} }
} }
/* checks if an input is a valid email. */
function validateEmail($variable){ function validateEmail($variable){
if (!filter_var($GLOBALS[$variable], FILTER_VALIDATE_EMAIL)) { if (!filter_var($GLOBALS[$variable], FILTER_VALIDATE_EMAIL)) {
$GLOBALS[$variable . "Err"] = "Geldige email invullen!"; $GLOBALS[$variable . "Err"] = "Geldige email invullen!";
@@ -66,6 +74,7 @@ function validateEmail($variable){
} }
} }
/* checks if two passwords matches. */
function matchPassword(){ function matchPassword(){
if ($_POST["password"] != $_POST["confirmpassword"]) { if ($_POST["password"] != $_POST["confirmpassword"]) {
$GLOBALS["confirmpasswordErr"] = "Wachtwoorden matchen niet"; $GLOBALS["confirmpasswordErr"] = "Wachtwoorden matchen niet";
@@ -86,6 +95,7 @@ function registerCheck(){
} }
} }
/* removes weird characters of an input. */
function test_input($data) { function test_input($data) {
$data = trim($data); $data = trim($data);
$data = stripslashes($data); $data = stripslashes($data);