Example #1
0
 /**
  * Activate user
  * @param RestoUser $user
  */
 private function activateUser($user)
 {
     if (isset($user) && isset($this->context->query['act'])) {
         if ($user->activate($this->context->query['act'])) {
             /*
              * Close database handler and redirect to a human readable page...
              */
             if (isset($this->context->query['redirect'])) {
                 if (isset($this->context->dbDriver)) {
                     $this->context->dbDriver->closeDbh();
                 }
                 header('Location: ' . $this->context->query['redirect']);
                 exit;
             } else {
                 RestoLogUtil::success('User activated');
             }
         } else {
             RestoLogUtil::error('User not activated');
         }
     } else {
         RestoLogUtil::httpError(400);
     }
 }
Example #2
0
 /**
  * 
  * Process HTTP POST request on users
  * 
  *    user/cart                                     |  Add new item in user cart
  *    user/orders                                   |  Send an order for user
  *
  * @param array $segments
  * @param array $data
  */
 private function POST_user($segments, $data)
 {
     if (!isset($segments[1]) || isset($segments[2])) {
         RestoLogUtil::httpError(404);
     }
     /**
      * 
      * Insert item in cart
      * 
      *  @SWG\Post(
      *      tags={"cart"},
      *      path="/user/cart",
      *      summary="Insert item",
      *      description="Insert item in user cart",
      *      operationId="insertCartItem",
      *      produces={"application/json"},
      *      @SWG\Parameter(
      *          name="_clear",
      *          in="query",
      *          description="True to clear cart before inserting item",
      *          required=false,
      *          default=false,
      *          type="string",
      *          @SWG\Items(type="string")
      *      ),
      *      @SWG\Response(
      *          response="200",
      *          description="Acknowledgment that item was added to cart"
      *      ),
      *      @SWG\Response(
      *          response="403",
      *          description="Forbidden"
      *      )
      * )
      * 
      */
     if ($segments[1] === 'cart') {
         $clear = isset($this->context->query['_clear']) ? filter_var($this->context->query['_clear'], FILTER_VALIDATE_BOOLEAN) : false;
         /*
          * Remove items first
          */
         if ($clear) {
             $this->user->getCart()->clear(true);
         }
         /*
          * Add items
          */
         $items = $this->user->getCart()->add($data, true);
         return $items !== false ? RestoLogUtil::success('Add items to cart', array('items' => $items)) : RestoLogUtil::error('Cannot add items to cart');
     } else {
         if ($segments[1] === 'orders') {
             $order = $this->user->placeOrder($data);
             return $order ? RestoLogUtil::success('Place order', array('order' => $order)) : RestoLogUtil::error('Cannot place order');
         } else {
             RestoLogUtil::httpError(404);
         }
     }
 }
Example #3
0
 /**
  * Sign license
  * 
  *  @param RestoLicense $license
  */
 public function signLicense($license)
 {
     if (!isset($license) || !is_object($license)) {
         return RestoLogUtil::error('License not set');
     }
     /*
      * Get array which describe the license
      */
     $license = $license->toArray();
     /*
      * User can sign license if it does not reach the signature quota
      */
     if ($this->context->dbDriver->execute(RestoDatabaseDriver::SIGNATURE, array('email' => $this->profile['email'], 'licenseId' => $license['licenseId'], 'signatureQuota' => $license['signatureQuota']))) {
         return RestoLogUtil::success('License signed', array('email' => $this->profile['email'], 'license' => $license));
     } else {
         return RestoLogUtil::error('Cannot sign license');
     }
 }
Example #4
0
 /**
  * 
  * Process HTTP PUT request on users
  *
  *    user
  *    user/cart/{itemid}                            |  Modify item in user cart
  * 
  * @param array $segments
  * @param array $data
  */
 private function PUT_user($segments, $data)
 {
     /*
      * user
      */
     if (!isset($segments[1])) {
         /*
          * For normal user (i.e. non admin), some properties cannot be modified after validation
          */
         if (!$this->user->isAdmin()) {
             /*
              * Already validated => avoid updating administrative properties
              */
             if (isset($this->user->profile['validatedby'])) {
                 unset($data['activated'], $data['validatedby'], $data['validationdate'], $data['country'], $data['organization'], $data['organizationcountry'], $data['flags']);
             }
             /*
              * These properties can only be changed by admin
              */
             unset($data['groups']);
         }
         /*
          * Ensure that user can only update its profile
          */
         $data['email'] = $this->user->profile['email'];
         $this->context->dbDriver->update(RestoDatabaseDriver::USER_PROFILE, array('profile' => $data));
         return RestoLogUtil::success('Update profile for user ' . $this->user->profile['email']);
     } else {
         if ($segments[1] === 'cart' && isset($segments[2])) {
             if ($this->user->getCart()->update($segments[2], $data, true)) {
                 return RestoLogUtil::success('Item ' . $segments[2] . ' updated', array('itemId' => $segments[2], 'item' => $data));
             } else {
                 return RestoLogUtil::error('Cannot update item ' . $segments[2]);
             }
         } else {
             RestoLogUtil::httpError(404);
         }
     }
 }
Example #5
0
 /**
  * 
  * Process user
  * 
  *    user/cart                                     |  Remove all cart items
  *    user/cart/{itemid}                            |  Remove {itemid} from user cart
  * 
  *  @SWG\Delete(
  *      tags={"user"},
  *      path="/user/cart/{itemId}",
  *      summary="Delete cart item(s)",
  *      description="Delete cart item {itemId}. Delete all items if no {itemId} is specified",
  *      operationId="deleteCartItem",
  *      produces={"application/json"},
  *      @SWG\Parameter(
  *          name="itemId",
  *          in="path",
  *          description="Cart item identifier",
  *          required=false,
  *          type="string",
  *          @SWG\Items(type="string")
  *      ),
  *      @SWG\Response(
  *          response="200",
  *          description="Acknowledgment on successful cart item(s) deletion"
  *      ),
  *      @SWG\Response(
  *          response="404",
  *          description="ItemId not found"
  *      ),
  *      @SWG\Response(
  *          response="403",
  *          description="Forbidden"
  *      )
  *  )
  * 
  * @param array $segments
  */
 private function DELETE_user($segments)
 {
     if (isset($segments[1]) && $segments[1] === 'cart') {
         /*
          * Clear all cart items
          */
         if (!isset($segments[2])) {
             return $this->user->getCart()->clear(true) ? RestoLogUtil::success('Cart cleared') : RestoLogUtil::error('Cannot clear cart');
         } else {
             return $this->user->getCart()->remove($segments[2], true) ? RestoLogUtil::success('Item removed from cart', array('itemid' => $segments[2])) : RestoLogUtil::error('Item cannot be removed', array('itemid' => $segments[2]));
         }
     } else {
         RestoLogUtil::httpError(404);
     }
 }