Marijn settings #60
2
.gitignore
vendored
2
.gitignore
vendored
@@ -117,7 +117,7 @@ Temporary Items
|
||||
# *.pdf
|
||||
|
||||
## 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):
|
||||
*.bbl
|
||||
|
||||
@@ -13,22 +13,26 @@
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
/*
|
||||
* This view adds the main layout over the screen.
|
||||
* Header and menu.
|
||||
*/
|
||||
|
||||
include("../views/main.php");
|
||||
|
||||
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");
|
||||
|
||||
/* This adds the footer. */
|
||||
include("../views/footer.php");
|
||||
|
||||
?>
|
||||
|
||||
@@ -5,6 +5,17 @@
|
||||
.settings-password {
|
||||
margin-right: 15px;
|
||||
}
|
||||
.settings-message {
|
||||
color: white;
|
||||
}
|
||||
.settings-message-angry {
|
||||
background-color: firebrick;
|
||||
}
|
||||
|
||||
.settings-message-happy {
|
||||
background-color: forestgreen;
|
||||
|
||||
}
|
||||
|
||||
|
||||
.settings li {
|
||||
|
||||
@@ -8,6 +8,4 @@ else {
|
||||
$GLOBALS["db"] = new PDO("mysql:host=$dbconf->mysql_host;dbname=$dbconf->mysql_database;charset=utf8",
|
||||
"$dbconf->mysql_username", "$dbconf->mysql_password")
|
||||
or die('Error connecting to mysql server');
|
||||
}
|
||||
|
||||
?>
|
||||
}
|
||||
@@ -21,6 +21,21 @@ function getSettings() {
|
||||
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() {
|
||||
$stmt = $GLOBALS["db"]->prepare("
|
||||
UPDATE
|
||||
@@ -43,4 +58,52 @@ function updateSettings() {
|
||||
$stmt->bindParam(":userID", $_SESSION["userID"]);
|
||||
|
||||
$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="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">
|
||||
<h5>Profiel Instellingen</h5>
|
||||
<ul>
|
||||
@@ -54,9 +61,10 @@ $settings = getSettings();
|
||||
</li>
|
||||
<li>
|
||||
<label></label>
|
||||
<input type="submit"
|
||||
value="Opslaan"
|
||||
>
|
||||
<button type="submit"
|
||||
value="profile"
|
||||
name="form"
|
||||
>Opslaan</button>
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
@@ -108,9 +116,10 @@ $settings = getSettings();
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<input type="submit"
|
||||
value="Verander wachtwoord"
|
||||
>
|
||||
<button type="submit"
|
||||
name="form"
|
||||
value="password"
|
||||
>Verander wachtwoord</button>
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
@@ -143,9 +152,10 @@ $settings = getSettings();
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<input type="submit"
|
||||
value="Verander Email"
|
||||
>
|
||||
<button type="submit"
|
||||
name="form"
|
||||
value="email"
|
||||
>Verander Email</button>
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user