Marijn settings #60
@@ -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":
|
||||||
|
updateSettings();
|
||||||
|
break;
|
||||||
|
case "password":
|
||||||
|
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");
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -9,5 +9,3 @@ else {
|
|||||||
"$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,20 @@ function getSettings() {
|
|||||||
return $stmt->fetch();
|
return $stmt->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getPasswordHash() {
|
||||||
|
$stmt = $GLOBALS["db"]->prepare("
|
||||||
|
SELECT
|
||||||
|
`password`
|
||||||
|
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
|
||||||
@@ -44,3 +58,29 @@ function updateSettings() {
|
|||||||
|
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updatePassword() {
|
||||||
|
if (password_verify($_POST["password-old"], getPasswordHash()["password"])) {
|
||||||
|
if ($_POST["password-new"] == $_POST["password-confirm"]) {
|
||||||
|
changePassword();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print("Did not match");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function changePassword() {
|
||||||
|
$stmt =$GLOBALS["db"]->prepare("
|
||||||
|
UPDATE
|
||||||
|
`user`
|
||||||
|
SET
|
||||||
|
`password` = :new_password
|
||||||
|
WHERE
|
||||||
|
`userID` = :userID
|
||||||
|
");
|
||||||
|
|
||||||
|
$hashed_password = password_hash($_POST["password-new"], PASSWORD_DEFAULT);
|
||||||
|
$stmt->bindParam(":new_password", $hashed_password);
|
||||||
|
$stmt->bindParam(":userID", $_SESSION["userID"]);
|
||||||
|
$stmt->execute();
|
||||||
|
}
|
||||||
@@ -54,9 +54,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 +109,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 +145,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