diff --git a/website/public/js/friendButtons.js b/website/public/js/friendButtons.js index 7b511a5..bdc3cc8 100644 --- a/website/public/js/friendButtons.js +++ b/website/public/js/friendButtons.js @@ -4,12 +4,14 @@ function placeFriendButtons() { friendshipStatus = data; $buttonContainer = $("div.friend-button-container"); $buttonContainer.children().remove(); + $("#start-profile-chat-form").hide(); if (friendshipStatus == -1) { return; } else if(friendshipStatus == 0) { $buttonContainer.append($("")); } else if(friendshipStatus == 1) { $buttonContainer.append($("")); + $("#start-profile-chat-form").show(); } else if(friendshipStatus == 2) { $buttonContainer.append($("")); } else if(friendshipStatus == 3) { diff --git a/website/public/login.php b/website/public/login.php index 0515793..81fee57 100644 --- a/website/public/login.php +++ b/website/public/login.php @@ -19,16 +19,24 @@ "; } + // define variables and set to empty values + $name = $surname = $bday = $username = $password = $confirmpassword = $location = $housenumber = $email = $confirmEmail = $captcha = $ip = ""; + $genericErr = $nameErr = $surnameErr = $bdayErr = $usernameErr = $passwordErr = $confirmpasswordErr = $locationErr = $housenumberErr = $emailErr = $confirmEmailErr = $captchaErr = ""; + $correct = true; + $day_date = "dag"; + $month_date = "maand"; + $year_date = "jaar"; + // Define variables and set to empty values - $uname = $psw =""; + $user = $psw =""; $loginErr = $resetErr =""; if ($_SERVER["REQUEST_METHOD"] == "POST") { switch ($_POST["submit"]) { case "login": try { - $uname = ($_POST["uname"]); - validateLogin($_POST["uname"], $_POST["psw"]); + $user = ($_POST["user"]); + validateLogin($_POST["user"], $_POST["psw"]); } catch(loginException $e) { $loginErr = $e->getMessage(); } @@ -46,7 +54,96 @@ "; } break; + case "register": + try { + $name = test_input(($_POST["name"])); + checkInputChoice($name, "lettersAndSpaces"); + } catch(lettersAndSpacesException $e){ + $correct = false; + $nameErr = $e->getMessage(); + } + try { + $surname = test_input(($_POST["surname"])); + checkInputChoice($surname, "lettersAndSpaces"); + } + catch(lettersAndSpacesException $e){ + $correct = false; + $surnameErr = $e->getMessage(); + } + + try{ + $day_date = test_input(($_POST["day_date"])); + $month_date = test_input(($_POST["month_date"])); + $year_date = test_input(($_POST["year_date"])); + $bday = $year_date . "-" . $month_date . "-" . $day_date; + checkInputChoice($bday, "bday"); + } catch(bdayException $e){ + $correct = false; + $bdayErr = $e->getMessage(); + } + + try{ + $username = str_replace(' ', '', test_input(($_POST["username"]))); + checkInputChoice($username, "username"); + } catch(usernameException $e){ + $correct = false; + $usernameErr = $e->getMessage(); + } + + try{ + $password = str_replace(' ', '', test_input(($_POST["password"]))); + checkInputChoice($password, "longerEight"); + matchPassword(); + } catch(passwordException $e){ + $correct = false; + $passwordErr = $e->getMessage(); + } catch(confirmPasswordException $e){ + $correct = false; + $confirmPasswordErr = $e->getMessage(); + } + + try{ + $location = test_input(($_POST["location"])); + checkInputChoice($location, "lettersAndSpaces"); + } catch(lettersAndSpacesException $e){ + $correct = false; + $locationErr = $e->getMessage(); + } + + try{ + $email = test_input(($_POST["email"])); + checkInputChoice($email, "email"); + $confirmEmail = test_input(($_POST["confirmEmail"])); + matchEmail(); + } catch(emailException $e){ + $correct = false; + $emailErr = $e->getMessage(); + } catch(confirmEmailException $e){ + $correct = false; + $confirmEmailErr = $e->getMessage(); + } + + try{ + $captcha = $_POST['g-recaptcha-response']; + checkCaptcha($captcha); + } catch(captchaException $e){ + $correct = false; + $captchaErr = $e->getMessage(); + } + + try { + getIp(); + registerCheck($correct); + sendConfirmEmailUsername($username); + } catch(registerException $e){ + echo ""; + $genericErr = $e->getMessage(); + } } } // // Trying to login diff --git a/website/public/register.php b/website/public/register.php index 1ce4817..0077e62 100644 --- a/website/public/register.php +++ b/website/public/register.php @@ -14,9 +14,12 @@ header("location: login.php"); } // define variables and set to empty values - $name = $surname = $bday = $username = $password = $confirmpassword = $location = $housenumber = $email = $captcha = $ip = ""; - $genericErr = $nameErr = $surnameErr = $bdayErr = $usernameErr = $passwordErr = $confirmpasswordErr = $locationErr = $housenumberErr = $emailErr = $captchaErr = ""; + $name = $surname = $bday = $username = $password = $confirmpassword = $location = $housenumber = $email = $confirmEmail = $captcha = $ip = ""; + $genericErr = $nameErr = $surnameErr = $bdayErr = $usernameErr = $passwordErr = $confirmpasswordErr = $locationErr = $housenumberErr = $emailErr = $confirmEmailErr = $captchaErr = ""; $correct = true; + $day_date = "dag"; + $month_date = "maand"; + $year_date = "jaar"; // Trying to register an account if ($_SERVER["REQUEST_METHOD"] == "POST") { @@ -38,7 +41,10 @@ } try{ - $bday = test_input(($_POST["bday"])); + $day_date = test_input(($_POST["day_date"])); + $month_date = test_input(($_POST["month_date"])); + $year_date = test_input(($_POST["year_date"])); + $bday = $year_date . "-" . $month_date . "-" . $day_date; checkInputChoice($bday, "bday"); } catch(bdayException $e){ $correct = false; @@ -76,9 +82,14 @@ try{ $email = test_input(($_POST["email"])); checkInputChoice($email, "email"); + $confirmEmail = test_input(($_POST["confirmEmail"])); + matchEmail(); } catch(emailException $e){ $correct = false; $emailErr = $e->getMessage(); + } catch(confirmEmailException $e){ + $correct = false; + $confirmEmailErr = $e->getMessage(); } try{ diff --git a/website/public/styles/index.css b/website/public/styles/index.css index 97d6f63..85cc670 100644 --- a/website/public/styles/index.css +++ b/website/public/styles/index.css @@ -28,10 +28,12 @@ body { form { /*background-color: #a87a87;*/ border-radius: 12px; - height: 85%; + height: 80%; margin: auto; - width: 80%; + width: 600px; overflow-y:auto; + overflow-x: hidden; + } @@ -130,7 +132,11 @@ label { margin: 34px auto; overflow-y: auto; padding: 20px; - width: 45%; + width: 600px; +} + +select{ + width: 18%; } ul { @@ -160,7 +166,7 @@ ul { margin: auto; padding: 0; border: 1px solid #888; - width: 500px; + width: 589px; box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19); -webkit-animation-name: animatetop; -webkit-animation-duration: 0.4s; @@ -200,10 +206,11 @@ ul { color: black; } -.modal-body {padding: 2px 16px;} +.modal-body { + padding: 2px 16px; +} .modal-footer { - padding: 2px 16px; background-color: #FBC02D; color: black; -} \ No newline at end of file +} diff --git a/website/public/styles/main.css b/website/public/styles/main.css index abda8be..0c37afa 100644 --- a/website/public/styles/main.css +++ b/website/public/styles/main.css @@ -275,3 +275,16 @@ div[data-title]:hover:after { display: inline-block; vertical-align: middle; } + +::-webkit-scrollbar { + width: 5px; + height: 5px; +} +::-webkit-scrollbar-track { + background: none; +} +::-webkit-scrollbar-thumb { + -webkit-border-radius: 20px; + border-radius: 20px; + background: #4CAF50; +} \ No newline at end of file diff --git a/website/public/styles/profile.css b/website/public/styles/profile.css index 85b2db5..becbeca 100644 --- a/website/public/styles/profile.css +++ b/website/public/styles/profile.css @@ -30,6 +30,7 @@ div.posts div.post { width: calc(100% - 40px); cursor: pointer; transition-duration: 250ms; + word-wrap: break-word; } div.posts div.post:hover { diff --git a/website/queries/checkInput.php b/website/queries/checkInput.php index 9b91833..fbf64a7 100644 --- a/website/queries/checkInput.php +++ b/website/queries/checkInput.php @@ -38,8 +38,7 @@ function checkName($variable){ if (empty($variable)) { throw new lettersAndSpacesException("Verplicht!"); } 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!"); } } @@ -48,12 +47,12 @@ function validateBday($variable){ if (empty($variable)) { throw new bdayException("Verplicht!"); } else { - if (!(validateDate($variable, "Y/m/d"))) { + if (!(validateDate($variable, "Y-m-d"))) { throw new bdayException("Geen geldige datum"); } else { - $dateNow = date("Y/m/d"); + $dateNow = date("Y-m-d"); if ($dateNow < $variable) { - throw new bdayException("Geen geldige datum"); + throw new bdayException("Geen geldige datum!"); } } } @@ -97,6 +96,12 @@ function validateEmail($variable){ } } +function matchEmail(){ + if (strtolower($_POST["email"]) != strtolower($_POST["confirmEmail"])){ + throw new confirmEmailException("Emails matchen niet!"); + } +} + /* checks if an input is a valid email. */ function resetEmail($variable){ if (empty($variable)) { @@ -206,6 +211,14 @@ class emailException extends Exception } } +class confirmEmailException extends Exception +{ + public function __construct($message = "", $code = 0, Exception $previous = null) + { + parent::__construct($message, $code, $previous); + } +} + class captchaException extends Exception { public function __construct($message = "", $code = 0, Exception $previous = null) diff --git a/website/queries/login.php b/website/queries/login.php index 2af255a..6af9e1e 100644 --- a/website/queries/login.php +++ b/website/queries/login.php @@ -9,10 +9,11 @@ function getUser() { FROM `user` WHERE - `username` LIKE :username + `username` LIKE :username OR + `email` LIKE :username "); - $stmt->bindParam(":username", $_POST["uname"]); + $stmt->bindParam(":username", test_input($_POST["user"])); $stmt->execute(); return $stmt->fetch(PDO::FETCH_ASSOC); } @@ -20,7 +21,7 @@ function getUser() { function validateLogin($username, $password){ // Empty username or password field if (empty($username) || empty($password)) { - throw new loginException("Gebruikersnaam of wachtwoord is niet ingevuld"); + throw new loginException("Inloggegevens zijn niet ingevuld"); } else { $psw = test_input($password); diff --git a/website/queries/private_message.php b/website/queries/private_message.php index fecea2b..4d48d3a 100644 --- a/website/queries/private_message.php +++ b/website/queries/private_message.php @@ -1,91 +1,105 @@ prepare(" + SELECT + * + FROM + `private_message` + WHERE + `origin` = :user1 AND + `destination` = :user2 OR + `origin` = :user2 AND + `destination` = :user1 + ORDER BY + `messageID` ASC + "); - $stmt = $GLOBALS["db"]->prepare(" - SELECT - * - FROM - `private_message` - WHERE - `origin` = :user1 AND - `destination` = :user2 OR - `origin` = :user2 AND - `destination` = :user1 - ORDER BY - `messageID` ASC - "); + $stmt->bindParam(":user1", $user1ID); + $stmt->bindParam(":user2", $user2ID); - $stmt->bindParam(":user1", $user1ID); - $stmt->bindParam(":user2", $user2ID); + $stmt->execute(); - $stmt->execute(); - - return json_encode($stmt->fetchAll()); + return json_encode($stmt->fetchAll()); + } else { + return "[]"; + } } function sendMessage($destination, $content) { - $stmt = $GLOBALS["db"]->prepare(" - INSERT INTO - `private_message` - ( - `origin`, - `destination`, - `content` - ) - VALUES - ( - :origin, - :destination, - :content - ) - "); + require_once("friendship.php"); + if (getFriendshipStatus($destination) == 1) { + $stmt = $GLOBALS["db"]->prepare(" + INSERT INTO + `private_message` + ( + `origin`, + `destination`, + `content` + ) + VALUES + ( + :origin, + :destination, + :content + ) + "); - return $stmt->execute(array( - "origin" => $_SESSION["userID"], - "destination" => $destination, - "content" => $content - )); + return $stmt->execute(array( + "origin" => $_SESSION["userID"], + "destination" => $destination, + "content" => $content + )); + } else { + return false; + } } function getNewChatMessages($lastID, $destination) { - $stmt = $GLOBALS["db"]->prepare(" - SELECT - * - FROM - `private_message` - WHERE - ( - `origin` = :user1 AND - `destination` = :user2 OR - `origin` = :user2 AND - `destination` = :user1) AND - `messageID` > :lastID - ORDER BY - `messageID` ASC - "); + require_once("friendship.php"); + if (getFriendshipStatus($destination) == 1) { + $stmt = $GLOBALS["db"]->prepare(" + SELECT + * + FROM + `private_message` + WHERE + ( + `origin` = :user1 AND + `destination` = :user2 OR + `origin` = :user2 AND + `destination` = :user1) AND + `messageID` > :lastID + ORDER BY + `messageID` ASC + "); - $stmt->bindParam(':user1', $_SESSION["userID"]); - $stmt->bindParam(':user2', $destination); - $stmt->bindParam(':lastID', $lastID); + $stmt->bindParam(':user1', $_SESSION["userID"]); + $stmt->bindParam(':user2', $destination); + $stmt->bindParam(':lastID', $lastID); - $stmt->execute(); + $stmt->execute(); - return json_encode($stmt->fetchAll()); + return json_encode($stmt->fetchAll()); + } else { + return "[]"; + } } function selectAllUnreadChat() { $stmt = $GLOBALS["db"]->prepare(" SELECT - LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `fullname`, + LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) AS `fullname`, `user`.`userID`, IFNULL( `profilepicture`, '../img/avatar-standard.png' ) AS profilepicture, - LEFT(`private_message`.`content`, 15) as `content` + LEFT(`private_message`.`content`, 15) AS `content` FROM `private_message`, `friendship`, @@ -101,7 +115,8 @@ function selectAllUnreadChat() { `friendship`.chatLastVisted2 IS NULL)) AND `private_message`.`origin` = `user`.`userID` AND `private_message`.`destination` = :userID AND - `user`.`role` != 'banned' + `user`.`role` != 'banned' AND + `friendship`.`status` = 'confirmed' GROUP BY `user`.`userID` diff --git a/website/queries/register.php b/website/queries/register.php index 738ef43..be9d415 100644 --- a/website/queries/register.php +++ b/website/queries/register.php @@ -10,7 +10,7 @@ function getExistingUsername() { `username` LIKE :username "); - $stmt->bindParam(":username", $_POST["username"]); + $stmt->bindParam(":username", test_input($_POST["username"])); $stmt->execute(); return $stmt->rowCount(); @@ -26,7 +26,7 @@ function getExistingEmail() { `email` LIKE :email "); - $stmt->bindParam(":email", $_POST["email"]); + $stmt->bindParam(":email", test_input($_POST["email"])); $stmt->execute(); return $stmt->rowCount(); @@ -42,7 +42,7 @@ function getResetEmail() { `email` LIKE :email "); - $stmt->bindParam(":email", $_POST["forgotEmail"]); + $stmt->bindParam(":email", test_input($_POST["forgotEmail"])); $stmt->execute(); return $stmt->rowCount(); @@ -70,15 +70,21 @@ function registerAccount() { $hash=password_hash($_POST["password"], PASSWORD_DEFAULT); - $stmt->bindParam(":fname", $_POST["name"]); - $stmt->bindParam(":lname", $_POST["surname"]); - $stmt->bindParam(":bday", $_POST["bday"]); - $stmt->bindParam(":username", $_POST["username"]); - $stmt->bindParam(":password", $hash); - $stmt->bindParam(":location", $_POST["location"]); - $stmt->bindParam(":email", (strtolower($_POST["email"]))); + $stmt->bindParam(":fname", test_input($_POST["name"])); + $stmt->bindParam(":lname", test_input($_POST["surname"])); + $stmt->bindParam(":bday", test_input($_POST["bday"])); + $stmt->bindParam(":username", test_input($_POST["username"])); + $stmt->bindParam(":password", test_input($hash)); + $stmt->bindParam(":location", test_input($_POST["location"])); + $stmt->bindParam(":email", test_input(strtolower($_POST["email"]))); $stmt->execute(); $stmt->rowCount(); } + +function submitselect($date, $value){ + if ($date == $value){ + echo "selected"; + } +} ?> diff --git a/website/queries/user.php b/website/queries/user.php index 4a7ee57..3b0c4a8 100644 --- a/website/queries/user.php +++ b/website/queries/user.php @@ -35,6 +35,7 @@ function getUsername($userID) { function selectUser($me, $other) { $stmt = $GLOBALS["db"]->prepare(" SELECT + `userID`, `username`, `birthdate`, `location`, @@ -94,7 +95,7 @@ function selectAllUserGroups($userID) { `group_page`.`groupID` = `group_member`.`groupID` WHERE `userID` = :userID AND - `role` = 1 + `role` = 'member' "); $stmt->bindParam(':userID', $userID, PDO::PARAM_INT); @@ -331,9 +332,10 @@ function searchSomeUsers($n, $m, $search) { FROM `user` WHERE - `username` LIKE :keyword OR + (`username` LIKE :keyword OR `fname` LIKE :keyword OR - `lname` LIKE :keyword + `lname` LIKE :keyword) AND + `role` != 'banned' ORDER BY `fname`, `lname`, diff --git a/website/views/chat-view.php b/website/views/chat-view.php index 0d90149..974b441 100644 --- a/website/views/chat-view.php +++ b/website/views/chat-view.php @@ -74,6 +74,7 @@ name="content" id="newContent" placeholder="Schrijf een bericht..." + autocomplete="off" autofocus required /> diff --git a/website/views/login-view.php b/website/views/login-view.php index de4c48b..b9052b3 100644 --- a/website/views/login-view.php +++ b/website/views/login-view.php @@ -13,12 +13,12 @@