Added showEmail and showBday to the settings page #145
@@ -1,6 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
include_once "../queries/emailconfirm.php";
|
include_once "../queries/emailconfirm.php";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class AlertMessage
|
||||||
|
* abstract class for alertMessages used in
|
||||||
|
*/
|
||||||
abstract class AlertMessage extends Exception {
|
abstract class AlertMessage extends Exception {
|
||||||
public function __construct($message = "", $code = 0, Exception $previous = null)
|
public function __construct($message = "", $code = 0, Exception $previous = null)
|
||||||
{
|
{
|
||||||
@@ -10,6 +14,10 @@ abstract class AlertMessage extends Exception {
|
|||||||
abstract public function getClass();
|
abstract public function getClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class HappyAlert
|
||||||
|
* class for a happy alert as an exception.
|
||||||
|
*/
|
||||||
class HappyAlert extends AlertMessage {
|
class HappyAlert extends AlertMessage {
|
||||||
|
|
||||||
public function __construct($message = "Gelukt!", $code = 0, Exception $previous = null)
|
public function __construct($message = "Gelukt!", $code = 0, Exception $previous = null)
|
||||||
@@ -22,6 +30,10 @@ class HappyAlert extends AlertMessage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class AngryAlert
|
||||||
|
* class for an angry alert as as exception.
|
||||||
|
*/
|
||||||
class AngryAlert extends AlertMessage {
|
class AngryAlert extends AlertMessage {
|
||||||
public function __construct($message = "Er is iets fout gegaan.", $code = 0, Exception $previous = null)
|
public function __construct($message = "Er is iets fout gegaan.", $code = 0, Exception $previous = null)
|
||||||
{
|
{
|
||||||
@@ -46,7 +58,9 @@ function getSettings() {
|
|||||||
`location`,
|
`location`,
|
||||||
`birthdate`,
|
`birthdate`,
|
||||||
`bio`,
|
`bio`,
|
||||||
`profilepicture`
|
`profilepicture`,
|
||||||
|
`showBday`,
|
||||||
|
`showEmail`
|
||||||
FROM
|
FROM
|
||||||
`user`
|
`user`
|
||||||
WHERE
|
WHERE
|
||||||
@@ -58,6 +72,10 @@ function getSettings() {
|
|||||||
return $stmt->fetch();
|
return $stmt->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the passwordHas form the database
|
||||||
|
* @return mixed passwordhash
|
||||||
|
*/
|
||||||
function getPasswordHash() {
|
function getPasswordHash() {
|
||||||
$stmt = $GLOBALS["db"]->prepare("
|
$stmt = $GLOBALS["db"]->prepare("
|
||||||
SELECT
|
SELECT
|
||||||
@@ -73,6 +91,10 @@ function getPasswordHash() {
|
|||||||
return $stmt->fetch();
|
return $stmt->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the setting from post.
|
||||||
|
* @throws HappyAlert
|
||||||
|
*/
|
||||||
function updateSettings() {
|
function updateSettings() {
|
||||||
$stmt = $GLOBALS["db"]->prepare("
|
$stmt = $GLOBALS["db"]->prepare("
|
||||||
UPDATE
|
UPDATE
|
||||||
@@ -82,7 +104,9 @@ function updateSettings() {
|
|||||||
`lname` = :lname,
|
`lname` = :lname,
|
||||||
`location` = :location,
|
`location` = :location,
|
||||||
`birthdate` = :bday,
|
`birthdate` = :bday,
|
||||||
`bio` = :bio
|
`bio` = :bio,
|
||||||
|
`showEmail` = :showEmail,
|
||||||
|
`showBday` = :showBday
|
||||||
WHERE
|
WHERE
|
||||||
`userID` = :userID
|
`userID` = :userID
|
||||||
");
|
");
|
||||||
@@ -92,15 +116,22 @@ function updateSettings() {
|
|||||||
$stmt->bindValue(":location", test_input($_POST["location"]));
|
$stmt->bindValue(":location", test_input($_POST["location"]));
|
||||||
$stmt->bindValue(":bday", test_input($_POST["bday"]));
|
$stmt->bindValue(":bday", test_input($_POST["bday"]));
|
||||||
$stmt->bindValue(":bio", test_input($_POST["bio"]));
|
$stmt->bindValue(":bio", test_input($_POST["bio"]));
|
||||||
|
$stmt->bindValue(":showEmail", test_input($_POST["showEmail"]));
|
||||||
|
$stmt->bindValue(":showBday", test_input($_POST["showBday"]));
|
||||||
|
|
||||||
$stmt->bindValue(":userID", $_SESSION["userID"]);
|
$stmt->bindValue(":userID", $_SESSION["userID"]);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
throw new HappyAlert("Instellingen zijn opgeslagen.");
|
throw new HappyAlert("Instellingen zijn opgeslagen.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change
|
||||||
|
* @throws AngryAlert
|
||||||
|
*/
|
||||||
function changePassword() {
|
function changePassword() {
|
||||||
$user = getPasswordHash();
|
$user = getPasswordHash();
|
||||||
if (password_verify($_POST["password-old"], $user["password"])) {
|
if (password_verify($_POST["password-old"], test_input($user["password"]))) {
|
||||||
if ($_POST["password-new"] == $_POST["password-confirm"] && (strlen($_POST["password-new"]) >= 8)) {
|
if (test_input($_POST["password-new"]) == test_input($_POST["password-confirm"]) && (strlen(test_input($_POST["password-new"])) >= 8)) {
|
||||||
doChangePassword();
|
doChangePassword();
|
||||||
} else {
|
} else {
|
||||||
throw new AngryAlert("Wachtwoorden komen niet overeen.");
|
throw new AngryAlert("Wachtwoorden komen niet overeen.");
|
||||||
@@ -110,6 +141,10 @@ function changePassword() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws AngryAlert
|
||||||
|
* @throws HappyAlert
|
||||||
|
*/
|
||||||
function doChangePassword() {
|
function doChangePassword() {
|
||||||
$stmt = $GLOBALS["db"]->prepare("
|
$stmt = $GLOBALS["db"]->prepare("
|
||||||
UPDATE
|
UPDATE
|
||||||
@@ -134,8 +169,8 @@ function doChangePassword() {
|
|||||||
|
|
||||||
function changeEmail() {
|
function changeEmail() {
|
||||||
|
|
||||||
if ($_POST["email"] == $_POST["email-confirm"]) {
|
if (test_input($_POST["email"]) == test_input($_POST["email-confirm"])) {
|
||||||
$email = strtolower($_POST["email"]);
|
$email = strtolower(test_input($_POST["email"]));
|
||||||
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
//check if email exists
|
//check if email exists
|
||||||
emailIsAvailableInDatabase($email);
|
emailIsAvailableInDatabase($email);
|
||||||
@@ -193,7 +228,6 @@ function updateAvatar() {
|
|||||||
$tmpImg = $_FILES["pp"]["tmp_name"];
|
$tmpImg = $_FILES["pp"]["tmp_name"];
|
||||||
|
|
||||||
checkAvatarSize($tmpImg);
|
checkAvatarSize($tmpImg);
|
||||||
removeOldAvatar();
|
|
||||||
if (getimagesize($tmpImg)["mime"] == "image/gif") {
|
if (getimagesize($tmpImg)["mime"] == "image/gif") {
|
||||||
if ($_FILES["pp"]["size"] > 4000000) {
|
if ($_FILES["pp"]["size"] > 4000000) {
|
||||||
throw new AngryAlert("Bestand is te groot, maximaal 4MB toegestaan.");
|
throw new AngryAlert("Bestand is te groot, maximaal 4MB toegestaan.");
|
||||||
@@ -205,6 +239,7 @@ function updateAvatar() {
|
|||||||
$scaledImg = scaleAvatar($tmpImg);
|
$scaledImg = scaleAvatar($tmpImg);
|
||||||
imagepng($scaledImg, $profilePictureDir . $relativePath);
|
imagepng($scaledImg, $profilePictureDir . $relativePath);
|
||||||
}
|
}
|
||||||
|
removeOldAvatar();
|
||||||
setAvatarToDatabase("../" . $relativePath);
|
setAvatarToDatabase("../" . $relativePath);
|
||||||
throw new HappyAlert("Profielfoto veranderd.");
|
throw new HappyAlert("Profielfoto veranderd.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,32 @@ $settings = getSettings();
|
|||||||
value="<?= $settings["birthdate"]?>"
|
value="<?= $settings["birthdate"]?>"
|
||||||
>
|
>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<label for="showBday">Toon leeftijd</label>
|
||||||
|
<input type="radio"
|
||||||
|
name="showBday"
|
||||||
|
value="1"
|
||||||
|
<?php echo ($settings["showBday"] ? "checked" : "")?>
|
||||||
|
> Ja
|
||||||
|
<input type="radio"
|
||||||
|
name="showBday"
|
||||||
|
value="0"
|
||||||
|
<?php echo ($settings["showBday"] ? "" : "checked")?>
|
||||||
|
> Nee
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<label for="showEmail">Toon Email</label>
|
||||||
|
<input type="radio"
|
||||||
|
name="showEmail"
|
||||||
|
value="1"
|
||||||
|
<?php echo ($settings["showEmail"] ? "checked" : "")?>
|
||||||
|
> Ja
|
||||||
|
<input type="radio"
|
||||||
|
name="showEmail"
|
||||||
|
value="0"
|
||||||
|
<?php echo ($settings["showEmail"] ? "" : "checked")?>
|
||||||
|
> Nee
|
||||||
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<label for="bio">Bio</label>
|
<label for="bio">Bio</label>
|
||||||
<textarea name="bio"
|
<textarea name="bio"
|
||||||
|
|||||||
Reference in New Issue
Block a user