From 77d5aef39cb59decc75963eae67a081ae1233d0d Mon Sep 17 00:00:00 2001 From: Stanislav Dmitriev Date: Tue, 2 Feb 2021 15:18:44 +0500 Subject: [PATCH] added deleting user --- delete.php | 39 ++++++++++++++++++++++++++++++ functions.php | 61 +++++++++++++++++++++++++++++++++++++++++++---- logout.php | 5 +--- page_register.php | 12 ++++++---- security.php | 2 +- test.php | 2 +- users.php | 2 +- 7 files changed, 107 insertions(+), 16 deletions(-) create mode 100644 delete.php diff --git a/delete.php b/delete.php new file mode 100644 index 0000000..38287f1 --- /dev/null +++ b/delete.php @@ -0,0 +1,39 @@ + intval($user_id), + ]; + $statement = $pdo->prepare($query); + $statement->execute($params); + return boolval($statement); +} + /** * Записать в БД путь до изображения аватара * @@ -94,7 +130,7 @@ function set_avatar_path(int $user_id, string $path) $query = "UPDATE users SET img=:img WHERE id = :id"; $params = [ - 'id' => $user_id, + 'id' => intval($user_id), 'img' => $path, ]; $statement = $pdo->prepare($query); @@ -139,8 +175,9 @@ function set_status(int $user_id, string $status) * * @return boolean */ -function is_valid_passwords(string $password, string $confirmed_password){ - return ($password===$confirmed_password)&&!empty($password); +function is_valid_passwords(string $password, string $confirmed_password) +{ + return ($password === $confirmed_password) && !empty($password); } /** @@ -153,7 +190,8 @@ function is_valid_passwords(string $password, string $confirmed_password){ * * @return boolean */ -function edit_credentials(int $user_id, string $email, string $password){ +function edit_credentials(int $user_id, string $email, string $password) +{ global $pdo; $query = "UPDATE users SET email=:email, password=:password @@ -218,6 +256,19 @@ function is_not_logged_in() return (!isset($_SESSION['user']) && empty($_SESSION['user'])); } +/** + * Функция выхода из аккаунта + * + * @return void + */ +function logout() +{ + if (isset($_SESSION['user'])) + unset($_SESSION['user']); + session_destroy(); +} + + /** * Функция авторизации пользователя * diff --git a/logout.php b/logout.php index 93287c7..a7910c7 100644 --- a/logout.php +++ b/logout.php @@ -1,9 +1,6 @@
+
-
diff --git a/security.php b/security.php index b289578..a5640d0 100644 --- a/security.php +++ b/security.php @@ -7,7 +7,7 @@ exit(); } // Есть ли права на редактирование -if (!is_admin() ?? $_POST['id'] !== $_SESSION['user']['id']) { +if (!is_admin() && $_POST['id'] !== $_SESSION['user']['id']) { set_flash_message('danger', 'Недостаточно прав для редактирования'); redirect_to('users.php'); exit(); diff --git a/test.php b/test.php index 7786d6a..671530c 100644 --- a/test.php +++ b/test.php @@ -2,4 +2,4 @@ // этот файл не участвует в работе сайта session_start(); include_once 'functions.php'; -echo is_valid_passwords("1","1"); \ No newline at end of file +d(get_user_by_id(42)); \ No newline at end of file diff --git a/users.php b/users.php index e355a7c..824e7c2 100644 --- a/users.php +++ b/users.php @@ -107,7 +107,7 @@ class="fs-xl text-truncate text-truncate-lg text-info"> Загрузить аватар - Удалить