Beispiel #1
0
 public static function register($username, $email, $password)
 {
     $user = new Model_User();
     $user->username = $username;
     $user->email = $email;
     $user->password = Hash::hash($password);
     $user->save();
 }
 protected function before()
 {
     parent::before();
     $userId = Session::get('userId');
     if ($userId) {
         $this->user = new Model_User();
         $this->user->get($userId);
     }
 }
 public function action_searchPhotos($text)
 {
     $photos = new Model_Photo();
     $allPhotos = [];
     $this->view = new View("photos/searchPhotos");
     foreach ($photos->getAll() as $photo) {
         $p = new Model_Photo();
         $p->get($photo['_id']);
         if ($p->loaded && isset($p->bigPath) && isset($p->smallPath) && file_exists("assets/uploads/" . $p->bigPath) && file_exists("assets/uploads/" . $p->smallPath) && stripos(strtolower($p->title), strtolower($text)) !== false) {
             if (isset($p->autorUser)) {
                 $autor = new Model_User();
                 $autor->get($p->autorUser);
                 $p->autor = $autor->username;
                 if ($p->tryb == "private" && (!$this->user || $autor->username != $this->user->username)) {
                     continue;
                 }
             }
             $allPhotos[] = $p;
         }
     }
     $this->view->passData('photos', $allPhotos);
 }
 public function action_rememberedPhotos()
 {
     $this->content = new View("photos/remembered");
     $photos = new Model_Photo();
     $allPhotos = [];
     foreach ($photos->getAll() as $photo) {
         $p = new Model_Photo();
         $p->get($photo['_id']);
         if ($p->loaded && isset($p->bigPath) && isset($p->smallPath) && file_exists("assets/uploads/" . $p->bigPath) && file_exists("assets/uploads/" . $p->smallPath)) {
             if (isset($p->autorUser)) {
                 $autor = new Model_User();
                 $autor->get($p->autorUser);
                 $p->autor = $autor->username;
                 if ($p->tryb == "private" && (!$this->user || $autor->username != $this->user->username)) {
                     continue;
                 }
             }
             if (Session::get("remember_photo_" . $p->_id->{'$id'}, false)) {
                 $allPhotos[] = $p;
             }
         }
     }
     $this->content->passData('photos', $allPhotos);
 }
 public function action_postRegister()
 {
     if (!$this->userNotAllowed()) {
         return;
     }
     try {
         Model_User::validate($_POST);
         Model_User::register($_POST['username'], $_POST['email'], $_POST['password']);
         Session::set('message', "Rejestracja przebiegła pomyślnie. Możesz się teraz zalogować.");
         $this->redirect(FRONT_CONTROLLER . '/user/login');
     } catch (Validation_Exception $exception) {
         $this->content = new View("user/register");
         $this->content->passData('errorField', $exception->field);
         $this->content->passData('error', $exception->error);
     }
 }
Beispiel #6
0
 public static function validate($data, $files, $userLogged = null)
 {
     $table = self::$table;
     if (isset($data['title']) && !empty($data['title'])) {
         if (strlen($data['title']) < 3) {
             throw new Validation_Exception('Tytuł', 2, 3);
         } else {
             if (strlen($data['title']) > 20) {
                 throw new Validation_Exception('Tytuł', 3, 20);
             }
         }
         if (!preg_match('#[0-9a-zA-Z\\s-]+#', $data['title'])) {
             throw new Validation_Exception('Tytuł', 6);
         }
     } else {
         throw new Validation_Exception('Tytuł', 1);
     }
     if (isset($data['autorUser'])) {
         $user = new Model_User();
         $user->get($data['autorUser']);
         if (!$user->loaded) {
             throw new Validation_Exception("Autor", 9);
         } else {
             if ($user->_id->{'$id'} !== $userLogged->_id->{'$id'}) {
                 throw new Validation_Exception("Autor", 9);
             }
         }
     } else {
         if (isset($data['autor']) && !empty($data['autor'])) {
             if (strlen($data['autor']) < 3) {
                 throw new Validation_Exception('Autor', 2, 3);
             } else {
                 if (strlen($data['autor']) > 20) {
                     throw new Validation_Exception('Autor', 3, 20);
                 }
             }
             if (!preg_match('#[0-9a-zA-Z\\s-]+#', $data['autor'])) {
                 throw new Validation_Exception('Autor', 6);
             }
         } else {
             throw new Validation_Exception('Autor', 1);
         }
     }
     if (empty($files["file"]["tmp_name"])) {
         throw new Validation_Exception('Zdjęcie', 10);
     }
     $targetFile = basename($files["file"]["name"]);
     $fileType = pathinfo($targetFile, PATHINFO_EXTENSION);
     $check = getimagesize($files["file"]["tmp_name"]);
     if ($check !== false) {
         $mime = $check["mime"];
         if ($files["file"]["size"] > 1000000) {
             throw new Validation_Exception('Zdjęcie', 11, '1MB');
         }
         if (!preg_match('/jpg|jpeg|png/', $fileType)) {
             throw new Validation_Exception('Zdjęcie', 12, "JPG, PNG");
         }
     } else {
         throw new Validation_Exception('Zdjęcie', 10);
     }
     return true;
 }