diff --git a/.gitignore b/.gitignore index bffac2c..51193cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea/* application/config/* +logs/* \ No newline at end of file diff --git a/application/App.php b/application/App.php new file mode 100644 index 0000000..bcf65d9 --- /dev/null +++ b/application/App.php @@ -0,0 +1,49 @@ +guard = AuthorizationGuard::getInstance(); + $this->route = new Route(); + $request = new Request(); + } + + public static function getInstance() + { + if (is_null(self::$instance)) { + self::$instance = new self(); + } + + return self::$instance; + } + + public function run() + { + $this->isAuth = $this->guard->isAuthorized(); + + $this->route->start(); + } + +} \ No newline at end of file diff --git a/application/bootstrap.php b/application/bootstrap.php index 807f735..12089d6 100644 --- a/application/bootstrap.php +++ b/application/bootstrap.php @@ -9,12 +9,10 @@ use \application\core\Route; - - require_once 'core/BaseModel.php'; require_once 'core/BaseView.php'; require_once 'core/BaseController.php'; require_once 'core/Route.php'; - -Route::start(); // запускаем маршрутизатор \ No newline at end of file +$route = new Route(); +$route->start(); \ No newline at end of file diff --git a/application/components/AuthorizationGuard.php b/application/components/AuthorizationGuard.php new file mode 100644 index 0000000..d1366e2 --- /dev/null +++ b/application/components/AuthorizationGuard.php @@ -0,0 +1,138 @@ +security = new Security(); + $this->userRepository = new UserRepository(); + } + + // вот через этот метод мы будем получать инстанс + // если класс не был инстанцирован, делаем это + // если был, пропускаем этот шаш и сразу возвращаем инстанс + // итого: у нас всегда будет один и тот же экзмепляр этого класса + public static function getInstance() + { + if (is_null(self::$instance)) { + self::$instance = new self(); + } + + return self::$instance; + } + + // простой геттер + public function getCurrentUser() + { + return $this->currentUser; + } + + // простой сеттер + public function setCurrentUser(User $user) + { + return $this->currentUser = $user; + } + + // регистрация + public function registerUser(array $data) + { + $data['password'] = $this->security->encode($data['password']); + unset($data['password_check']); + if ($this->userRepository->add($data)) { + return true; + } else { + $this->errors[] = $this->userRepository->getError(); + return false; + } + } + + // авторизация + public function authUser(array $data = null) + { + if ($this->isAuthorized()) { + return true; + } + $user = new User(); + $passwordHash = $this->userRepository->get(['email' => $data['email']], 'password'); + $success = $this->security->checkPassword($data['password'], $passwordHash[0]['password']); + if (!$success) { + $this->errors['message'] = 'Неверный email или пароль'; + return false; + } + $user->getByEmail($data['email']); + $cookie = $this->security->encode($data['email'] . $passwordHash[0]['password']); + setcookie('isAuth', $cookie, strtotime('+30 days'), '/'); + $this->userRepository->edit($user->getId(), ['cookie' => $cookie]); + $this->setCurrentUser($user); + + return true; //smth|bool|User|че там надо; + } + + public function isAuthorized() + { + + $user = new User(); + + if (!isset($_COOKIE['isAuth'])) { + return false; + } + + $result = $this->userRepository->get(['cookie' => $_COOKIE['isAuth']]); + if (!empty($result)) { + $user->getByEmail($result[0]['email']); + $this->setCurrentUser($user); + return true; + } + + setcookie('isAuth', '', strtotime( '-1 days' ), '/'); + return false; + } + /** + * @return array + */ + public function getErrors(): array + { + return $this->errors; + } +} \ No newline at end of file diff --git a/application/components/Request.php b/application/components/Request.php new file mode 100644 index 0000000..059f496 --- /dev/null +++ b/application/components/Request.php @@ -0,0 +1,13 @@ + 'validateRequired', + 'email' => 'validateEmail', + 'string' => 'validateString', + 'phone' => 'validatePhone', + 'password' => 'validatePassword', + 'unique' => 'validateUnique' + ]; + + /** + * @param array $arrayOfData + * @param array $rules + * @return bool + */ + public function validate($arrayOfData, $rules) + { + // проверка совпадений паролей + if (array_key_exists('password', $arrayOfData) && array_key_exists('password_check', $arrayOfData)) { + $this->passwordCheck[] = $arrayOfData['password']; + $this->passwordCheck[] = $arrayOfData['password_check']; + } + foreach ($arrayOfData as $attribute => $value) { + if (array_key_exists($attribute, $rules)) { + $tmpRules = explode('|', $rules[$attribute]); + foreach ($tmpRules as $rule) { + if (!isset($this->validatorsMapping[$rule])) { + throw new InvalidValidatorException(); + } + + if ($rule == 'unique') { + $this->unique = $attribute; + } + $method = $this->validatorsMapping[$rule]; + if(!$this->$method($value)) { + // Если нет значения -> записываем, есть значение -> нет + if (!array_key_exists('attribute', $this->errorMessages)) { + $this->errorAttributes[] = $attribute; + } else { + if (!in_array($attribute, $this->errorAttributes)) { + $this->errorAttributes[] = $attribute; + } + } + } + } + } + } + if (!empty($this->errorMessages)) { + return false; + } + + return true; + } + + /** + * Проверка телефона + * @param $inputPhone + * @return bool + */ + protected function validatePhone($inputPhone) + { + $inputPhone = $this->clean($inputPhone); + $inputPhone = str_replace(['+', ' ', '(' , ')', '-'], '', $inputPhone); + // только ли цифры? + if (!is_numeric($inputPhone)) { + $this->errorMessages[] = 'Введен неверный формат телфона'; + return false; + } + // Длина телефона + if (!$this->checkLength($inputPhone,6,12)) { + $this->errorMessages[] = 'Телефон введен верно?'; + return false; + } + + return true; + } + + /** + * Обязательное поле. + * Не пустая ли значние + * @param $input + * @return bool + */ + protected function validateRequired($input) + { + if (empty($input)) { + // Если есть такая ошибка, больше не пишет данную ошибку + if (!in_array('Поля не должны быть пустыми', $this->errorMessages)) { + $this->errorMessages[] = 'Поля не должны быть пустыми'; + } + return false; + } + return true; + } + + /** + * Строковое значение + * @param $input + * @return bool + */ + protected function validateString($input) + { + $input = $this->clean($input); + return is_string($input); + } + + /** + * Проверка email + * @param $inputEmail + * @return bool + */ + protected function validateEmail($inputEmail) + { + $inputEmail = $this->clean($inputEmail); + if (!filter_var($inputEmail, FILTER_VALIDATE_EMAIL)) { + $this->errorMessages[] = 'Email введен неверно'; + return false; + } + + return true; + } + + /** + * проверка пароля + * @param $inputPassword + * @return bool + */ + protected function validatePassword($inputPassword) + { + if (!empty($this->passwordCheck) && $this->passwordCheck[0] != $this->passwordCheck[1]) { + $this->errorMessages[] = 'Введенные пароли не совпадают'; + return false; + } + $inputPassword = $this->clean($inputPassword); + if (!$this->checkLength($inputPassword, 6, 200)) { + $this->errorMessages[] = 'Пароль должен быть больше 6-ти символов'; + return false; + } + + return true; + } + + protected function validateUnique($input) + { + $repository = new UserRepository(); + if ($repository->get([$this->unique => $input], $this->unique)) { + $this->errorMessages[] = 'Пользователь с таким ' . $this->unique . ' уже существует'; + return false; + } + + return true; + } + + /** + * Возвращает массив с ошибками + * @return array + */ + public function getErrorsMessages() + { + return $this->errorMessages; + } + + /** + * Массив с атрибутами полей + * @return array + */ + public function getErrorsAttributes() + { + return $this->errorAttributes; + } + + public function getErrors() + { + return [ + 'errors' => $this->errorMessages, + 'attributes' => $this->errorAttributes + ]; + } + + /** + * Функция для проверки длины input'а + * @param string $value - input field + * @param $min + * @param $max + * @return bool + */ + protected function checkLength($value = "", $min, $max) + { + $result = (mb_strlen($value) < $min || mb_strlen($value) > $max); + return !$result; + } + + /** + * Отчиста данных от html и php тегов + * @param string $value + * @return string + */ + protected function clean($value = "") + { + $value = trim($value); + $value = stripslashes($value); + $value = strip_tags($value); + $value = htmlspecialchars($value); + + return $value; + } +} +?> \ No newline at end of file diff --git a/application/contracts/PasswordEncoder.php b/application/contracts/PasswordEncoder.php new file mode 100644 index 0000000..23622b9 --- /dev/null +++ b/application/contracts/PasswordEncoder.php @@ -0,0 +1,18 @@ +view->render('administration_view.php'); + } + +} \ No newline at end of file diff --git a/application/controllers/ControllerAuthorization.php b/application/controllers/ControllerAuthorization.php new file mode 100644 index 0000000..017dbc3 --- /dev/null +++ b/application/controllers/ControllerAuthorization.php @@ -0,0 +1,102 @@ +view->render('authorization_view.php','template_view.php'); + } + + /** + * ControllerLogin constructor. + */ + public function __construct() + { + parent::__construct(); + $this->guard = AuthorizationGuard::getInstance(); + } + + public function actionRegister() + { + if (!isset($_POST['registerForm'])) { + $this->view->render('register_view.php'); + throw new InvalidInputDataException(); + return false; + } + $data = $_POST['registerForm']; + $rules = [ + 'name' => 'string|required', + 'phone' => 'string|phone|unique', + 'email' => 'string|required|email|unique', + 'password' => 'string|required|password', + 'password_check' => 'string|required' + ]; + + // Валидация + $validation = new Validator(); + $formIsValid = $validation->validate($data, $rules); + if($formIsValid) { + if ($this->guard->registerUser($data)) { + $this->view->render('register_view.php', ['success' => 'Регистрация прошла успешно :)']); + return true; + } + + $this->view->render('register_view.php', ['errors' => 'Что-то пошло не так... Попробуйте позже :)']); + } else { + $this->view->render('register_view.php', $validation->getErrors()); + } + } + + /** + * + */ + public function actionLogin(){ + + if (!isset($_POST['loginForm'])) { + echo "error"; + } + $validation = new Validator(); + $rules = [ + 'email' => 'string|required|email', + 'password' => 'string|required|password' + ]; + $formIsValid = $validation->validate($_POST['loginForm'], $rules); + if ($formIsValid) { + if ($this->guard->authUser($_POST['loginForm'])) { +// header ('Location: /');*/ + $this->view->render("site_view.php"); + } else { + $errors = $this->guard->getErrors(); + $this->view->render('authorization_view.php', ['errors' => $errors['message']]); + } + } else { + $this->view->render('authorization_view.php', ['errors' => 'Некоректные значения.']); + } + } + + public function actionLogout() + { + setcookie('isAuth', '', strtotime( '-1 days' ), '/'); + header ('Location: /'); + } + + public function actionFormRegister() + { + $this->view->render('register_view.php','template_view.php'); + } + +} diff --git a/application/controllers/ControllerLogin.php b/application/controllers/ControllerLogin.php deleted file mode 100644 index 9a9f009..0000000 --- a/application/controllers/ControllerLogin.php +++ /dev/null @@ -1,38 +0,0 @@ -view->render('login_view.php','template_view.php'); - } - - - public function actionRegister() - { - $user = new User(); - if (!isset($_POST['submitted'])) { - $error = require_once '../application/views/error_view.php'; - } - $this->view->render('register_view.php','template_view.php',['error' => $error]); - //$user->checkInput($_POST); - // - } - - public function actionFormRegister() - { - $this->view->render('register_view.php','template_view.php'); - } - -} diff --git a/application/controllers/ControllerSite.php b/application/controllers/ControllerSite.php index 589db09..d240d79 100644 --- a/application/controllers/ControllerSite.php +++ b/application/controllers/ControllerSite.php @@ -7,16 +7,17 @@ */ namespace application\controllers; +use application\App; +use application\components\AuthorizationGuard; use application\core\BaseController; -use application\repositories; - +use application\repositories\CategoryRepository; class ControllerSite extends BaseController { function actionIndex() { - $categories = new \application\repositories\CategoryRepository(); + $categories = new CategoryRepository(); $data = $categories->getAllRows(); - $this->view->render('site_view.php', 'template_view.php',['categories' => $data]); + $this->view->render('site_view.php', ['categories' => $data]); } } \ No newline at end of file diff --git a/application/core/BaseController.php b/application/core/BaseController.php index f3d1b8d..8a10eae 100644 --- a/application/core/BaseController.php +++ b/application/core/BaseController.php @@ -7,10 +7,17 @@ */ namespace application\core; +use application\components\Validator; + class BaseController { + /** + * ХДЕ ПХПДОК КОММЕНТАРИИ??!!!! + */ + protected $view; + function __construct() { $this->view = new BaseView(); @@ -19,4 +26,9 @@ function __construct() function actionIndex() { } + + protected function validate() + { + $validate = new Validator(); + } } \ No newline at end of file diff --git a/application/core/BaseModel.php b/application/core/BaseModel.php index 78fe12b..da50035 100644 --- a/application/core/BaseModel.php +++ b/application/core/BaseModel.php @@ -16,7 +16,7 @@ class BaseModel /** * @var $repository экземпляр класса репозитория */ - protected $repository; + protected $table; public function getTable() { diff --git a/application/core/BaseView.php b/application/core/BaseView.php index 805e252..ceaf491 100644 --- a/application/core/BaseView.php +++ b/application/core/BaseView.php @@ -5,16 +5,33 @@ * Date: 01.08.17 * Time: 15:20 */ + namespace application\core; + class BaseView { - protected $templateView = "template_view.php"; // здесь можно указать общий вид по умолчанию. + /** + * Шаблон используемый по умолчанию + * @var $templateView + */ + protected $templateView = "template_view.php"; - function render($contentView, $templateView, $data = null) + /** + * @param $contentView контент + * @param $templateView шаблон + * @param $data массив с данными передаваемые в шаблон + */ + function render($contentView, $data = null, $templateView = null) { if (is_array($data)) { extract($data); } - include __DIR__.'/../views/'.$templateView; + + if (!is_null($templateView)) { + $this->templateView = $templateView; + } + + + require_once __DIR__.'/../views/layout/' . $this->templateView; } } diff --git a/application/core/Route.php b/application/core/Route.php index bd4cce7..2e8cd21 100644 --- a/application/core/Route.php +++ b/application/core/Route.php @@ -7,79 +7,57 @@ */ namespace application\core; - - - +use application\helpers\MyException; class Route { - // контроллер и действие по умолчанию - private static $modelName = 'model'; - private static $controllerName = 'Site'; - private static $actionName = 'index'; + protected $controllerName = 'Site'; + protected $actionName = 'index'; - - public static function start() + public function start() { $routes = explode('/', $_SERVER['REQUEST_URI']); // получаем имя контроллера if (!empty($routes[1])) { - self::$controllerName = ucfirst($routes[1]); + $this->controllerName = ucfirst($routes[1]); } // получаем имя экшена if (!empty($routes[2])) { - self::$actionName = $routes[2]; + $this->actionName = $routes[2]; } // добавляем префиксы - self::setPrefix(self::$controllerName,self::$actionName); - - // подцепляем файл с классом модели (файла модели может и не быть) - $modelFile = self::$modelName.'.php'; - $modelPath = "../application/models/".$modelFile; - - if (file_exists($modelPath)) { - require $modelPath; - } + $this->setPrefix($this->controllerName, $this->actionName); // подцепляем файл с классом контроллера - $controllerPath = '../application/controllers/'.self::$controllerName.'.php'; + $controllerPath = '../application/controllers/' . $this->controllerName . '.php'; if (file_exists($controllerPath)) { - require $controllerPath; + require_once $controllerPath; } else { - //self::ErrorPage404(); + } // создаем контроллер - $controllerName = '\\application\\controllers\\'.self::$controllerName; + $controllerName = '\\application\\controllers\\' . $this->controllerName; $controller = new $controllerName; - $action = self::$actionName; + $action = $this->actionName; if (method_exists($controller, $action)) { // вызываем действие контроллера $controller->$action(); } else { - //self::ErrorPage404(); + } } - private function setPrefix($controller, $action = null) + protected function setPrefix($controller, $action = null) { - self::$modelName = $controller; - self::$controllerName = 'Controller'.$controller; - self::$actionName = 'action'.$action; + $this->controllerName = 'Controller' . $controller; + $this->actionName = 'action' . $action; } - - private function ErrorPage404() - { - $host = 'http://'.$_SERVER['HTTP_HOST'].'/'; - header('HTTP/1.1 404 Not Found'); - header("Status: 404 Not Found"); - header('Location:'.$host.'404'); - } } diff --git a/application/dbal/Database.php b/application/dbal/Database.php index be1a69f..aa81981 100644 --- a/application/dbal/Database.php +++ b/application/dbal/Database.php @@ -8,14 +8,14 @@ namespace application\dbal; +use \Exception; use PDO; class Database { - /** - * ссылка на подключение к БД - * @var PDO - */ + + protected static $instance = null; + protected $pdo; /** @@ -24,16 +24,28 @@ class Database */ protected $error; - public function __construct() + private function __construct() { $this->pdo = $this->getDB(); } /** - * @param $data массив с входными данными + * @return PDO + */ + public static function getInstance() + { + if(is_null(self::$instance)) { + self::$instance = new self; + } + + return self::$instance; + } + + /** + * @param $data array * @return array [columns,values,anchors] */ - public function getPreparedData($data) + public function getPreparedData(array $data) { $columns = []; $values = []; @@ -41,7 +53,7 @@ public function getPreparedData($data) foreach ($data as $key => $value) { $columns[] = $key; $values[] = $value; - $anchors[] = ":".$key; + $anchors[] = ":" . $key; } return [ 'columns' => $columns, @@ -56,14 +68,13 @@ public function getPreparedData($data) */ public function getDB(){ if (is_null($this->pdo)) { - $database = require_once '../application/config/database.php'; - $this->pdo = new PDO( - 'mysql:host=' . $database['host'] . - ';dbname='. - $database['database'] .';charset=utf8;', - $database['user'], - $database['password'] - ); + try{ + $database = include '../application/config/database.php'; + $this->pdo = new PDO('mysql:host='.$database['host'].';dbname='. + $database['database'].';charset=utf8;', $database['user'], $database['password']); + } catch (Exception $exception) { + echo $exception->getMessage(); + } } return $this->pdo; } @@ -129,13 +140,12 @@ public function makeSelect($sql, $data = null) $this->error = $statement->errorInfo(); return false; } - } /** * Метод, который присваевает якорям их значения - * @param $statement - * @param $data [values[0], anchors[1]] + * @param $statement подготовленный sql запрос + * @param $data [array values[0], array anchors[1]] * @return mixed $statement */ protected function bindParams($statement, $data) @@ -145,9 +155,9 @@ protected function bindParams($statement, $data) if (is_array($values) and is_array($anchors)) { foreach ($values as $key => $value) { if (is_numeric($value)) { - $statement->bindValue($anchors[$key],$value,PDO::PARAM_INT); + $statement->bindValue($anchors[$key], $value, PDO::PARAM_INT); } else { - $statement->bindValue($anchors[$key],$value,PDO::PARAM_STR); + $statement->bindValue($anchors[$key], $value, PDO::PARAM_STR); } } } else { diff --git a/application/helpers/Log.php b/application/helpers/Log.php new file mode 100644 index 0000000..4cb4ebb --- /dev/null +++ b/application/helpers/Log.php @@ -0,0 +1,39 @@ +time = date("H:i:s"); + $this->message = $this->time . " "; + $this->message .= $message . PHP_EOL; + file_put_contents($this->file, $this->message, FILE_APPEND | LOCK_EX); + } +} \ No newline at end of file diff --git a/application/models/Cake.php b/application/models/Cake.php index 8872757..a6c5aa4 100644 --- a/application/models/Cake.php +++ b/application/models/Cake.php @@ -11,6 +11,9 @@ class Cake extends BaseModel { + /** + * Все эти методы должны обрабатываться контроллером тортиков + */ public function add() { diff --git a/application/models/User.php b/application/models/User.php index 75b4ae5..42057ec 100644 --- a/application/models/User.php +++ b/application/models/User.php @@ -9,34 +9,81 @@ use application\core\BaseModel; use application\repositories\UserRepository; - +use application\components\Security; class User extends BaseModel { - protected $repository; + protected $table = 'users'; - public function __construct() - { - $this->repository = new UserRepository(); - } + protected $id; + + protected $email; + + protected $isAdmin = false; + + protected $age; - public function checkInput($input) + + public function getByEmail($email) { - if (!isset($input['submitted'])) { - return false; + $repository = new UserRepository(); + $data = $repository->get(['email' => $email]); + if(!empty($data)) { + $this->setData($data[0]); + return true; } - return true; + return false; } - public function register($data) + protected function setData(array $data) { - var_dump($data); - if (!is_null($data)) { - if ($data['password'] === $data['password_check']) { - array_pop($data); - $this->repository->add($data); + foreach ($data as $key => $value) { + if (property_exists($this,$key)) { + $this->$key = $value; } } } + + /** + * @return mixed + */ + public function getId() + { + return $this->id; + } + + /** + * @return mixed + */ + public function getAge() + { + return $this->age; + } + + /** + * @param mixed $age + */ + public function setAge($age) + { + $this->age = $age; + } + + /** + * @return mixed + */ + public function getEmail() + { + return $this->email; + } + + /** + * @param mixed $email + */ + public function setEmail($email) + { + $this->email = $email; + } + + } diff --git a/application/repositories/BaseRepository.php b/application/repositories/BaseRepository.php index b9c91ce..7c012a2 100644 --- a/application/repositories/BaseRepository.php +++ b/application/repositories/BaseRepository.php @@ -8,8 +8,9 @@ namespace application\repositories; use application\dbal\Database; -abstract class BaseRepository{ +abstract class BaseRepository +{ /** * @var Database $connection */ @@ -23,13 +24,38 @@ abstract class BaseRepository{ public function __construct() { - $this->connection = new Database(); + $this->connection = Database::getInstance(); } /** - * Возвращает все торты из бд + * Возвращает массив с заданными параметрами + * @param array $parameters (example 'where $parameters') + * @param string|null $columns (example 'id,name') + * @return array + */ + public function get(array $parameters, $columns = null) + { + $dataToExecute = $this->connection->getPreparedData($parameters); + foreach ($dataToExecute['columns'] as $key => $value) { + $columnAndAnchor[] = $value . ' = ' . $dataToExecute['anchors'][$key]; + } + $columnAndAnchor = implode(' and ', $columnAndAnchor); + if ($columns) { + $sql = "SELECT $columns FROM $this->table WHERE $columnAndAnchor"; + } else { + $sql = "SELECT * FROM $this->table WHERE $columnAndAnchor"; + } + + if($result = $this->connection->makeSelect($sql,[$dataToExecute['values'],$dataToExecute['anchors']])) { + return $result; + } + return []; + } + + /** + * Изменение записи в бд + * @param $id * @param $data - * @return array|bool */ public function edit($id, $data) { @@ -45,42 +71,62 @@ public function edit($id, $data) $this->runQuery($sql,[$dataToExecute['values'], $dataToExecute['anchors']]); } + /** + * Добавление записи в таблицу + * @param $data + * @return bool + */ public function add($data) { $dataToExecute = $this->connection->getPreparedData($data); - $anchors = implode(',',$dataToExecute['anchors']); - $columns = implode(',',$dataToExecute['columns']); + $anchors = implode(',', $dataToExecute['anchors']); + $columns = implode(',', $dataToExecute['columns']); $sql = "INSERT INTO $this->table (". $columns . ") VALUES (" . $anchors . ')'; - $this->runQuery($sql, [$dataToExecute['values'], $dataToExecute['anchors']]); + $result = $this->runQuery($sql, [$dataToExecute['values'], $dataToExecute['anchors']]); + return $result; } + /** + * Все записи из таблицы $table + * @return array|bool + */ public function getAllRows() { $sql = "SELECT * FROM $this->table"; $data = $this->connection->makeSelect($sql); return $data; } + /** * Удаление из таблицы элемента по id * @param $id */ - public function deleteById($id) + public function delete($id) { $sql = "DELETE FROM $this->table WHERE id = :id"; $this->runQuery($sql,[[$id], [':id']]); } + public function getError() + { + return $this->connection->getError(); + } + /** * Проверка на выполнение запроса * Если запрос неудачный, показывает ошибку * @param $sql * @param null|array $values + * @return bool */ protected function runQuery($sql, $values = null) { if(!$this->connection->executeQuery($sql, $values)) { - var_dump($this->connection->getError()); + //var_dump($this->connection->getError()); + return false; } + return true; } + } \ No newline at end of file diff --git a/application/repositories/CakeRepository.php b/application/repositories/CakeRepository.php index 1a89f34..a84c904 100644 --- a/application/repositories/CakeRepository.php +++ b/application/repositories/CakeRepository.php @@ -11,26 +11,4 @@ class CakeRepository extends BaseRepository { protected $table = 'cakes'; - - - /** - * Возвращает массив с заданными параметрами - * @param array $parameters (example 'where $parameters') - * @param string|null $columns (example 'id,name') - * @return array|bool - */ - public function getCakes($parameters, $columns = null) - { - $dataToExecute = $this->connection->getPreparedData($parameters); - foreach ($dataToExecute['columns'] as $key => $value) { - $columnAndAnchor[] = $value . ' = ' . $dataToExecute['anchors'][$key]; - } - $columnAndAnchor = implode(' and ',$columnAndAnchor); - if ($columns) { - $sql = "SELECT $columns FROM $this->table WHERE $columnAndAnchor"; - } else { - $sql = "SELECT * FROM $this->table WHERE $columnAndAnchor"; - } - return $this->connection->makeSelect($sql,[$dataToExecute['values'],$dataToExecute['anchors']]); - } } \ No newline at end of file diff --git a/application/repositories/UserRepository.php b/application/repositories/UserRepository.php index 12bcfd2..06ee2df 100644 --- a/application/repositories/UserRepository.php +++ b/application/repositories/UserRepository.php @@ -11,21 +11,4 @@ class UserRepository extends BaseRepository { protected $table = 'users'; - public function add($data) - { - $data['password'] = $this->setPassword($data['password']); - parent::add($data); - } - - - public function editPassword() - { - - } - - - protected function setPassword($password) - { - return password_hash($password,PASSWORD_DEFAULT); - } } \ No newline at end of file diff --git a/application/views/administration_view.php b/application/views/administration_view.php new file mode 100644 index 0000000..e69de29 diff --git a/application/views/login_view.php b/application/views/authorization_view.php similarity index 54% rename from application/views/login_view.php rename to application/views/authorization_view.php index a4b1b9c..fd373a5 100644 --- a/application/views/login_view.php +++ b/application/views/authorization_view.php @@ -3,13 +3,16 @@