public function actionSetUserEventParticipation()
 {
     $objValidator = new helpers\Validation();
     $params = array('event', 'user_token', 'participation');
     try {
         $isRequestValid = $objValidator->validateRequest($params);
         if ($isRequestValid) {
             $userToken = $this->_request->getPost('user_token', null);
             $objUserMdl = new \models\Users();
             $eventId = $this->_request->getPost('event', null);
             $dataToInsert = array('events_id' => $eventId, 'participation_id' => $this->_request->getPost('participation', null));
             // check if user is valid or not
             $userDetails = $objUserMdl->getUserFromToken($userToken);
             if (!$userDetails) {
                 $this->_request->sendErrorResponse(403, 403, 'User token invalid');
             }
             $objUsersEventParticipation = new \models\UsersEventsParticipation();
             $dataToInsert['users_id'] = $userDetails->id;
             $isStatusSaved = $objUsersEventParticipation->insertUserEventParticipation($dataToInsert, $userDetails);
             if ($isStatusSaved) {
                 // send push notification
                 $objNotifier = new \models\Pushnotifications();
                 $objNotifier->participationNotifications($eventId, $userDetails);
                 $this->_request->sendSuccessResponse('Status Saved');
             } else {
                 $this->_request->sendErrorResponse(404, 404, 'Error saving status');
             }
         } else {
             $this->_request->sendErrorResponse(403, 403, 'Request cannot be validated');
         }
     } catch (\Exception $e) {
         $this->_request->sendErrorResponse(404, 404, $e->getMessage());
     }
 }
Ejemplo n.º 2
0
 public function loginAction()
 {
     if (Helpers\Input::exists() && Helpers\Token::check(Helpers\Input::get('token'))) {
         $valid = helpers\Validation::check(array('username' => array('required' => true, 'name' => 'Username'), 'password' => array('required' => true, 'name' => 'Password')));
         if (empty($valid->errors())) {
         } else {
             $_SESSION['errors']['login'] = $valid->errors;
         }
     }
 }
Ejemplo n.º 3
0
 public function actionUpdateUserProfile()
 {
     $objValidator = new helpers\Validation();
     $objImageProcessor = new helpers\ImageProcessor();
     $params = array('user_token');
     try {
         $isRequestValid = $objValidator->validateRequest($params);
         if ($isRequestValid) {
             $objUserAuthMdl = new \models\Users();
             $userToken = $this->_request->getPost('user_token', null);
             $userDetails = $objUserAuthMdl->getUserFromToken($userToken);
             if (!$userDetails) {
                 $this->_request->sendErrorResponse(403, 403, 'User token invalid');
             }
             $profilePhoto = null;
             $profilePostedPic = $this->_request->getPost('profilepic', null);
             $dpPath = __DIR__ . '/../images/' . $userDetails->id . '_pp.jpg';
             if ($profilePostedPic && $objImageProcessor->convertBase64ToImage($profilePostedPic, $dpPath)) {
                 $profilePhoto = $userDetails->id . '_pp.jpg';
             }
             $password = $this->_request->getPost('password', null);
             $dataToUpdate = array('first_name' => $this->_request->getPost('first_name', null), 'last_name' => $this->_request->getPost('last_name', null), 'email' => $this->_request->getPost('email', null), 'password' => $password ? md5($password) : null, 'city' => $this->_request->getPost('city', null), 'country' => $this->_request->getPost('country', null), 'gender' => $this->_request->getPost('gender', null), 'phone' => $this->_request->getPost('phone', null), 'address' => $this->_request->getPost('address', null), 'websiteurl' => $this->_request->getPost('websiteurl', null));
             $fileterdArray = array_filter($dataToUpdate);
             if (empty($fileterdArray)) {
                 $this->_request->sendErrorResponse(404, 404, 'Please pass data to update');
             }
             // check if user is valid or not
             $return = $objUserAuthMdl->updateUser($dataToUpdate, $userDetails);
             if ($return && $return > 0) {
                 $this->_request->sendSuccessResponse('User successfully updated');
             } else {
                 if ($return == -1) {
                     $this->_request->sendErrorResponse(404, 404, 'Email alredy exists');
                 } else {
                     if ($return == -2) {
                         $this->_request->sendErrorResponse(404, 404, 'Invalid email address');
                     } else {
                         $this->_request->sendErrorResponse(404, 404, 'Error updating user please try latere');
                     }
                 }
             }
         } else {
             $this->_request->sendErrorResponse(403, 403, 'Request cannot be validated');
         }
     } catch (\Exception $e) {
         $this->_request->sendErrorResponse(404, 404, $e->getMessage());
     }
 }
