Marijn button #99

Merged
11166932 merged 152 commits from marijn-button into master 2017-01-23 13:25:08 +01:00
11 changed files with 168 additions and 136 deletions
Showing only changes of commit b6f6c44cea - Show all commits

14
website/.htaccess Normal file
View File

@@ -0,0 +1,14 @@
Options +FollowSymLinks
RewriteEngine On
ErrorDocument 404 /error404.jpg
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
RewriteRule ^([^/.]+)\/$ $1.php [L]
RewriteRule ^profile/([A-z0-9]+)\/?$ profile.php?username=$1 [NC]

View File

@@ -1,7 +0,0 @@
<?xml version='1.0'?>
<MySQL_INIT>
<mysql_host>localhost</mysql_host>
<mysql_database>myhyvesbookplus</mysql_database>
<mysql_username>mhbp</mysql_username>
<mysql_password>qdtboXhCHJyL2szC</mysql_password>
</MySQL_INIT>

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;
checkInputChoice("username", "username");
checkInputChoice("password", "longerEight");
checkInputChoice("confirmpassword", "");
matchPassword();
checkInputChoice("location", "lettersAndSpace");
checkInputChoice("email", "email");
registerCheck();
}
}
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");
}
}
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");
?>

View File

@@ -0,0 +1,105 @@
<?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){
if (empty($_POST[$variable])) {
$GLOBALS[$variable . "Err"] = "Verplicht!";
$GLOBALS["correct"] = false;
} else {
$GLOBALS[$variable] = test_input($_POST[$variable]);
switch ($option) {
case "lettersAndSpace":
checkonly($variable);
break;
case "username";
username($variable);
break;
case "longerEight";
longerEight($variable);
break;
case "email";
validateEmail($variable);
break;
default:
break;
}
}
}
/* Checks for only letters and spaces. */
function checkOnly($variable){
if (!preg_match("/^[a-zA-Z ]*$/",$GLOBALS[$variable])) {
$GLOBALS[$variable . "Err"] = "Alleen letters en spaties zijn toegestaan!";
$correct = false;
}
}
/* checks if username exist and if its longer than 6 characters. */
function username($variable){
if (strlen($GLOBALS[$variable]) < 6) {
$GLOBALS[$variable . "Err"] = "Gebruikersnaam moet minstens 6 karakters bevatten";
$correct = false;
} else if (getExistingUsername() == 1) {
$GLOBALS[$variable . "Err"] = "Gebruikersnaam bestaat al";
$correct = false;
}
}
/* checks if an input is longer that 8 characters. */
function longerEight($variable){
if (strlen($GLOBALS[$variable]) < 8) {
$GLOBALS[$variable . "Err"] = "Moet minstens 8 karakters bevatten";
$correct = false;
}
}
/* checks if an input is a valid email. */
function validateEmail($variable){
if (!filter_var($GLOBALS[$variable], FILTER_VALIDATE_EMAIL)) {
$GLOBALS[$variable . "Err"] = "Geldige email invullen!";
$correct = false;
} else if (getExistingEmail() == 1){
$GLOBALS[$variable . "Err"] = "Email bestaat al";
$correct = false;
}
}
/* checks if two passwords matches. */
function matchPassword(){
if ($_POST["password"] != $_POST["confirmpassword"]) {
$GLOBALS["confirmpasswordErr"] = "Wachtwoorden matchen niet";
$GLOBALS["correct"] = false;
}
}
// Checks if everything is filled in correctly
function registerCheck(){
if ($GLOBALS["correct"] == false){
$GLOBALS["genericErr"] = "Bepaalde velden zijn verkeerd of niet ingevuld!";
} else {
registerAccount();
header("location: login.php");
}
}
/* removes weird characters of an input. */
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>

View File

@@ -7,7 +7,7 @@ function selectAllFriends($userID) {
`username`,
IFNULL(
`profilepicture`,
'img/notbad.jpg'
'../img/notbad.jpg'
) AS profilepicture,
`onlinestatus`,
`role`

View File

@@ -22,7 +22,7 @@ function selectUser($userID) {
`username`,
IFNULL(
`profilepicture`,
'img/notbad.png'
'../img/notbad.jpg'
) AS profilepicture,
`bio`,
`role`,

View File

@@ -46,6 +46,6 @@
</form>
<!-- Button for going to the register screen -->
<div class="login_containerlogin">
<a href="https://myhyvesbookplus.nl/~joey/public/register.php" class="button">Registreer een account</a>
<a href="https://myhyvesbookplus.nl/register.php" class="button">Registreer een account</a>
</div>
</div>

View File

@@ -4,18 +4,19 @@
<div class="profile-button">
<p><img src="img/add-friend.png"> Als vriend toevoegen</p>
</div>
<h1 class="profile-username"><?php echo $user["username"] ?></h1>
<p><?php echo $user["bio"] ?></p>
<h1 class="profile-username"><?= $user["fname"]?> <?=$user["lname"]?> (<?=$user["username"]?>)</h1>
<p><?=$user["bio"]?></p>
</div>
<div class="item-box left platform">
<h2>Vrienden</h2>
<p>
<?php
while($friend = $friends->fetch()) {
echo "<a href='#' data-title='" . $friend["username"] . "'><img class='profile-picture' src='" . $friend["profilepicture"] . "' alt='" . $friend["username"] . "'s profielfoto></a>";
while($friend = $profile_friends->fetch()) {
echo "<a href='#' data-title='${friend["username"]}'><img class='profile-picture' src='${friend["profilepicture"]}' alt='${friend["username"]}'s profielfoto></a>";
}
if($friends->rowCount() === 0) {
echo "<p>Deze gebruiker heeft nog geen vrienden gemaakt.</p>";
}
@@ -27,7 +28,7 @@
<h2>Groepen</h2>
<p>
<?php
while($group = $groups->fetch()) {
while($group = $profile_groups->fetch()) {
echo "<a href='#' data-title='${group["name"]}'><img class='group-picture' src='${group["picture"]}' alt='${group["name"]}s logo'></a>";
}
@@ -51,4 +52,5 @@
";
}
?>
</div>
</div>

View File

@@ -108,7 +108,7 @@
<!-- Register email -->
<div class="login_containerregister">
<label><b>Email</b></label>
<input type="email"
<input type="text"
placeholder="Voer uw email in"
name="email"
value="<?php echo $email ?>"
@@ -130,6 +130,6 @@
<!-- Button for going back to login screen -->
<div class="login_containerlogin">
<a href="https://myhyvesbookplus.nl/~joey/public/login.php" class="button">Login met een account</a>
<a href="https://myhyvesbookplus.nl/login.php" class="button">Login met een account</a>
</div>
</div>