Пример #1
0
 /**
  * Save a new user to the database.
  *
  */
 public function store()
 {
     Csrf::checkToken($this->_request->getInput('_CSRF'));
     $validator = new Validator($this->_request);
     $rules = ['name' => ['required'], 'email' => ['required'], 'password' => ['required', 'password'], 'password-repeat' => ['required']];
     $name = $this->_request->getInput('name');
     $email = $this->_request->getInput('email');
     $password = $this->_request->getRawInput('password');
     $postData = $this->_request->getAllPostInput();
     if ($validator->validate($rules, $postData)) {
         $this->_user->name = $name;
         $this->_user->email = $email;
         $this->_user->password = $this->_auth->hashPassword($password);
         if ($this->_user->save()) {
             return header('Location: ' . POST_REGISTER_URL);
         }
         //The email address is already registered.
         $this->_pageData->errors = ['email' => ['That email address is already registered.']];
     } else {
         $this->_pageData->errors = $validator->getErrors();
     }
     $this->_pageData->csrfToken = Csrf::createToken();
     $this->_pageData->pageTitle = "Create User";
     $this->_pageData->loggedIn = $this->_auth->checkLoggedIn();
     $this->_pageData->name = $name;
     $this->_pageData->email = $email;
     return $this->_view->make('admin/create-user', $this->_pageData);
 }
Пример #2
0
 /**
  * Update a property.
  *
  * @param $id
  */
 public function update($id)
 {
     try {
         $this->_property = $this->_property->findOrFail($id);
     } catch (Exception $e) {
         return header('Location: ' . POST_UPDATE_PROPERTY_URL);
     }
     Csrf::checkToken($this->_request->getInput('_CSRF'));
     $this->_pageData->csrfToken = Csrf::createToken();
     $validator = new Validator($this->_request);
     $rules = ['name' => ['required']];
     $name = $this->_request->getInput('name');
     $rate = $this->_request->getInput('rate');
     $short_desc = $this->_request->getRawInput('short_desc');
     $long_desc = $this->_request->getRawInput('long_desc');
     $postData = $this->_request->getAllPostInput();
     if ($validator->validate($rules, $postData)) {
         $this->_property->name = $name;
         $this->_property->rate = $rate;
         $this->_property->short_Desc = $short_desc;
         $this->_property->long_Desc = $long_desc;
         if ($this->_property->save()) {
             return header('Location: ' . POST_ADD_PROPERTY_URL);
         }
     }
     $this->_pageData->pageTitle = "Edit Property";
     $this->_pageData->loggedIn = $this->_auth->checkLoggedIn();
     $this->_pageData->uri = $this->_request->getUri();
     $this->_pageData->csrfToken = Csrf::createToken();
     $this->_pageData->property = $this->_property;
     $this->_pageData->errors = $validator->getErrors();
     return $this->_view->make('admin/edit-property', $this->_pageData);
 }
Пример #3
0
 /**
  * Check availability of property.
  *
  * @return string
  */
 public function check()
 {
     //Validate the input
     $validator = new Validator($this->_request);
     $rules = ['check_in' => ['required'], 'check_out' => ['required']];
     $postData = $this->_request->getAllPostInput();
     if (!$validator->validate($rules, $postData)) {
         $response = ['status' => 'error', 'errors' => $validator->getErrors()];
         return $this->_response->returnJson($response);
     }
     $this->_reservation->pid = $postData['property'];
     $this->_reservation->check_in = date('Y-m-d', strtotime($this->_request->getInput("check_in")));
     $this->_reservation->check_out = date('Y-m-d', strtotime($this->_request->getInput("check_out")));
     $availability = new ReservationAvailability($this->_reservation);
     if (!$availability->check()) {
         $response = ['status' => 'unavailable'];
         return $this->_response->returnJson($response);
     }
     $response = ['status' => 'success'];
     return $this->_response->returnJson($response);
 }