User Creation
This commit is contained in:
parent
0ff234d61d
commit
0830637271
@ -3,8 +3,8 @@ class UserManager
|
|||||||
{
|
{
|
||||||
public function getUsers () {
|
public function getUsers () {
|
||||||
try {
|
try {
|
||||||
$allRoom = Db::loadAll ("SELECT * FROM users");
|
$allUsers = Db::loadAll ("SELECT user_id, username FROM users");
|
||||||
return $allRoom;
|
return $allUsers;
|
||||||
} catch(PDOException $error) {
|
} catch(PDOException $error) {
|
||||||
echo $error->getMessage();
|
echo $error->getMessage();
|
||||||
die();
|
die();
|
||||||
@ -64,9 +64,6 @@ class UserManager
|
|||||||
public function logout () {
|
public function logout () {
|
||||||
unset($_SESSION['user']);
|
unset($_SESSION['user']);
|
||||||
session_destroy();
|
session_destroy();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (isset($_COOKIE['rememberMe'])){
|
if (isset($_COOKIE['rememberMe'])){
|
||||||
unset($_COOKIE['rememberMe']);
|
unset($_COOKIE['rememberMe']);
|
||||||
setcookie("rememberMe", 'false', time(), BASEDIR, $_SERVER['HTTP_HOST']);
|
setcookie("rememberMe", 'false', time(), BASEDIR, $_SERVER['HTTP_HOST']);
|
||||||
@ -190,10 +187,27 @@ class UserManager
|
|||||||
if (self::getHashPassword($oldPassword) == $oldPasswordSaved) {
|
if (self::getHashPassword($oldPassword) == $oldPasswordSaved) {
|
||||||
self::setUserData('password', self::getHashPassword($newPassword));
|
self::setUserData('password', self::getHashPassword($newPassword));
|
||||||
} else {
|
} else {
|
||||||
throw new ChybaUzivatele ("old password did not match");
|
throw new Exception ("old password did not match");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new ChybaUzivatele ("new password arent same");
|
throw new Exception ("new password arent same");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createUser($userName, $password){
|
||||||
|
$userId = Db::loadOne('SELECT * FROM users WHERE username = ?;', array($userName))['user_id'];
|
||||||
|
if ($userId != null) {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
$user = [
|
||||||
|
'username' => $userName,
|
||||||
|
'password' => self::getHashPassword($password),
|
||||||
|
];
|
||||||
|
return Db::add ('users', $user);
|
||||||
|
} catch(PDOException $error) {
|
||||||
|
echo $error->getMessage();
|
||||||
|
die();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user