Esempio n. 1
0
 public function setData(array $data = [])
 {
     Validate::check(is_array($data), "Wrong user data");
     foreach ($data as $key => $value) {
         if (property_exists($this, $key)) {
             $this->{$key} = $value;
         }
     }
 }
Esempio n. 2
0
 public static function get($id)
 {
     Validate::int($id, 1, null, "Пост не найден");
     $db = DB::instance();
     $query = $db->getQuery();
     $query->select("*")->from(self::$table)->where("id = '%d'", $id);
     $post = $db->queryRow($query);
     Validate::check(!empty($post), "Пост не найден", 404);
     return new self($post);
 }
Esempio n. 3
0
 public function run()
 {
     $uri = $_SERVER['REQUEST_URI'];
     $this->router = new Router($uri);
     $controller_class = ucfirst($this->router->controller) . "Controller";
     $action_method = "action" . ucfirst($this->router->action);
     Validate::check(class_exists($controller_class), "Controller {$controller_class} not found", 404);
     $this->controller = new $controller_class();
     Validate::check(method_exists($this->controller, $action_method), "Action {$action_method} not found", 404);
     echo call_user_func_array([$this->controller, $action_method], $this->router->data);
 }
Esempio n. 4
0
 public function actionDelete($id)
 {
     $user = UserModel::isAuthorized();
     if (!$user) {
         $this->redirect("/user/auth");
     }
     $post = PostModel::get($id);
     Validate::check($post->user_id == $user->id, "У вас не прав для редактирования этого блога", 403);
     $post->delete();
     $this->redirect("/");
 }
Esempio n. 5
0
 public static function authorize($email, $password)
 {
     Validate::length($email, 1, null, "Заполните поле Email");
     Validate::length($password, 1, null, "Заполните поле Пароль");
     $db = DB::instance();
     $query = $db->getQuery();
     $query->select("*")->from(self::$table)->where("email = '%s'", $email)->where("password = '******'", md5($password));
     $user = $db->queryRow($query);
     Validate::check(!empty($user), "Неверный логин или пароль");
     $_SESSION['user']['id'] = $user['id'];
     return new self($user);
 }