Ejemplo n.º 4
0
 public function actionUpdate()
 {
     $objValidator = new helpers\Validation();
     $params = array('dog_id', 'name', 'date_of_birth', 'breed', 'gender', 'user_token');
     try {
         $isRequestValid = $objValidator->validateRequest($params);
         if ($isRequestValid) {
             $userToken = $this->_request->getPost('user_token', null);
             $objUserMdl = new \models\Users();
             $objDogMdl = new \models\Dogs();
             $dataToInsert = array('name' => $this->_request->getPost('name', null), 'date_of_birth' => $this->_request->getPost('date_of_birth', null), 'dog_breed_id' => $this->_request->getPost('breed', null), 'gender' => $this->_request->getPost('gender', null), 'dog_pic' => $this->_request->getPost('dogpic', null), 'id' => $this->_request->getPost('dog_id', null));
             // check if user is valid or not
             $userDetails = $objUserMdl->getUserFromToken($userToken);
             if (!$userDetails) {
                 $this->_request->sendErrorResponse(403, 403, 'User token invalid');
             }
             $isDogInserted = $objDogMdl->updateDogProfile($dataToInsert, $userDetails->id);
             if ($isDogInserted) {
                 $this->_request->sendSuccessResponse('Dog Profile updated');
             } else {
                 $this->_request->sendErrorResponse(404, 404, 'Error updating dog profile');
             }
         } else {
             $this->_request->sendErrorResponse(403, 403, 'Request cannot be validated');
         }
     } catch (\Exception $e) {
         echo $e->getMessage();
         $this->_request->sendErrorResponse(404, 404, $e->getMessage());
     }
 }
Ejemplo n.º 5
0
 /**
  * Public function action delete event
  * 
  * **/
 public function actionDeleteEvent()
 {
     $objValidator = new helpers\Validation();
     $params = array('user_token', 'eventid');
     try {
         $isRequestValid = $objValidator->validateRequest($params);
         if ($isRequestValid) {
             $userToken = $this->_request->getPost('user_token', null);
             $eventId = $this->_request->getPost('eventid', null);
             $objUserAuthMdl = new \models\Users();
             $objEventsModel = new \models\Events();
             $userDetails = $objUserAuthMdl->getUserFromToken($userToken);
             if (!$userDetails) {
                 $this->_request->sendErrorResponse(403, 403, 'User token invalid');
             }
             //check if event exists or not
             $eventRow = $objEventsModel->findEventById($eventId);
             if (!$eventRow->id) {
                 $this->_request->sendErrorResponse(403, 403, 'Invalid Event');
             }
             // check if event is owned by user
             $isUserEventOwner = $eventRow->users_id == $userDetails->id ? true : false;
             if (!$isUserEventOwner) {
                 $this->_request->sendErrorResponse(403, 403, 'User is not authenticated to delete event');
             }
             try {
                 \R::trash($eventRow);
                 $this->_request->sendSuccessResponse('Event successfully deleted');
             } catch (Exception $ex) {
                 $this->_request->sendErrorResponse(403, 403, 'Error deleting event');
             }
         } else {
             $this->_request->sendErrorResponse(403, 403, 'Request cannot be validated');
         }
     } catch (\Exception $e) {
         $this->_request->sendErrorResponse(404, 404, $e->getMessage());
     }
 }
Ejemplo n.º 6
0
 public function actionSearchExpertsByLocation()
 {
     $objValidator = new helpers\Validation();
     $params = array('user_token', 'query');
     try {
         $isRequestValid = $objValidator->validateRequest($params);
         if ($isRequestValid) {
             $userToken = $this->_request->getPost('user_token', null);
             $objUserMdl = new \models\Users();
             $obUserProfileMdl = new \models\UsersProfiles();
             // check if user is valid or not
             $userDetails = $objUserMdl->getUserFromToken($userToken);
             if (!$userDetails) {
                 $this->_request->sendErrorResponse(403, 403, 'User token invalid');
             }
             $query = $this->_request->getPost('query', null);
             $profiles = $obUserProfileMdl->searchUsersByLocation($query);
             if ($profiles) {
                 $this->_request->sendSuccessResponse('success', $profiles);
             } else {
                 $this->_request->sendErrorResponse(404, 404, 'Profiles not found');
             }
         } else {
             $this->_request->sendErrorResponse(403, 403, 'Request cannot be validated');
         }
     } catch (\Exception $e) {
         echo $e->getMessage();
         $this->_request->sendErrorResponse(404, 404, $e->getMessage());
     }
 }