Exemplo n.º 1
0
 function moveCategory($params)
 {
     if (!is_object($params) || !isset($params->id) || !isset($params->direction) || !in_array($params->direction, array('up', 'down'))) {
         JsonRpc::setInvalidParamsError($this);
         return null;
     }
     return $this->_moveCategory($params->id, $params->direction);
 }
Exemplo n.º 2
0
 function getProducts($params)
 {
     // check params
     if (!is_object($params)) {
         JsonRpc::setInvalidParamsError($this);
         return null;
     }
     // expected params are offset/count/filters(object)/order_by/order_dir.
     // for now the filters will include category/search_term/price_lower/price_higher/code/sale(y/n)/in_stock
     return ProductModel::getProducts($params->limit, $params->offset, $params->filters);
 }
Exemplo n.º 3
0
 function callJsonRPC($method, $params = null)
 {
     // check if the method exists...
     if (!$this->checkMethod($this->selectedGroup, $method)) {
         return null;
     }
     if (!$this->checkParams($this->selectedGroup, $method, $params)) {
         return array("result" => null, "error" => JsonRpc::getInvalidParamsError());
     }
     // load class
     $CI =& get_instance();
     $handlerClassName = $this->descriptors[$this->selectedGroup]["handlerClass"];
     $handlerClassNameLc = strtolower($handlerClassName);
     $CI->load->library('business/' . $handlerClassName);
     $result = $CI->{$handlerClassNameLc}->{$method}($params);
     $errorCode = $CI->{$handlerClassNameLc}->errorCode;
     $errorMessage = $CI->{$handlerClassNameLc}->errorMessage;
     return array("result" => $result, "error" => $errorCode != 0 ? array('code' => $errorCode, 'message' => $errorMessage) : null);
 }
Exemplo n.º 4
0
 function authenticate($params)
 {
     // params must be a username and a password hash
     if (is_object($params) && isset($params->userName) && isset($params->password) && isset($params->salt)) {
         $user = UserModel::authenticateUser($params->userName, $params->password, $params->salt);
         if ($user === false) {
             $this->errorCode = -1;
             $this->errorMessage = "Authentication failure!";
         }
         if ($user !== false) {
             $CI =& get_instance();
             $CI->load->library('session');
             $CI->session->set_userdata('user_id', $user->id);
             return true;
         }
         return false;
     } else {
         JsonRpc::setInvalidParamsError($this);
     }
     return false;
 }
Exemplo n.º 5
0
<?php

/*
*Copyright 2012 Gianrico D'Angelis  -- gianrico.dangelis@gmail.com
*
*Licensed under the Apache License, Version 2.0 (the "License");
*you may not use this file except in compliance with the License.
*You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*Unless required by applicable law or agreed to in writing, software
*distributed under the License is distributed on an "AS IS" BASIS,
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*See the License for the specific language governing permissions and
*limitations under the License.
*/
@define(BASEPATH, '../system/');
//folder, contain database classes
@define(APPPATH, '../application/');
@define(EXT, '.php');
require_once '../system/database/DB.php';
include_once "./lib/jsonrpc.lib.php";
include_once "./rpcmethods/emrpc.methods.php";
header("Content-Type: application/json");
$server = new JsonRpc(new EmrpcServer());
$server->process();