Hendrik post #126
31
website/public/API/edit_friendship.php
Normal file
31
website/public/API/edit_friendship.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
require("../../queries/friendship.php");
|
||||
require("../../queries/user.php");
|
||||
|
||||
if(empty($_POST["userID"]) OR empty($_POST["delete"]) AND empty($_POST["accept"]) AND empty($_POST["request"])) {
|
||||
echo "Not enough arguments.";
|
||||
return;
|
||||
}
|
||||
|
||||
$friendship_status = getFriendshipStatus($_POST["userID"]);
|
||||
echo "\nfriendshipstatus: $friendship_status";
|
||||
echo "You: " . $_SESSION["userID"];
|
||||
echo "other user: " . $_POST["userID"];
|
||||
|
||||
|
||||
if(!empty($_POST["request"]) AND $friendship_status == 0) {
|
||||
echo "request";
|
||||
requestFriendship($_POST["userID"]);
|
||||
} else if(!empty($_POST["delete"]) AND in_array($friendship_status, array(1, 2, 3))) {
|
||||
echo "delete";
|
||||
removeFriendship($_POST["userID"]);
|
||||
} else if (!empty($_POST["accept"]) AND $friendship_status == 3) {
|
||||
echo "accept";
|
||||
acceptFriendship($_POST["userID"]);
|
||||
}
|
||||
|
||||
$username = getUsername($_POST["userID"]);
|
||||
|
||||
header("Location: ../profile.php?username=$username");
|
||||
@@ -3,6 +3,6 @@
|
||||
session_start();
|
||||
|
||||
require_once ("../../queries/connect.php");
|
||||
require_once ("../../queries/friendship.php");
|
||||
require_once ("../../queries/private_message.php");
|
||||
|
||||
echo selectAllUnreadChat();
|
||||
@@ -5,9 +5,12 @@ session_start();
|
||||
require_once("../../queries/connect.php");
|
||||
require_once("../../queries/private_message.php");
|
||||
require_once("../../queries/checkInput.php");
|
||||
require_once("../../queries/friendship.php");
|
||||
|
||||
if (isset($_POST["lastID"]) && $_POST["lastID"] != "") {
|
||||
echo getNewChatMessages(test_input($_POST["lastID"]), test_input($_POST["destination"]));
|
||||
setLastVisited(test_input($_POST["destination"]));
|
||||
} else {
|
||||
echo getOldChatMessages(test_input($_POST["destination"]));
|
||||
setLastVisited(test_input($_POST["destination"]));
|
||||
}
|
||||
49
website/public/emailconfirm.php
Normal file
49
website/public/emailconfirm.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
include_once("../queries/connect.php");
|
||||
if (array_key_exists("u", $_GET) and array_key_exists("h", $_GET)) {
|
||||
$checkHash = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`email`,
|
||||
`role`
|
||||
FROM
|
||||
`user`
|
||||
WHERE
|
||||
`userID` = :userID
|
||||
");
|
||||
$checkHash->bindParam(":userID", $_GET["u"]);
|
||||
$checkHash->execute();
|
||||
$result = $checkHash->fetch();
|
||||
$email = $result["email"];
|
||||
$role = $result["role"];
|
||||
if ($role == "unconfirmed") {
|
||||
doActivate($email);
|
||||
} else {
|
||||
echo "Ongeldige link.";
|
||||
}
|
||||
|
||||
} else {
|
||||
echo "Ongeldige link.";
|
||||
}
|
||||
|
||||
function doActivate(string $email) {
|
||||
if (password_verify($email, $_GET["h"])) {
|
||||
$confirmUser = $GLOBALS["db"]->prepare("
|
||||
UPDATE
|
||||
`user`
|
||||
SET
|
||||
`role` = :role
|
||||
WHERE
|
||||
`userID` = :userID
|
||||
");
|
||||
$confirmUser->bindValue(":role", "user");
|
||||
$confirmUser->bindParam(":userID", $_GET["u"]);
|
||||
$confirmUser->execute();
|
||||
if ($confirmUser->rowCount()) {
|
||||
echo "Email bevestigd <br />
|
||||
<a href='index.php'>U wordt automatisch doorgestuurd naar de login pagina over 5 seconden.</a> ";
|
||||
header("refresh:5;url=login.php");
|
||||
}
|
||||
} else {
|
||||
echo "Ongeldige link.";
|
||||
}
|
||||
}
|
||||
BIN
website/public/img/avatar-standard.png
Normal file
BIN
website/public/img/avatar-standard.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 98 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 24 KiB |
@@ -53,8 +53,8 @@ function switchUser(userID) {
|
||||
$(".destinationID").val(userID);
|
||||
$("#chat-history").html("");
|
||||
$("#lastID").val("");
|
||||
$(".chat-left .friend-item").removeClass("active-friend-chat");
|
||||
$(".chat-left #friend-item-" + userID).addClass("active-friend-chat");
|
||||
$("#chat-recent-panel .friend-item").removeClass("active-friend-chat");
|
||||
$("#chat-left #friend-item-" + userID).addClass("active-friend-chat");
|
||||
}
|
||||
|
||||
function sayEmpty() {
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
function showNotifications(notifications, id) {
|
||||
$("#" + id).html("");
|
||||
function showFriendNotifications(notifications) {
|
||||
$("#friendrequestslist").html("");
|
||||
for (i in notifications) {
|
||||
$("#" + id).append(" \
|
||||
<li class='friend-item $extraItem'> \
|
||||
var outgoing = "";
|
||||
if (notifications[i].friend_state == "3") {
|
||||
outgoing = "<button\
|
||||
name='accept' \
|
||||
class='accept-notification' \
|
||||
value='"+ notifications[i].userID +"'> \
|
||||
<i class='fa fa-check'></i> \
|
||||
</button>";
|
||||
}
|
||||
|
||||
$("#friendrequestslist").append(" \
|
||||
<li class='friend-item'> \
|
||||
<form action='profile.php' method='get'> \
|
||||
<button type='submit' \
|
||||
name='username' \
|
||||
@@ -13,6 +23,41 @@ function showNotifications(notifications, id) {
|
||||
</div> \
|
||||
</button> \
|
||||
</form> \
|
||||
<div class='notification-options'>\
|
||||
<form action='API/edit_friendship.php' method='post'> \
|
||||
<input type='hidden' name='userID' value='"+ notifications[i].userID +"' /> \
|
||||
"+ outgoing +" \
|
||||
<button type='submit' \
|
||||
name='delete' \
|
||||
class='deny-notification' \
|
||||
value='"+ notifications[i].userID +"'> \
|
||||
<i class='fa fa-times'></i> \
|
||||
</button>\
|
||||
<form>\
|
||||
</div> \
|
||||
</li> \
|
||||
");
|
||||
}
|
||||
}
|
||||
|
||||
function showChatNotifications(notifications) {
|
||||
$("#unreadChatlist").html("");
|
||||
for (i in notifications) {
|
||||
$("#unreadChatlist").append(" \
|
||||
<li class='friend-item'> \
|
||||
<form action='chat.php' method='get'> \
|
||||
<button type='submit' \
|
||||
name='chatID' \
|
||||
value='"+ notifications[i].userID +"'> \
|
||||
<div class='friend'> \
|
||||
<img alt='PF' class='profile-picture' src='"+ notifications[i].profilepicture +"'/> \
|
||||
<div class='friend-name'> \
|
||||
"+ notifications[i].name +"<br/> \
|
||||
<span style='color: #666'>"+ notifications[i].content +"</span> \
|
||||
</div> \
|
||||
</div> \
|
||||
</button> \
|
||||
</form> \
|
||||
</li> \
|
||||
");
|
||||
}
|
||||
@@ -23,14 +68,14 @@ function loadNotifications() {
|
||||
"API/loadFriendRequestNotifications.php"
|
||||
).done(function(data) {
|
||||
if (data && data != "[]") {
|
||||
showNotifications(JSON.parse(data), "friendrequestslist");
|
||||
showFriendNotifications(JSON.parse(data));
|
||||
}
|
||||
});
|
||||
$.post(
|
||||
"API/loadChatNotifications.php"
|
||||
).done(function(data) {
|
||||
if (data && data != "[]") {
|
||||
showNotifications(JSON.parse(data), "unreadChatlist");
|
||||
showChatNotifications(JSON.parse(data));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -4,5 +4,12 @@ function checkLoggedIn() {
|
||||
} else {
|
||||
window.location.href = "profile.php";
|
||||
}
|
||||
document.getElementById("demo").innerHTML = x;
|
||||
}
|
||||
|
||||
function bannedAlert(){
|
||||
alert("Your account is banned");
|
||||
}
|
||||
|
||||
function emailNotConfirmed(){
|
||||
alert("Your account has not been verified yet!\nAnother email has been sent to you")
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
require_once("../queries/connect.php");
|
||||
include_once("../queries/login.php");
|
||||
include_once("../queries/checkInput.php");
|
||||
include_once("../queries/emailconfirm.php");
|
||||
?>
|
||||
<body>
|
||||
<?php
|
||||
@@ -22,26 +23,11 @@
|
||||
|
||||
// Trying to login
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
// Empty username or password field
|
||||
if (empty($_POST["uname"]) || empty($_POST["psw"])) {
|
||||
$loginErr = "Gebruikersnaam of wachtwoord is niet ingevuld";
|
||||
|
||||
}
|
||||
else {
|
||||
$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)) {
|
||||
$_SESSION["userID"] = $userid;
|
||||
header("location: profile.php");
|
||||
|
||||
} else {
|
||||
$loginErr = "Inloggegevens zijn niet correct";
|
||||
}
|
||||
|
||||
try{
|
||||
$uname = ($_POST["uname"]);
|
||||
validateLogin($_POST["uname"], $_POST["psw"]);
|
||||
} catch(loginException $e) {
|
||||
$loginErr = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<?php
|
||||
include("../views/login_head.php");
|
||||
require_once("../queries/connect.php");
|
||||
include_once("../queries/login.php");
|
||||
?>
|
||||
<body>
|
||||
<?php
|
||||
session_start();
|
||||
unset($_SESSION["userID"]);
|
||||
header("Location: login.php");
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
session_start();
|
||||
session_destroy();
|
||||
header("Location: login.php");
|
||||
@@ -22,7 +22,7 @@ if(empty($_GET["username"])) {
|
||||
$userID = getUserID($_GET["username"]);
|
||||
}
|
||||
|
||||
$user = selectUser($userID);
|
||||
$user = selectUser($_SESSION["userID"], $userID);
|
||||
$profile_friends = selectAllFriends($userID);
|
||||
$profile_groups = selectAllUserGroups($userID);
|
||||
$posts = selectAllUserPosts($userID);
|
||||
|
||||
@@ -5,38 +5,97 @@
|
||||
require_once("../queries/connect.php");
|
||||
include_once("../queries/register.php");
|
||||
include_once("../queries/checkInput.php");
|
||||
include_once("../queries/emailconfirm.php");
|
||||
?>
|
||||
<body>
|
||||
<?php
|
||||
session_start();
|
||||
if(isset($_SESSION["userID"])){
|
||||
header("location: profile.php");
|
||||
header("location: login.php");
|
||||
}
|
||||
// define variables and set to empty values
|
||||
$name = $surname = $bday = $username = $password = $confirmpassword = $location = $housenumber = $email = "";
|
||||
$genericErr = $nameErr = $surnameErr = $bdayErr = $usernameErr = $passwordErr = $confirmpasswordErr = $locationErr = $housenumberErr = $emailErr = "";
|
||||
$name = $surname = $bday = $username = $password = $confirmpassword = $location = $housenumber = $email = $captcha = $ip = "";
|
||||
$genericErr = $nameErr = $surnameErr = $bdayErr = $usernameErr = $passwordErr = $confirmpasswordErr = $locationErr = $housenumberErr = $emailErr = $captchaErr = "";
|
||||
$correct = true;
|
||||
|
||||
// Trying to register an account
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
checkInputChoice("name", "lettersAndSpace");
|
||||
checkInputChoice("surname", "lettersAndSpace");
|
||||
|
||||
if (empty($_POST["bday"])) {
|
||||
$bdayErr = "Geboortedatum is verplicht!";
|
||||
try {
|
||||
$name = test_input(($_POST["name"]));
|
||||
checkInputChoice($name, "lettersAndSpaces");
|
||||
} catch(lettersAndSpacesException $e){
|
||||
$correct = false;
|
||||
|
||||
} else {
|
||||
$bday = test_input($_POST["bday"]);
|
||||
$nameErr = $e->getMessage();
|
||||
}
|
||||
|
||||
checkInputChoice("username", "username");
|
||||
checkInputChoice("password", "longerEight");
|
||||
checkInputChoice("confirmpassword", "");
|
||||
try {
|
||||
$surname = test_input(($_POST["surname"]));
|
||||
checkInputChoice($surname, "lettersAndSpaces");
|
||||
}
|
||||
catch(lettersAndSpacesException $e){
|
||||
$correct = false;
|
||||
$surnameErr = $e->getMessage();
|
||||
}
|
||||
|
||||
try{
|
||||
$bday = test_input(($_POST["bday"]));
|
||||
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();
|
||||
checkInputChoice("location", "lettersAndSpace");
|
||||
checkInputChoice("email", "email");
|
||||
registerCheck();
|
||||
} 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");
|
||||
} catch(emailException $e){
|
||||
$correct = false;
|
||||
$emailErr = $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){
|
||||
$genericErr = $e->getMessage();
|
||||
}
|
||||
}
|
||||
/* This view adds register view */
|
||||
include("../views/register-view.php");
|
||||
|
||||
@@ -12,23 +12,28 @@
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
$notImplemented = new settingsMessage("angry", "Deze functie werkt nog niet :(");
|
||||
|
||||
$alertClass;
|
||||
$alertMessage;
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
try {
|
||||
switch ($_POST["form"]) {
|
||||
case "profile":
|
||||
$result = updateSettings();
|
||||
updateSettings();
|
||||
break;
|
||||
case "password":
|
||||
$result = changePassword();
|
||||
changePassword();
|
||||
break;
|
||||
case "email":
|
||||
$result = changeEmail();
|
||||
changeEmail();
|
||||
break;
|
||||
case "picture":
|
||||
updateProfilePicture();
|
||||
$result = new settingsMessage("happy", "Deze melding doet nog niks nuttigs.");
|
||||
updateAvatar();
|
||||
break;
|
||||
|
||||
}
|
||||
} catch (AlertMessage $w) {
|
||||
$alertClass = $w->getClass();
|
||||
$alertMessage = $w->getMessage();
|
||||
}
|
||||
}
|
||||
include("../views/main.php");
|
||||
|
||||
@@ -1,34 +1,38 @@
|
||||
/* Overall chat-screen */
|
||||
.chat {
|
||||
position: fixed;
|
||||
|
||||
top: 80px;
|
||||
left: 256px;
|
||||
padding: 20px 0;
|
||||
width: calc(100% - 256px);
|
||||
height: calc(100% - 120px);
|
||||
display: inline-flex;
|
||||
|
||||
padding: 20px 0;
|
||||
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.chat-left {
|
||||
#chat-recent-panel {
|
||||
width: 256px;
|
||||
height: calc(100% - 100px);
|
||||
margin: 0 10px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.chat-right {
|
||||
width: calc(100% - 256px - 40px);
|
||||
height: calc(100% - 80px);
|
||||
margin-right: 10px;
|
||||
display: inline-block;
|
||||
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
/* Chat history. */
|
||||
.chat-history {
|
||||
#chat-history {
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
height: 100%;
|
||||
|
||||
width: calc(100% - 256px - 75px);
|
||||
height: calc(100% - 80px);
|
||||
|
||||
padding: 10px;
|
||||
|
||||
display: inline-block;
|
||||
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
@@ -36,7 +40,13 @@
|
||||
.chat-message {
|
||||
width: 100%;
|
||||
min-height: 40px;
|
||||
padding-top: 10px;
|
||||
padding: 10px 0;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.chat-message::after {
|
||||
content: '';
|
||||
display: table;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
@@ -63,7 +73,7 @@
|
||||
/* Chat reply field */
|
||||
|
||||
.chat-field {
|
||||
width: 100%;
|
||||
width: calc(100% - 10px);
|
||||
display: table;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
a.button {
|
||||
background-color: #C8CABD;
|
||||
border-radius: 10px;
|
||||
border-radius: 5px;
|
||||
color: black;
|
||||
cursor: pointer;
|
||||
height: 50%;
|
||||
margin: 8px 0;
|
||||
padding: 14px 20px;
|
||||
width: 25%;
|
||||
padding: 8px 20px;
|
||||
width: 50%;
|
||||
font-family: Arial;
|
||||
font-size: 16px;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
/* Body */
|
||||
body {
|
||||
height: 100%;
|
||||
background-color: #C8CABD;
|
||||
background-color: #FBC02D;
|
||||
/*background-image: url(http://play.pokemonshowdown.com/fx/client-bg-shaymin.jpg);
|
||||
background-size: cover;
|
||||
background-attachment: fixed;*/
|
||||
@@ -24,31 +23,14 @@ body {
|
||||
font-family: Arial, sans-serif;
|
||||
}
|
||||
|
||||
/* The Close Button */
|
||||
.close {
|
||||
/* Position it in the top right corner outside of the modal */
|
||||
color: white;
|
||||
font-size: 100px;
|
||||
font-weight: bold;
|
||||
position: absolute;
|
||||
right: 25px;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
/* Close button on hover */
|
||||
.close:hover,
|
||||
.close:focus {
|
||||
color: red;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* inlogform */
|
||||
form {
|
||||
/*background-color: #a87a87;*/
|
||||
border-radius: 12px;
|
||||
height: 70%;
|
||||
height: 75%;
|
||||
margin: auto;
|
||||
width: 70%;
|
||||
width: 80%;
|
||||
overflow-y:auto;
|
||||
}
|
||||
|
||||
@@ -72,24 +54,20 @@ input[type=text], input[type=password], input[type=email], input[type="date"] {
|
||||
border-color: #C8CABD;
|
||||
display: inline-block;
|
||||
height: 60%;
|
||||
font-size: 16px;
|
||||
padding: 8px 20px;
|
||||
margin: 4px 0;
|
||||
width: 70%;
|
||||
width: 55%;
|
||||
}
|
||||
/*
|
||||
input[type=text], input[type=password], input[type=email], input[type="date"] {
|
||||
border: 0px;
|
||||
border-bottom: 4px solid lightgray;
|
||||
border-radius: 0px;
|
||||
}*/
|
||||
|
||||
button[type=submit] {
|
||||
background-color: #C8CABD;
|
||||
color: black ;
|
||||
color: black;
|
||||
cursor: pointer;
|
||||
font-family: Arial;
|
||||
font-size: 16px;
|
||||
width: 50%;
|
||||
font-size: 22px;
|
||||
height: 30px;
|
||||
width: 120px;
|
||||
}
|
||||
|
||||
.error {
|
||||
@@ -106,12 +84,12 @@ label {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
background-color: #C8CABD;
|
||||
height: 30px;
|
||||
width: 90px;
|
||||
padding: 3px 3px 3px 0px;
|
||||
height: 25px;
|
||||
width: 120px;
|
||||
padding: 3px 3px 3px 3px;
|
||||
text-align: center;
|
||||
border-radius: 0px 10px 10px 0px;
|
||||
font-size: 24px;
|
||||
border-radius: 0px 5px 5px 0px;
|
||||
font-size: 22px;
|
||||
|
||||
}
|
||||
.left-arrow:after {
|
||||
@@ -121,9 +99,9 @@ label {
|
||||
right: 100%;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
border-top: 15px solid transparent;
|
||||
border-top: 12px solid transparent;
|
||||
border-right: 20px solid #C8CABD;
|
||||
border-bottom: 15px solid transparent;
|
||||
border-bottom: 12px solid transparent;
|
||||
border-left: 0px solid transparent;
|
||||
}
|
||||
|
||||
@@ -135,7 +113,7 @@ label {
|
||||
|
||||
/* padding voor login_containers */
|
||||
.login_containerlogin {
|
||||
padding:25px;
|
||||
padding:16px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@@ -163,7 +141,7 @@ label {
|
||||
margin: 34px auto;
|
||||
overflow-y: auto;
|
||||
padding: 20px;
|
||||
width: 50%;
|
||||
width: 45%;
|
||||
}
|
||||
|
||||
/*.platform {
|
||||
|
||||
@@ -242,3 +242,23 @@ div[data-title]:hover:after {
|
||||
line-height: normal;
|
||||
font-family: Arial, sans-serif;
|
||||
}
|
||||
|
||||
.friend {
|
||||
|
||||
}
|
||||
|
||||
|
||||
.friend-item, .group-item {
|
||||
cursor: pointer;
|
||||
transition-duration: 250ms;
|
||||
}
|
||||
|
||||
.friend-item:hover, .group-item:hover {
|
||||
background: #FBC02D;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
|
||||
}
|
||||
|
||||
.friend-name {
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
@@ -34,16 +34,6 @@
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.friend-item, .group-item {
|
||||
cursor: pointer;
|
||||
transition-duration: 250ms;
|
||||
}
|
||||
|
||||
.friend-item:hover, .group-item:hover {
|
||||
background: #FBC02D;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
|
||||
}
|
||||
|
||||
.menu button {
|
||||
background: none;
|
||||
color: inherit;
|
||||
@@ -74,3 +64,31 @@
|
||||
#quick-links i:hover {
|
||||
color: #FBC02D;
|
||||
}
|
||||
|
||||
.notification-options {
|
||||
display: none;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.notification-options form {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.notification-options button {
|
||||
display: inline-block;
|
||||
padding: 5px 20px;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.accept-notification:hover {
|
||||
color: #4CAF50;
|
||||
}
|
||||
|
||||
.deny-notification:hover {
|
||||
color: firebrick;
|
||||
}
|
||||
|
||||
.friend-item:hover .notification-options {
|
||||
display: inline-block;
|
||||
}
|
||||
@@ -78,8 +78,9 @@ div.posts .post form textarea.newpost {
|
||||
font-size: 0.8em;
|
||||
}
|
||||
|
||||
.profile-button {
|
||||
input.profile-button {
|
||||
float: right;
|
||||
height: auto;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #4CAF50;
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* Function for checking inputfields
|
||||
* @param variable $variable Give name of the inputfield.
|
||||
* @param string $option Give the name of the option.
|
||||
* @param String $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);
|
||||
case "lettersAndSpaces";
|
||||
checkName($variable);
|
||||
break;
|
||||
|
||||
case "bday";
|
||||
validateBday($variable);
|
||||
break;
|
||||
|
||||
case "username";
|
||||
@@ -31,67 +29,111 @@ function checkInputChoice($variable, $option){
|
||||
|
||||
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;
|
||||
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!");
|
||||
}
|
||||
}
|
||||
|
||||
/* Checks for bday */
|
||||
function validateBday($variable){
|
||||
if (empty($variable)) {
|
||||
throw new bdayException("Verplicht!");
|
||||
} else {
|
||||
if (!(validateDate($variable, "Y/m/d"))) {
|
||||
throw new bdayException("Geen geldige datum");
|
||||
} else {
|
||||
$dateNow = date("Y/m/d");
|
||||
if ($dateNow < $variable) {
|
||||
throw new bdayException("Geen geldige datum");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Checks for date
|
||||
function validateDate($date, $format)
|
||||
{
|
||||
$d = DateTime::createFromFormat($format, $date);
|
||||
return $d && $d->format($format) == $date;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
if (empty($variable)) {
|
||||
throw new usernameException("Verplicht!");
|
||||
} else if (strlen($variable) < 6) {
|
||||
throw new usernameException("Moet minstens 6 karakters bevatten");
|
||||
} else if (getExistingUsername() == 1) {
|
||||
$GLOBALS[$variable . "Err"] = "Gebruikersnaam bestaat al";
|
||||
$correct = false;
|
||||
throw new usernameException("Gebruikersnaam bestaal al");
|
||||
}
|
||||
}
|
||||
|
||||
/* 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;
|
||||
if (empty($variable)) {
|
||||
throw new passwordException("Verplicht!");
|
||||
} else if (strlen($variable) < 8) {
|
||||
throw new passwordException("Moet minstens 8 karakters bevatten");
|
||||
}
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
if (empty($variable)) {
|
||||
throw new emailException("Verplicht!");
|
||||
} else if (!filter_var($variable, FILTER_VALIDATE_EMAIL)) {
|
||||
throw new emailException("Geldige email invullen");
|
||||
} else if (getExistingEmail() == 1){
|
||||
$GLOBALS[$variable . "Err"] = "Email bestaat al";
|
||||
$correct = false;
|
||||
|
||||
throw new emailException("Email bestaal al!");
|
||||
}
|
||||
}
|
||||
|
||||
/* checks if two passwords matches. */
|
||||
function matchPassword(){
|
||||
if ($_POST["password"] != $_POST["confirmpassword"]) {
|
||||
$GLOBALS["confirmpasswordErr"] = "Wachtwoorden matchen niet";
|
||||
$GLOBALS["correct"] = false;
|
||||
|
||||
throw new confirmPasswordException("Wachtwoorden matchen niet!");
|
||||
}
|
||||
}
|
||||
|
||||
// Checks if everything is filled in correctly
|
||||
function registerCheck(){
|
||||
if ($GLOBALS["correct"] == false){
|
||||
$GLOBALS["genericErr"] = "Bepaalde velden zijn verkeerd of niet ingevuld!";
|
||||
/* Checks if captcha is correctly filled in */
|
||||
function checkCaptcha($captcha){
|
||||
if(!$captcha){
|
||||
throw new captchaException("Captcha needs to be filled in!");
|
||||
} else {
|
||||
$response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6Lc72xIUAAAAAPizuF3nUbklCPljVCVzgYespz8o&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']));
|
||||
if($response->success==false) {
|
||||
throw new captchaException("You are a spammer!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Get ip adres */
|
||||
function getIp(){
|
||||
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
|
||||
$GLOBALS["ip"] = $_SERVER['HTTP_CLIENT_IP'];
|
||||
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||
$GLOBALS["ip"] = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
} else {
|
||||
$GLOBALS["ip"] = $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
}
|
||||
|
||||
/* Checks if everything is filled in correctly */
|
||||
function registerCheck($status){
|
||||
if ($status == false){
|
||||
throw new registerException("Bepaalde velden zijn verkeerd of niet ingevuld");
|
||||
} else {
|
||||
registerAccount();
|
||||
header("location: login.php");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,4 +144,69 @@ function test_input($data) {
|
||||
$data = htmlspecialchars($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
class lettersAndSpacesException extends Exception
|
||||
{
|
||||
public function __construct($message = "", $code = 0, Exception $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class bdayException extends Exception
|
||||
{
|
||||
public function __construct($message = "", $code = 0, Exception $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
|
||||
class usernameException extends Exception
|
||||
{
|
||||
public function __construct($message = "", $code = 0, Exception $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
|
||||
class passwordException extends Exception
|
||||
{
|
||||
public function __construct($message = "", $code = 0, Exception $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
|
||||
class confirmPasswordException extends Exception
|
||||
{
|
||||
public function __construct($message = "", $code = 0, Exception $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
|
||||
class emailException 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)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
|
||||
class registerException extends Exception
|
||||
{
|
||||
public function __construct($message = "", $code = 0, Exception $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
42
website/queries/emailconfirm.php
Normal file
42
website/queries/emailconfirm.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
function sendConfirmEmailUsername(string $username) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`userID`
|
||||
FROM
|
||||
`user`
|
||||
WHERE
|
||||
`username` = :username
|
||||
");
|
||||
$stmt->bindParam(":username", $username);
|
||||
$stmt->execute();
|
||||
$userID = $stmt->fetch()["username"];
|
||||
sendConfirmEmail($userID);
|
||||
}
|
||||
|
||||
function sendConfirmEmail(int $userID) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`email`,
|
||||
`fname`
|
||||
FROM
|
||||
`user`
|
||||
WHERE
|
||||
`userID` = :userID
|
||||
");
|
||||
|
||||
$stmt->bindParam(":userID", $userID);
|
||||
$stmt->execute();
|
||||
$user = $stmt->fetch();
|
||||
|
||||
$email = $user["email"];
|
||||
$fname = $user["fname"];
|
||||
$hash = password_hash($email, PASSWORD_DEFAULT);
|
||||
$confirmLink = "https://myhyvesbookplus.nl/emailconfirm.php?u=$userID&h=$hash";
|
||||
|
||||
$subject = "Bevestig uw emailadres";
|
||||
$body = "Hallo $fname,\r\n\r\nKlik op de onderstaande link om uw emailadres te bevestigen.\r\n\r\n$confirmLink\r\n\r\nGroeten MyHyvesbook+";
|
||||
$header = "From: MyHyvesbook+ <noreply@myhyvesbookplus.nl>";
|
||||
mail($email, $subject, $body, $header);
|
||||
}
|
||||
@@ -1,13 +1,16 @@
|
||||
<?php
|
||||
|
||||
require("connect.php");
|
||||
|
||||
function selectAllFriends($userID) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`userID`,
|
||||
`username`,
|
||||
LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `name`,
|
||||
IFNULL(
|
||||
`profilepicture`,
|
||||
'../img/notbad.jpg'
|
||||
'../img/avatar-standard.png'
|
||||
) AS profilepicture,
|
||||
`onlinestatus`,
|
||||
`role`
|
||||
@@ -36,9 +39,25 @@ function selectAllFriendRequests() {
|
||||
SELECT
|
||||
`userID`,
|
||||
`username`,
|
||||
CASE `status` IS NULL
|
||||
WHEN TRUE THEN 0
|
||||
WHEN FALSE THEN
|
||||
CASE `status` = 'confirmed'
|
||||
WHEN TRUE THEN
|
||||
1
|
||||
WHEN FALSE THEN
|
||||
CASE `user1ID` = :userID
|
||||
WHEN TRUE THEN
|
||||
2
|
||||
WHEN FALSE THEN
|
||||
3
|
||||
END
|
||||
END
|
||||
END AS `friend_state`,
|
||||
LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `name`,
|
||||
IFNULL(
|
||||
`profilepicture`,
|
||||
'../img/notbad.jpg'
|
||||
'../img/avatar-standard.png'
|
||||
) AS profilepicture,
|
||||
`onlinestatus`,
|
||||
`role`
|
||||
@@ -61,3 +80,105 @@ function selectAllFriendRequests() {
|
||||
|
||||
return json_encode($stmt->fetchAll());
|
||||
}
|
||||
|
||||
function getFriendshipStatus($userID) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
CASE `status` IS NULL
|
||||
WHEN TRUE THEN 0
|
||||
WHEN FALSE THEN
|
||||
CASE `status` = 'confirmed'
|
||||
WHEN TRUE THEN
|
||||
1
|
||||
WHEN FALSE THEN
|
||||
CASE `user1ID` = :me AND `user2ID` = :other
|
||||
WHEN TRUE THEN
|
||||
2
|
||||
WHEN FALSE THEN
|
||||
3
|
||||
END
|
||||
END
|
||||
END AS `friend_state`
|
||||
FROM
|
||||
`friendship`
|
||||
WHERE
|
||||
`user1ID` = :other AND `user2ID` = :me OR
|
||||
`user1ID` = :me AND `user2ID` = :other
|
||||
");
|
||||
|
||||
$stmt->bindParam(':me', $_SESSION["userID"], PDO::PARAM_INT);
|
||||
$stmt->bindParam(':other', $userID, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
return $stmt->fetch()["friend_state"];
|
||||
}
|
||||
|
||||
function requestFriendship($userID) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
INSERT INTO `friendship` (user1ID, user2ID)
|
||||
VALUES (:user1, :user2)
|
||||
");
|
||||
|
||||
$stmt->bindParam(':user1', $_SESSION["userID"], PDO::PARAM_INT);
|
||||
$stmt->bindParam(':user2', $userID, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
function removeFriendship($userID) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
DELETE FROM `friendship`
|
||||
WHERE
|
||||
`user1ID` = :user1 AND
|
||||
`user2ID` = :user2 OR
|
||||
`user1ID` = :user2 AND
|
||||
`user2ID` = :user1
|
||||
");
|
||||
|
||||
$stmt->bindParam(':user1', $_SESSION["userID"], PDO::PARAM_INT);
|
||||
$stmt->bindParam(':user2', $userID, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
function acceptFriendship($userID) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
UPDATE `friendship`
|
||||
SET `status`='confirmed'
|
||||
WHERE
|
||||
`user1ID` = :user1 AND
|
||||
`user2ID` = :user2
|
||||
LIMIT 1
|
||||
");
|
||||
|
||||
$stmt->bindParam(':user1', $userID, PDO::PARAM_INT);
|
||||
$stmt->bindParam(':user2', $_SESSION["userID"], PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
function setLastVisited($friend) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
UPDATE
|
||||
`friendship`
|
||||
SET `friendship`.chatLastVisted1=(
|
||||
CASE `user1ID` = :sessionUser
|
||||
WHEN TRUE THEN NOW()
|
||||
WHEN FALSE THEN `chatLastVisted1`
|
||||
END
|
||||
),
|
||||
`friendship`.`chatLastVisted2`=(
|
||||
CASE `user2ID` = :sessionUser
|
||||
WHEN TRUE THEN NOW()
|
||||
WHEN FALSE THEN `chatLastVisted2`
|
||||
END
|
||||
)
|
||||
WHERE
|
||||
`user1ID` = :sessionUser AND
|
||||
`user2ID` = :friend OR
|
||||
`user2ID` = :sessionUser AND
|
||||
`user1ID` = :friend;
|
||||
");
|
||||
|
||||
$stmt->bindParam(':sessionUser', $_SESSION["userID"], PDO::PARAM_INT);
|
||||
$stmt->bindParam(':friend', $friend, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
|
||||
return $stmt;
|
||||
}
|
||||
@@ -6,7 +6,7 @@ function getHeaderInfo() {
|
||||
`lname`,
|
||||
IFNULL(
|
||||
`profilepicture`,
|
||||
'img/notbad.jpg'
|
||||
'img/avatar-standard.png'
|
||||
) AS profilepicture
|
||||
FROM
|
||||
`user`
|
||||
|
||||
@@ -4,7 +4,8 @@ function getUser() {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`password`,
|
||||
`userID`
|
||||
`userID`,
|
||||
`role`
|
||||
FROM
|
||||
`user`
|
||||
WHERE
|
||||
@@ -15,3 +16,46 @@ function getUser() {
|
||||
$stmt->execute();
|
||||
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 if ($role == "unconfirmed"){
|
||||
sendConfirmEmail(getUser()["userID"]);
|
||||
echo "<script>
|
||||
window.onload=emailNotConfirmed();
|
||||
</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);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
@@ -74,3 +74,39 @@ function getNewChatMessages($lastID, $destination) {
|
||||
|
||||
return json_encode($stmt->fetchAll());
|
||||
}
|
||||
|
||||
|
||||
function selectAllUnreadChat() {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
LEFT(CONCAT(`user`.`fname`, ' ', `user`.`lname`), 15) as `name`,
|
||||
`user`.`userID`,
|
||||
IFNULL(
|
||||
`profilepicture`,
|
||||
'../img/notbad.jpg'
|
||||
) AS profilepicture,
|
||||
LEFT(`private_message`.`content`, 15) as `content`
|
||||
FROM
|
||||
`private_message`,
|
||||
`friendship`,
|
||||
`user`
|
||||
WHERE
|
||||
(`friendship`.user2ID = `private_message`.`origin` AND
|
||||
`friendship`.user1ID = `private_message`.`destination` AND
|
||||
`friendship`.chatLastVisted1 < `private_message`.`creationdate` OR
|
||||
`friendship`.user1ID = `private_message`.`origin` AND
|
||||
`friendship`.user2ID = `private_message`.`destination` AND
|
||||
`friendship`.chatLastVisted2 < `private_message`.`creationdate`) AND
|
||||
`private_message`.`origin` = `user`.`userID` AND
|
||||
`private_message`.`destination` = :userID AND
|
||||
`user`.`role` != 'banned'
|
||||
|
||||
GROUP BY `user`.`userID`
|
||||
");
|
||||
|
||||
$stmt->bindParam(':userID', $_SESSION["userID"]);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
return json_encode($stmt->fetchAll());
|
||||
}
|
||||
@@ -1,35 +1,35 @@
|
||||
<?php
|
||||
include_once "../queries/emailconfirm.php";
|
||||
|
||||
class settingsMessage {
|
||||
private $class;
|
||||
private $message;
|
||||
|
||||
/**
|
||||
* settingsMessage constructor.
|
||||
* @param string $type Happy or angry
|
||||
* @param string $message The message to display
|
||||
*/
|
||||
public function __construct($type, $message) {
|
||||
$this->message = $message;
|
||||
switch ($type) {
|
||||
case "happy":
|
||||
$this->class = "settings-message-happy";
|
||||
break;
|
||||
case "angry":
|
||||
$this->class = "settings-message-angry";
|
||||
break;
|
||||
default:
|
||||
$this->class = "settings-message";
|
||||
break;
|
||||
abstract class AlertMessage extends Exception {
|
||||
public function __construct($message = "", $code = 0, Exception $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
abstract public function getClass();
|
||||
}
|
||||
|
||||
class HappyAlert extends AlertMessage {
|
||||
|
||||
public function __construct($message = "Gelukt!", $code = 0, Exception $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
public function getClass() {
|
||||
return $this->class;
|
||||
return "settings-message-happy";
|
||||
}
|
||||
}
|
||||
|
||||
class AngryAlert extends AlertMessage {
|
||||
public function __construct($message = "Er is iets fout gegaan.", $code = 0, Exception $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
public function getMessage() {
|
||||
return $this->message;
|
||||
public function getClass() {
|
||||
return "settings-message-angry";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,24 +94,19 @@ function updateSettings() {
|
||||
$stmt->bindValue(":bio", test_input($_POST["bio"]));
|
||||
$stmt->bindValue(":userID", $_SESSION["userID"]);
|
||||
$stmt->execute();
|
||||
|
||||
return new settingsMessage("happy", "Instellingen zijn opgeslagen.");
|
||||
throw new HappyAlert("Instellingen zijn opgeslagen.");
|
||||
}
|
||||
|
||||
function changePassword() {
|
||||
$user = getPasswordHash();
|
||||
if (password_verify($_POST["password-old"], $user["password"])) {
|
||||
if ($_POST["password-new"] == $_POST["password-confirm"] && (strlen($_POST["password-new"]) >= 8)) {
|
||||
if (doChangePassword()) {
|
||||
return new settingsMessage("happy", "Wachtwoord gewijzigd.");
|
||||
doChangePassword();
|
||||
} else {
|
||||
return new settingsMessage("angry", "Er is iets mis gegaan.");
|
||||
throw new AngryAlert("Wachtwoorden komen niet overeen.");
|
||||
}
|
||||
} else {
|
||||
return new settingsMessage("angry", "Wachtwoorden komen niet oveen.");
|
||||
}
|
||||
} else {
|
||||
return new settingsMessage("angry", "Oud wachtwoord niet correct.");
|
||||
throw new AngryAlert("Oud wachtwoord niet correct.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +124,12 @@ function doChangePassword() {
|
||||
$stmt->bindParam(":new_password", $hashed_password);
|
||||
$stmt->bindParam(":userID", $_SESSION["userID"]);
|
||||
$stmt->execute();
|
||||
return $stmt->rowCount();
|
||||
|
||||
if ($stmt->rowCount()) {
|
||||
throw new HappyAlert("Wachtwoord gewijzigd.");
|
||||
} else {
|
||||
throw new AngryAlert();
|
||||
}
|
||||
}
|
||||
|
||||
function changeEmail() {
|
||||
@@ -138,20 +138,13 @@ function changeEmail() {
|
||||
$email = strtolower($_POST["email"]);
|
||||
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
//check if email exists
|
||||
if (emailIsAvailableInDatabase($email)) {
|
||||
if (doChangeEmail($email)) {
|
||||
return new settingsMessage("happy", "Emailadres is veranderd.");
|
||||
emailIsAvailableInDatabase($email);
|
||||
doChangeEmail($email);
|
||||
} else {
|
||||
return new settingsMessage("angry", "Er is iets mis gegaan.");
|
||||
throw new AngryAlert("Geef een geldig emailadres");
|
||||
}
|
||||
} else {
|
||||
return new settingsMessage("angry", "Emailadres bestaat al.");
|
||||
}
|
||||
} else {
|
||||
return new settingsMessage("angry", "Geef een geldig emailadres.");
|
||||
}
|
||||
} else {
|
||||
return new settingsMessage("angry", "Emailadressen komen niet overeen.");
|
||||
throw new AngryAlert("Emailadressen komen niet overeen.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +160,9 @@ function emailIsAvailableInDatabase($email) {
|
||||
|
||||
$stmt->bindParam(":email", $email);
|
||||
$stmt->execute();
|
||||
return !$stmt->rowCount();
|
||||
if ($stmt->rowCount()) {
|
||||
throw new AngryAlert("Emailadres wordt al gebruikt.");
|
||||
}
|
||||
}
|
||||
|
||||
function doChangeEmail($email) {
|
||||
@@ -175,25 +170,46 @@ function doChangeEmail($email) {
|
||||
UPDATE
|
||||
`user`
|
||||
SET
|
||||
`email` = :email
|
||||
`email` = :email,
|
||||
`role` = 'unconfirmed'
|
||||
WHERE
|
||||
`userID` = :userID
|
||||
");
|
||||
$stmt->bindParam(":email", $email);
|
||||
$stmt->bindParam(":userID", $_SESSION["userID"]);
|
||||
$stmt->execute();
|
||||
return $stmt->rowCount();
|
||||
|
||||
if ($stmt->rowCount()) {
|
||||
sendConfirmEmail($_SESSION["userID"]);
|
||||
session_destroy();
|
||||
throw new HappyAlert("Emailadres is veranderd.");
|
||||
} else {
|
||||
throw new AngryAlert();
|
||||
}
|
||||
}
|
||||
|
||||
function updateProfilePicture() {
|
||||
function updateAvatar() {
|
||||
$profilePictureDir = "/var/www/html/public/";
|
||||
$relativePath = "uploads/profilepictures/" . $_SESSION["userID"] . "_" . basename($_FILES["pp"]["name"]);
|
||||
removeOldProfilePicture();
|
||||
move_uploaded_file($_FILES['pp']['tmp_name'], $profilePictureDir . $relativePath);
|
||||
setProfilePictureToDatabase("../" . $relativePath);
|
||||
$tmpImg = $_FILES["pp"]["tmp_name"];
|
||||
|
||||
checkAvatarSize($tmpImg);
|
||||
removeOldAvatar();
|
||||
if (getimagesize($tmpImg)["mime"] == "image/gif") {
|
||||
if ($_FILES["pp"]["size"] > 4000000) {
|
||||
throw new AngryAlert("Bestand is te groot, maximaal 4MB toegestaan.");
|
||||
}
|
||||
$relativePath = "uploads/profilepictures/" . $_SESSION["userID"] . "_avatar.gif";
|
||||
move_uploaded_file($tmpImg, $profilePictureDir . $relativePath);
|
||||
} else {
|
||||
$relativePath = "uploads/profilepictures/" . $_SESSION["userID"] . "_avatar.png";
|
||||
$scaledImg = scaleAvatar($tmpImg);
|
||||
imagepng($scaledImg, $profilePictureDir . $relativePath);
|
||||
}
|
||||
setAvatarToDatabase("../" . $relativePath);
|
||||
throw new HappyAlert("Profielfoto veranderd.");
|
||||
}
|
||||
|
||||
function removeOldProfilePicture() {
|
||||
function removeOldAvatar() {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`profilepicture`
|
||||
@@ -205,20 +221,39 @@ function removeOldProfilePicture() {
|
||||
$stmt->bindParam(":userID", $_SESSION["userID"]);
|
||||
$stmt->execute();
|
||||
$old_avatar = $stmt->fetch()["profilepicture"];
|
||||
if ($old_avatar != NULL) {
|
||||
unlink("/var/www/html/public/uploads/" . $old_avatar);
|
||||
}
|
||||
}
|
||||
|
||||
function setProfilePictureToDatabase($url) {
|
||||
function setAvatarToDatabase(string $url) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
UPDATE
|
||||
`user`
|
||||
SET
|
||||
`profilepicture` = :profilePicture
|
||||
`profilepicture` = :avatar
|
||||
WHERE
|
||||
`userID` = :userID
|
||||
");
|
||||
|
||||
$stmt->bindParam(":profilePicture", $url);
|
||||
$stmt->bindParam(":avatar", $url);
|
||||
$stmt->bindParam(":userID", $_SESSION["userID"]);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
function checkAvatarSize(string $img) {
|
||||
$minResolution = 200;
|
||||
$imgSize = getimagesize($img);
|
||||
if ($imgSize[0] < $minResolution or $imgSize[1] < $minResolution) {
|
||||
throw new AngryAlert("Afbeelding te klein, minimaal 200x200 pixels.");
|
||||
}
|
||||
}
|
||||
|
||||
function scaleAvatar(string $imgLink, int $newWidth = 600) {
|
||||
$img = imagecreatefromstring(file_get_contents($imgLink));
|
||||
if ($img) {
|
||||
return imagescale($img, $newWidth);
|
||||
} else {
|
||||
throw new AngryAlert("Afbeelding wordt niet ondersteund.");
|
||||
}
|
||||
}
|
||||
@@ -17,27 +17,64 @@ function getUserID($username) {
|
||||
return $stmt->fetch()["userID"];
|
||||
}
|
||||
|
||||
function selectUser($userID) {
|
||||
function getUsername($userID) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`username`,
|
||||
IFNULL(
|
||||
`profilepicture`,
|
||||
'../img/notbad.jpg'
|
||||
) AS profilepicture,
|
||||
`bio`,
|
||||
`role`,
|
||||
`onlinestatus`,
|
||||
`loggedin`,
|
||||
`fname`,
|
||||
`lname`
|
||||
`username`
|
||||
FROM
|
||||
`user`
|
||||
WHERE
|
||||
`userID` = :userID
|
||||
");
|
||||
|
||||
$stmt->bindParam(':userID', $userID, PDO::PARAM_INT);
|
||||
$stmt->bindParam(':userID', $userID, PDO::PARAM_STR);
|
||||
$stmt->execute();
|
||||
return $stmt->fetch()["username"];
|
||||
}
|
||||
|
||||
function selectUser($me, $other) {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
SELECT
|
||||
`username`,
|
||||
`birthdate`,
|
||||
`location`,
|
||||
IFNULL(
|
||||
`profilepicture`,
|
||||
'../img/avatar-standard.png'
|
||||
) AS profilepicture,
|
||||
`bio`,
|
||||
`user`.`creationdate`,
|
||||
`onlinestatus`,
|
||||
`fname`,
|
||||
`lname`,
|
||||
CASE `status` IS NULL
|
||||
WHEN TRUE THEN 0
|
||||
WHEN FALSE THEN
|
||||
CASE `status` = 'confirmed'
|
||||
WHEN TRUE THEN
|
||||
1
|
||||
WHEN FALSE THEN
|
||||
CASE `user1ID` = `userID` AND `user2ID` = :me
|
||||
WHEN TRUE THEN
|
||||
2
|
||||
WHEN FALSE THEN
|
||||
3
|
||||
END
|
||||
END
|
||||
END AS `friend_status`
|
||||
FROM
|
||||
`user`
|
||||
LEFT JOIN
|
||||
`friendship`
|
||||
ON
|
||||
`user1ID` = `userID` AND `user2ID` = :me OR
|
||||
`user1ID` = :me AND `user2ID` = `userID`
|
||||
WHERE
|
||||
`user`.`userID` = :other
|
||||
");
|
||||
|
||||
$stmt->bindParam(':me', $me, PDO::PARAM_INT);
|
||||
$stmt->bindParam(':other', $other, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
return $stmt->fetch();
|
||||
}
|
||||
@@ -71,7 +108,13 @@ function selectAllUserPosts($userID) {
|
||||
`postID`,
|
||||
`author`,
|
||||
`title`,
|
||||
`content`,
|
||||
CASE LENGTH(`content`) >= 150
|
||||
WHEN TRUE THEN
|
||||
CONCAT(LEFT(`content`, 150), '...')
|
||||
WHEN FALSE THEN
|
||||
`content`
|
||||
END
|
||||
AS `content`,
|
||||
`creationdate`
|
||||
FROM
|
||||
`post`
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="content">
|
||||
<div class="chat">
|
||||
<nav class="nav-list chat-left left platform chat-recent">
|
||||
<nav class="nav-list platform" id="chat-recent-panel">
|
||||
<h5>Chats</h5>
|
||||
<ul>
|
||||
<?php
|
||||
@@ -16,8 +16,9 @@
|
||||
|
||||
// Set default values of a friend.
|
||||
$username = $friend["username"];
|
||||
$name = $friend["name"];
|
||||
$userID = $friend["userID"];
|
||||
$pf = "img/notbad.jpg";
|
||||
$pf = "img/avatar-standard.png";
|
||||
|
||||
// Change values if needed.
|
||||
if (!empty($friend["profilepicture"]))
|
||||
@@ -28,17 +29,25 @@
|
||||
<li class='friend-item' id='friend-item-$userID' onclick='switchUser(\"$userID\")'>
|
||||
<div class='friend'>
|
||||
<img alt='PF' class='profile-picture' src='$pf'/>
|
||||
$username
|
||||
<div class='friend-name'>
|
||||
$name<br/>
|
||||
<span style='color: #666'>$username</span>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
";
|
||||
}
|
||||
|
||||
$chatID = $_GET["chatID"];
|
||||
if (isset($chatID) && $chatID != "") {
|
||||
echo "<script>$(document).ready(function(){switchUser('$chatID')});</script>";
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
</nav>
|
||||
<div class="chat-right">
|
||||
<div id="chat-history" class="chat-history platform">
|
||||
</div>
|
||||
<div>
|
||||
<form id="lastIDForm">
|
||||
<input type="hidden"
|
||||
id="lastID"
|
||||
|
||||
3
website/views/loadFriends.php
Normal file
3
website/views/loadFriends.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
echo json_encode(selectAllFriends($_SESSION["userID"])->fetchAll());
|
||||
@@ -7,6 +7,7 @@
|
||||
<link rel="stylesheet"
|
||||
type="text/css"
|
||||
href="styles/index.css">
|
||||
<script src="/js/jqeury.js"></script>
|
||||
<script src="/js/registerAndLogin.js"></script>
|
||||
<script src="js/jqeury.js"></script>
|
||||
<script src="js/registerAndLogin.js"></script>
|
||||
<script src='https://www.google.com/recaptcha/api.js'></script>
|
||||
</head>
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
foreach ($friends as $i => $friend) {
|
||||
$username = $friend["username"];
|
||||
$name = $friend["name"];
|
||||
$extraItem = "";
|
||||
$pf = $friend["profilepicture"];
|
||||
|
||||
@@ -49,7 +50,10 @@
|
||||
value='$username'>
|
||||
<div class='friend'>
|
||||
<img alt='PF' class='profile-picture' src='$pf'/>
|
||||
$username
|
||||
<div class='friend-name'>
|
||||
$name<br/>
|
||||
<span style='color: #666'>$username</span>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
@@ -5,12 +5,20 @@
|
||||
<a href="profile.php"><i class="fa fa-user" data-title="Profiel"></i></a>
|
||||
<a href="logout.php"><i class="fa fa-sign-out" data-title="Uitloggen"></i></a>
|
||||
</section>
|
||||
<section id="notifocationCenter">
|
||||
<section>
|
||||
<h4>
|
||||
Vriendchapsverzoeken
|
||||
</h4>
|
||||
<ul class="nav-list" id="friendrequestslist">
|
||||
|
||||
</ul>
|
||||
</section>
|
||||
<section>
|
||||
<h4>
|
||||
Nieuwe berichten
|
||||
</h4>
|
||||
<ul class="nav-list" id="unreadChatlist">
|
||||
|
||||
</ul>
|
||||
</section>
|
||||
</nav>
|
||||
@@ -1,11 +1,24 @@
|
||||
<div class="content">
|
||||
<div class="profile-box platform">
|
||||
<img class="left profile-picture" src="<?php echo $user["profilepicture"] ?>">
|
||||
<div class="profile-button">
|
||||
<p><img src="/img/add-friend.png"> Als vriend toevoegen</p>
|
||||
</div>
|
||||
<h1 class="profile-username"><?=$user["username"]?></h1>
|
||||
<h5 class="profile-username"><?= $user["fname"]?> <?=$user["lname"]?></h5>
|
||||
|
||||
<form action="API/edit_friendship.php" method="post">
|
||||
<input type="hidden" name="userID" value="<?= $userID ?>">
|
||||
<?php
|
||||
if($userID != $_SESSION["userID"] AND $user["friend_status"] == 0) {
|
||||
echo "<input class='profile-button' type='submit' name='request' value='Stuur vriendschapsverzoek!'>";
|
||||
} else if($user["friend_status"] == 1) {
|
||||
echo "<input class='profile-button' type='submit' name='delete' value='Verwijder vriend!'>";
|
||||
} else if($user["friend_status"] == 2) {
|
||||
echo "<input class='profile-button' type='submit' name='accept' value='Accepteer vriendschapsverzoek!'>";
|
||||
echo "<input class='profile-button' type='submit' name='delete' value='Weiger vriendschapsverzoek!'>";
|
||||
} else if($user["friend_status"] == 3) {
|
||||
echo "<input class='profile-button' type='submit' name='delete' value='Trek vriendschapsverzoek in!'>";
|
||||
}
|
||||
?>
|
||||
</form>
|
||||
<h1 class="profile-username"><?= $user["fname"]?> <?=$user["lname"]?></h1>
|
||||
<h5 class="profile-username"><?=$user["username"]?></h5>
|
||||
<p><?=$user["bio"]?></p>
|
||||
</div>
|
||||
|
||||
@@ -14,7 +27,7 @@
|
||||
<p>
|
||||
<?php
|
||||
while($friend = $profile_friends->fetch()) {
|
||||
echo "<a href='/profile/${friend["username"]}/' data-title='${friend["username"]}'><img class='profile-picture' src='${friend["profilepicture"]}' alt='${friend["username"]}'s profielfoto></a>";
|
||||
echo "<a href='profile.php?username=${friend["username"]}' data-title='${friend["username"]}'><img class='profile-picture' src='${friend["profilepicture"]}' alt='${friend["username"]}'s profielfoto></a>";
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +60,7 @@
|
||||
<div class="post platform">
|
||||
<form>
|
||||
<input type="text" class="newpost" placeholder="Titel">
|
||||
<textarea class="newpost">Schrijf een berichtje...</textarea>
|
||||
<textarea class="newpost" placeholder="Schrijf een berichtje..."></textarea>
|
||||
<input type="submit" value="Plaats!">
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -41,11 +41,12 @@
|
||||
<!-- Register birthday -->
|
||||
<div class="login_containerregister">
|
||||
<label><b>Geboortedatum</b></label>
|
||||
<input type="date"
|
||||
<input type="text"
|
||||
name="bday"
|
||||
value="<?php echo $bday ?>"
|
||||
id="bday"
|
||||
placeholder="01/01/1900"
|
||||
placeholder="1996/01/01"
|
||||
data-fv-date-max=""
|
||||
>
|
||||
*<span class="error"> <?php echo $bdayErr;?></span>
|
||||
</div>
|
||||
@@ -95,7 +96,7 @@
|
||||
|
||||
<!-- Register location -->
|
||||
<div class="login_containerregister">
|
||||
<label><b>Woonplaats</b></label>
|
||||
<label><b>Locatie</b></label>
|
||||
<input type="text"
|
||||
placeholder="Voer uw woonplaats in"
|
||||
name="location"
|
||||
@@ -117,18 +118,23 @@
|
||||
*<span class="error"> <?php echo $emailErr;?></span>
|
||||
</div>
|
||||
|
||||
<!-- Button for registering -->
|
||||
<div class="login_containerregister">
|
||||
<div class="g-recaptcha" data-sitekey="6Lc72xIUAAAAADumlWetgENm7NGd9Npyo0c_tYYQ"></div>
|
||||
<span class="error"> <?php echo $captchaErr;?></span>
|
||||
</div>
|
||||
|
||||
<!-- Button for registering -->
|
||||
<div class="login_containerlogin">
|
||||
<!-- Button for going back to login screen -->
|
||||
<a href="https://myhyvesbookplus.nl/login.php" class="left-arrow">Login</a>
|
||||
|
||||
<button type="submit"
|
||||
value="Registreer uw account"
|
||||
name="Submit"
|
||||
id="frm1_submit">
|
||||
Registreer
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
<div class="login_containerlogin">
|
||||
<!-- Button for going back to login screen -->
|
||||
<a href="https://myhyvesbookplus.nl/login.php" class="left-arrow">Login</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -6,9 +6,9 @@ $settings = getSettings();
|
||||
<div class="settings">
|
||||
<?php
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
echo "<div class='platform settings-message ". $result->getClass()."'>".
|
||||
$result->getMessage().
|
||||
"</div>";
|
||||
echo "<div class='platform settings-message $alertClass '>
|
||||
$alertMessage
|
||||
</div>";
|
||||
}
|
||||
?>
|
||||
<form class="settings-profile platform" method="post">
|
||||
@@ -81,7 +81,8 @@ $settings = getSettings();
|
||||
<label>Selecteer foto</label>
|
||||
<input type="file"
|
||||
name="pp"
|
||||
accept="image/jpeg,image/gif,image/png"
|
||||
accept="image/*"
|
||||
size="4000000"
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
|
||||
Reference in New Issue
Block a user