Better Login

This commit is contained in:
JonatanRek 2019-10-13 12:29:07 +02:00
parent 8274e51eb6
commit d9ca8fcb1a
3 changed files with 51 additions and 2 deletions

View File

@ -62,9 +62,14 @@ class UserManager
}
public function logout () {
setcookie ("rememberMe","", time() - (30 * 24 * 60 * 60 * 1000), str_replace("login", "", str_replace('https://' . $_SERVER['HTTP_HOST'], "", $_SERVER['REQUEST_URI'])), $_SERVER['HTTP_HOST'], 1);
unset($_SESSION['user']);
session_destroy();
if (isset($_COOKIE['rememberMe'])){
//unset($_COOKIE['rememberMe']);
setcookie ("rememberMe2", $this->setEncryptedCookie($user['username']), time () + (30 * 24 * 60 * 60 * 1000), '/vasek/home/', $_SERVER['HTTP_HOST'], 1);
setcookie("token", "restt", time() - 36000, "/");
die();
}
}
public function setEncryptedCookie($value){
@ -176,5 +181,19 @@ class UserManager
die();
}
}
public function changePassword($oldPassword, $newPassword, $newPassword2){
if ($newPassword == $newPassword2) {
//Password Criteria
$oldPasswordSaved = self::getUserData('password');
if (self::getHashPassword($oldPassword) == $oldPasswordSaved) {
self::setUserData('password', self::getHashPassword($newPassword));
} else {
throw new ChybaUzivatele ("old password did not match");
}
} else {
throw new ChybaUzivatele ("new password arent same");
}
}
}
?>

10
app/controls/setting.php Normal file
View File

@ -0,0 +1,10 @@
<?php
if (isset($_POST) && !empty($_POST)){
if (isset($_POST['submitPasswordChange']) && $_POST['submitPasswordChange'] != "") {
$oldPassword = $_POST['oldPassword'];
$newPassword = $_POST['newPassword1'];
$newPassword2 = $_POST['newPassword2'];
UserManager::changePassword($oldPassword, $newPassword, $newPassword2);
//TODO: pridat odhlášení
}
}

View File

@ -56,6 +56,26 @@
<a href="rooms" class="button"><?php $LANGMNG->echo('b_rooms') ?></a>
</div>
</div>
<div class="col-12 col-sm-9 mx-auto mt-4">
<h4 class="mb-4"><?php $LANGMNG->echo('t_changePassword') ?></h4>
<form method="post">
<div class="field">
<div class="label"><?php $LANGMNG->echo('l_oldPassword') ?>:</div>
<input type="password" class="input" name="oldPassword" value="" data-cip-id="cIPJQ342845639">
</div>
<div class="field">
<div class="label"><?php $LANGMNG->echo('l_newPassword') ?>:</div>
<input type="password" class="input" name="newPassword1" value="" data-cip-id="cIPJQ342845639">
</div>
<div class="field">
<div class="label"><?php $LANGMNG->echo('l_newPassword') ?>:</div>
<input type="password" class="input" name="newPassword2" value="" data-cip-id="cIPJQ342845639">
</div>
<div class="field">
<input type="submit" name="submitPasswordChange" class="button" value="Uložit">
</div>
</form>
</div>
</div>
@ -65,6 +85,6 @@
$partial = new Partial('footer');
$partial->render();
?>
</script>
</script>
</body>
</html>