Merge branch 'marijn-settings' into 'master'
Marijn settings See merge request !56
This commit was merged in pull request #60.
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -117,7 +117,7 @@ Temporary Items
|
|||||||
# *.pdf
|
# *.pdf
|
||||||
|
|
||||||
## Generated if empty string is given at "Please type another file name for output:"
|
## Generated if empty string is given at "Please type another file name for output:"
|
||||||
projectplan.pdf
|
projectplan/projectplan.pdf
|
||||||
|
|
||||||
## Bibliography auxiliary files (bibtex/biblatex/biber):
|
## Bibliography auxiliary files (bibtex/biblatex/biber):
|
||||||
*.bbl
|
*.bbl
|
||||||
|
|||||||
@@ -13,22 +13,26 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<?php
|
<?php
|
||||||
/*
|
|
||||||
* This view adds the main layout over the screen.
|
|
||||||
* Header and menu.
|
|
||||||
*/
|
|
||||||
|
|
||||||
include("../views/main.php");
|
include("../views/main.php");
|
||||||
|
|
||||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
updateSettings();
|
switch ($_POST["form"]) {
|
||||||
}?>
|
case "profile":
|
||||||
|
$result = updateSettings();
|
||||||
|
break;
|
||||||
|
case "password":
|
||||||
|
$result = updatePassword();
|
||||||
|
break;
|
||||||
|
case "email":
|
||||||
|
break;
|
||||||
|
case "picture":
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
<?php
|
|
||||||
/* Add your view files here. */
|
|
||||||
include("../views/settings-view.php");
|
include("../views/settings-view.php");
|
||||||
|
|
||||||
/* This adds the footer. */
|
|
||||||
include("../views/footer.php");
|
include("../views/footer.php");
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -5,6 +5,17 @@
|
|||||||
.settings-password {
|
.settings-password {
|
||||||
margin-right: 15px;
|
margin-right: 15px;
|
||||||
}
|
}
|
||||||
|
.settings-message {
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
.settings-message-angry {
|
||||||
|
background-color: firebrick;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-message-happy {
|
||||||
|
background-color: forestgreen;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.settings li {
|
.settings li {
|
||||||
|
|||||||
@@ -8,6 +8,4 @@ else {
|
|||||||
$GLOBALS["db"] = new PDO("mysql:host=$dbconf->mysql_host;dbname=$dbconf->mysql_database;charset=utf8",
|
$GLOBALS["db"] = new PDO("mysql:host=$dbconf->mysql_host;dbname=$dbconf->mysql_database;charset=utf8",
|
||||||
"$dbconf->mysql_username", "$dbconf->mysql_password")
|
"$dbconf->mysql_username", "$dbconf->mysql_password")
|
||||||
or die('Error connecting to mysql server');
|
or die('Error connecting to mysql server');
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -21,6 +21,21 @@ function getSettings() {
|
|||||||
return $stmt->fetch();
|
return $stmt->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getPasswordHash() {
|
||||||
|
$stmt = $GLOBALS["db"]->prepare("
|
||||||
|
SELECT
|
||||||
|
`password`,
|
||||||
|
`username`
|
||||||
|
FROM
|
||||||
|
`user`
|
||||||
|
WHERE
|
||||||
|
`userID` = :userID
|
||||||
|
");
|
||||||
|
$stmt->bindParam(":userID", $_SESSION["userID"]);
|
||||||
|
$stmt->execute();
|
||||||
|
return $stmt->fetch();
|
||||||
|
}
|
||||||
|
|
||||||
function updateSettings() {
|
function updateSettings() {
|
||||||
$stmt = $GLOBALS["db"]->prepare("
|
$stmt = $GLOBALS["db"]->prepare("
|
||||||
UPDATE
|
UPDATE
|
||||||
@@ -43,4 +58,52 @@ function updateSettings() {
|
|||||||
$stmt->bindParam(":userID", $_SESSION["userID"]);
|
$stmt->bindParam(":userID", $_SESSION["userID"]);
|
||||||
|
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
|
||||||
|
return array (
|
||||||
|
"type" => "settings-message-happy",
|
||||||
|
"message" => "Instellingen zijn opgeslagen."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updatePassword() {
|
||||||
|
$user = getPasswordHash();
|
||||||
|
if (password_verify($_POST["password-old"].strtolower($user["username"]), $user["password"])) {
|
||||||
|
if ($_POST["password-new"] == $_POST["password-confirm"] && (strlen($_POST["password-new"]) >= 8)) {
|
||||||
|
if (changePassword($user)) {
|
||||||
|
return array ("type" => "settings-message-happy",
|
||||||
|
"message" => "Wachtwoord gewijzigd.");
|
||||||
|
} else {
|
||||||
|
return array (
|
||||||
|
"type" => "settings-message-angry",
|
||||||
|
"message" => "Er is iets mis gegaan.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return array (
|
||||||
|
"type" => "settings-message-angry",
|
||||||
|
"message" => "Wachtwoorden komen niet oveeen."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return array(
|
||||||
|
"type" => "settings-message-angry",
|
||||||
|
"message" => "Oud wachtwoord niet correct."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function changePassword($user) {
|
||||||
|
$stmt =$GLOBALS["db"]->prepare("
|
||||||
|
UPDATE
|
||||||
|
`user`
|
||||||
|
SET
|
||||||
|
`password` = :new_password
|
||||||
|
WHERE
|
||||||
|
`userID` = :userID
|
||||||
|
");
|
||||||
|
|
||||||
|
$hashed_password = password_hash($_POST["password-new"].strtolower($user["username"]), PASSWORD_DEFAULT);
|
||||||
|
$stmt->bindParam(":new_password", $hashed_password);
|
||||||
|
$stmt->bindParam(":userID", $_SESSION["userID"]);
|
||||||
|
$stmt->execute();
|
||||||
|
return $stmt->rowCount();
|
||||||
|
}
|
||||||
@@ -4,6 +4,13 @@ $settings = getSettings();
|
|||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="settings">
|
<div class="settings">
|
||||||
|
<?php
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
echo "<div class='platform settings-message ${result["type"]}'>
|
||||||
|
${result["message"]}
|
||||||
|
</div>";
|
||||||
|
}
|
||||||
|
?>
|
||||||
<form class="settings-profile platform" method="post">
|
<form class="settings-profile platform" method="post">
|
||||||
<h5>Profiel Instellingen</h5>
|
<h5>Profiel Instellingen</h5>
|
||||||
<ul>
|
<ul>
|
||||||
@@ -54,9 +61,10 @@ $settings = getSettings();
|
|||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<label></label>
|
<label></label>
|
||||||
<input type="submit"
|
<button type="submit"
|
||||||
value="Opslaan"
|
value="profile"
|
||||||
>
|
name="form"
|
||||||
|
>Opslaan</button>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</form>
|
</form>
|
||||||
@@ -108,9 +116,10 @@ $settings = getSettings();
|
|||||||
>
|
>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<input type="submit"
|
<button type="submit"
|
||||||
value="Verander wachtwoord"
|
name="form"
|
||||||
>
|
value="password"
|
||||||
|
>Verander wachtwoord</button>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</form>
|
</form>
|
||||||
@@ -143,9 +152,10 @@ $settings = getSettings();
|
|||||||
>
|
>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<input type="submit"
|
<button type="submit"
|
||||||
value="Verander Email"
|
name="form"
|
||||||
>
|
value="email"
|
||||||
|
>Verander Email</button>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user