Merge branch 'master' into hendrik-testing

This commit is contained in:
Hendrik
2017-01-27 10:48:18 +01:00
15 changed files with 564 additions and 138 deletions

View File

@@ -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)

View File

@@ -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);

View File

@@ -1,91 +1,105 @@
<?php
function getOldChatMessages($user2ID) {
require_once ("friendship.php");
$user1ID = $_SESSION["userID"];
if (getFriendshipStatus($user2ID) == 1) {
$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 = $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`

View File

@@ -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";
}
}
?>

View File

@@ -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`,