<?php require_once './functionPHP.php'; class Users { public $_email; public $_password; public $_error = ''; public $_showBooks = false; protected $_userId = null; public function __construct($email, $password) { $this->_email = $email; $this->_password = $password; } public function Check() { if ($this->_email != '' && $this->_password != '') { $connect = connect(); $email = mysqli_real_escape_string($connect, $this->_email); $query = "SELECT user_id, user_password FROM users WHERE user_email = '$email'"; $result = mysqli_query($connect, $query); if (mysqli_num_rows($result) == 1) { $user = mysqli_fetch_assoc($result); if ($this->_password == $user['user_password']) { $this->_showBooks = true; $this->_userId = $user['user_id']; } else { $this->_error = 'Неверный пароль'; } } else { $this->_error = 'Пользователь с таким email не найден'; } mysqli_close($connect); } else { $this->_error = 'Заполните оба поля'; } } public function getError() { return $this->_error; } public function getShowBooks() { return $this->_showBooks; } public function getId() { return $this->_userId; } } class Registration { public string $_email; public string $_password; public string $_repeatPassword; public array $_errors = []; public bool $_success = false; public function __construct(string $email, string $password, string $repeatPassword) { $this->_email = htmlentities($email); $this->_password = htmlentities($password); $this->_repeatPassword = htmlentities($repeatPassword); } public function register(): void { $connect = connect(); if ($this->_password !== $this->_repeatPassword) { echo $this->_errors[] = 'Введите одинаковые пароли'; return; } $email = mysqli_real_escape_string($connect, $this->_email); $query = "SELECT COUNT(*) AS `count` FROM `users` WHERE `user_email` = '$email'"; $result = mysqli_query($connect, $query); $count = mysqli_fetch_assoc($result)['count']; if ($count > 0) { echo $this->_errors[] = 'Такой email уже существует'; mysqli_close($connect); return; } $query = "INSERT INTO `users` (user_email, user_password) VALUES ('$email', '{$this->_password}')"; mysqli_query($connect, $query); mysqli_close($connect); $this->_success = true; } public function getErrors(): array { return $this->_errors; } public function isSuccess(): bool { return $this->_success; } } class Logout{ public static function exit() { session_destroy(); header('Location: ./авторизация.php'); exit; } }
You have javascript disabled. You will not be able to edit any code.