Hendrik testing #64

Merged
11342374 merged 35 commits from hendrik-testing into master 2017-01-18 16:08:50 +01:00
4 changed files with 66 additions and 21 deletions
Showing only changes of commit dde463df6c - Show all commits

View File

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

View File

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

View File

@@ -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
@@ -42,5 +56,31 @@ function updateSettings() {
$stmt->bindParam(":bio", $_POST["bio"]); $stmt->bindParam(":bio", $_POST["bio"]);
$stmt->bindParam(":userID", $_SESSION["userID"]); $stmt->bindParam(":userID", $_SESSION["userID"]);
$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(); $stmt->execute();
} }

View File

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