Example #1
0
 protected function proceed()
 {
     $srv = new UsersService();
     switch ($this->action) {
         case 'get':
             $this->succeed($srv->get($this->params['id']));
             break;
         case 'getAll':
             $this->succeed($srv->getAll());
             break;
         case 'updPwd':
             $this->succeed($srv->updatePassword($this->params['id'], $this->params['oldPwd'], $this->params['newPwd']));
             break;
     }
 }
Example #2
0
function getuserbyid($id)
{
    global $app;
    try {
        $us = new UsersService();
        $user = $us->getUsersByID($id);
        if ($user) {
            $app->response()->header('Content-Type', 'application/json');
            echo json_encode($user);
        } else {
            throw new ResourceNotFoundException();
        }
    } catch (ResourceNotFoundException $e) {
        $app->response()->status(404);
        $app->response()->header('X-Status-Reason', $e->getMessage());
    } catch (ResourceNotFoundException $e) {
        $app->response()->status(400);
        $app->response()->header('X-Status-Reason', $e->getMessage());
    }
}
function authenticate()
{
    $headers = apache_request_headers();
    if (isset($headers["X-Authorization"])) {
        $apiKey = $headers["X-Authorization"];
        require_once SERVICES_PATH . "UsersService.php";
        $user = UsersService::loadUserByApiKey($apiKey);
        if (empty($user)) {
            echoAccessDeniedResponse("Invalid key");
        } else {
            global $userId;
            $userId = $user->id;
        }
    } else {
        echoAccessDeniedResponse("No key");
    }
}
        $response["status"] = UsersService::$USER_SUCCESSFULLY_REGISTERED;
        $response["user"] = $user;
        $response["errorMessage"] = "";
    } else {
        $response["status"] = UsersService::$USER_REGISTRATION_ERROR;
        $response["errorMessage"] = "Error al registrar Usuario.";
    }
    echoResponse(200, $response);
});
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
//Login
$app->post('/login', function () use($app) {
    //Get Json body
    $bodyJson = json_decode($app->request->getBody());
    //Parse User
    $user = User::fromJsonObject($bodyJson->user);
    //Check Login
    if (!UsersService::checkLogin($user->login, $user->password)) {
        $response["errorMessage"] = "Usuario y/o contraseña incorrecta.";
        echoResponse(200, $response);
        return;
    }
    //Return Api Key
    $user = UsersService::loadUserByLogin($user->login);
    $response["user"] = $user;
    $response["errorMessage"] = "";
    echoResponse(201, $response);
});
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
//Run
$app->run();
Example #5
0
 protected function setUp()
 {
     // Attribute set
     $set = new AttributeSet("set");
     $attr = new Attribute("attr", 1);
     $val = new AttributeValue("value");
     $attr->id = AttributesService::createAttribute($attr);
     $val->id = AttributesService::createValue($val, $attr->id);
     $attr->addValue($val);
     $set->addAttribute($attr);
     $set->id = AttributesService::createSet($set);
     // Product, tax and category
     $taxCat = new TaxCat("Tax");
     $tax = new Tax(null, "Tax", stdtimefstr("2001-01-01 00:00:00"), 0.1);
     $taxCat->addTax($tax);
     $taxCat->id = TaxesService::createCat($taxCat);
     $taxCat2 = new TaxCat("Tax2");
     $tax2 = new Tax(null, "Tax2", stdtimefstr("2001-01-01 00:00:00"), 0.2);
     $taxCat2->addTax($tax2);
     $taxCat2->id = TaxesService::createCat($taxCat2);
     $pdo = PDOBuilder::getPDO();
     $stmt = $pdo->prepare("INSERT INTO CATEGORIES (ID, NAME) " . "VALUES (:id, :name)");
     $stmt->execute(array(":id" => "-1", ":name" => "Refill"));
     $cat = new Category(null, "Category", false, 1);
     $cat->id = CategoriesService::createCat($cat);
     $prd = new Product("REF", "product", 1.0, $cat->id, null, 1, $taxCat->id, true, false, 0.5, $set->id);
     $prd->id = ProductsService::create($prd);
     $prd2 = new Product("REF2", "product2", 2.0, $cat->id, null, 1, $taxCat2->id, true, false, 0.5, null);
     $prd2->id = ProductsService::create($prd2);
     $prdRefill = new Product("REFILL", "Refill", 1.0, "-1", null, 1, $taxCat->id, true, false);
     $prdRefill->id = ProductsService::create($prdRefill);
     // Tariff area
     $srvArea = new TariffAreasService();
     $area = new TariffArea("area", 1);
     $area->addPrice($prd->id, 0.8);
     $area->id = $srvArea->create($area);
     $this->areaId = $area->id;
     // Customer
     $srvCust = new CustomersService();
     $cust = new Customer(1, "Cust", "It's me", "card", null, null, 50.0, 10.0, 5.0, stdtimefstr("2012-01-01 00:00:00"), "It's", "me", "*****@*****.**", "012345", "23456", "11111", "Address1", "Address2", "59000", "City", "Region", "France", "Note", true);
     $cust->id = $srvCust->create($cust);
     $this->custId = $cust->id;
     // Location
     $locSrv = new LocationsService();
     $loc = new Location("Location");
     $loc->id = $locSrv->create($loc);
     $this->locationId = $loc->id;
     // Cash register
     $srvCashReg = new CashRegistersService();
     $cashReg = new CashRegister("Cash", $loc->id, 1);
     $cashReg->id = $srvCashReg->create($cashReg);
     // Cash
     $srvCash = new CashesService();
     $cash = $srvCash->add($cashReg->id);
     $cash->openDate = stdtimefstr("2000-02-02 02:02:02");
     $srvCash->update($cash);
     $this->cashId = $cash->id;
     // User
     $srvUsers = new UsersService();
     $user = new User("User", null, null, "0", true, false);
     $user->id = $srvUsers->create($user);
     // Currency
     $curr = new Currency("Eur", "€", ",", ".", "#,##0.00\$", 1, true, false);
     $srvCurr = new CurrenciesService();
     $curr->id = $srvCurr->create($curr);
     // Discount profile
     $profSrv = new DiscountProfilesService();
     $prof = new DiscountProfile("Profile", 0.1);
     $prof->id = $profSrv->create($prof);
     $this->discountProfilId = $prof->id;
     // Ticket
     $tkt1 = array("date" => stdtimefstr("2012-01-01 00:00:00"), "userId" => $user->id, "customerId" => null, "type" => Ticket::TYPE_SELL, "custCount" => 3, "tariffAreaId" => null, "discountRate" => 0.0, "discountProfileId" => null, "payments" => array(array("type" => "cash", "amount" => 10, "currencyId" => $curr->id, "currencyAmount" => 12)), "lines" => array(array("dispOrder" => 1, "productId" => $prd->id, "taxId" => $tax->id, "attributes" => null, "quantity" => 1.0, "price" => 10.0, "discountRate" => 0.0)));
     $jsAttr = array("attributeSetId" => $set->id, "values" => array(array("id" => $attr->id, "value" => "value")));
     $tkt2 = array("date" => stdtimefstr("2012-01-01 00:00:00"), "userId" => $user->id, "customerId" => null, "type" => Ticket::TYPE_SELL, "custCount" => 3, "tariffAreaId" => null, "discountRate" => 0.25, "discountProfileId" => $prof->id, "payments" => array(array("type" => "cash", "amount" => 10, "currencyId" => $curr->id, "currencyAmount" => 12)), "lines" => array(array("dispOrder" => 1, "productId" => $prd->id, "taxId" => $tax->id, "attributes" => $jsAttr, "quantity" => 1.0, "price" => 10.0, "discountRate" => 0.25)));
     $this->jsTicket1 = json_encode($tkt1);
     $this->jsTicket2 = json_encode($tkt2);
 }
<?php

session_start();
date_default_timezone_set('Asia/Bangkok');
$method = $_SERVER['REQUEST_METHOD'];
$request = explode("/", substr(@$_SERVER['PATH_INFO'], 1));
$input = json_decode(file_get_contents("php://input"));
require_once 'incSession.php';
require_once '../services/UsersService.php';
$sv = new UsersService();
$user = NULL;
//--- test------start
// $method = 'PUT'; //POST PUT DELETE GET
// $input = '{"aaaa":"aaaa"}';
//--- test------end
$s = new Session();
$data = $s->read(session_id());
if (!empty($data->user_name)) {
    $user = $data->user_name;
} else {
    if ($method == 'POST' && $request[0] == 'login') {
    } else {
        // 	$s->destroy(session_id());
        // 	http_response_code(401);
        // 	echo "you have not permission to access";
        // 	header("Location: /nutritionapps/");
        // 	exit();
    }
}
if (!empty($input->userid)) {
    $user = $input->userid;
 protected function setUp()
 {
     // Attribute set
     $set = new AttributeSet("set");
     $attr = new Attribute("attr", 1);
     $val = new AttributeValue("value");
     $attr->id = AttributesService::createAttribute($attr);
     $val->id = AttributesService::createValue($val, $attr->id);
     $attr->addValue($val);
     $this->attr = $attr;
     $set->addAttribute($attr);
     $set->id = AttributesService::createSet($set);
     $this->attrSet = $set;
     // Product, tax and category
     $taxCat = new TaxCat("Tax");
     $tax = new Tax(null, "Tax", stdtimefstr("2001-01-01 00:00:00"), 0.1);
     $taxCat->addTax($tax);
     $taxCat->id = TaxesService::createCat($taxCat);
     $taxCat2 = new TaxCat("Tax2");
     $tax2 = new Tax(null, "Tax2", stdtimefstr("2001-01-01 00:00:00"), 0.2);
     $taxCat2->addTax($tax2);
     $taxCat2->id = TaxesService::createCat($taxCat2);
     $this->tax = $taxCat->taxes[0];
     $this->tax2 = $taxCat2->taxes[0];
     $pdo = PDOBuilder::getPDO();
     $stmt = $pdo->prepare("INSERT INTO CATEGORIES (ID, NAME) " . "VALUES (:id, :name)");
     $stmt->execute(array(":id" => "-1", ":name" => "Refill"));
     $cat = new Category(null, "Category", false, 1);
     $cat->id = CategoriesService::createCat($cat);
     $prd = new Product("REF", "product", 1.0, $cat->id, null, 1, $taxCat->id, true, false, 0.5, $set->id);
     $prd->id = ProductsService::create($prd);
     $this->prd = $prd;
     $prd2 = new Product("REF2", "product2", 2.0, $cat->id, null, 1, $taxCat2->id, true, false, 0.5, null);
     $prd2->id = ProductsService::create($prd2);
     $prdRefill = new Product("REFILL", "Refill", 1.0, "-1", null, 1, $taxCat->id, true, false);
     $prdRefill->id = ProductsService::create($prdRefill);
     $this->prd = $prd;
     $this->prd2 = $prd2;
     $this->prdRefill = $prdRefill;
     // Tariff area
     $srvArea = new TariffAreasService();
     $area = new TariffArea("area", 1);
     $area->addPrice($this->prd->id, 0.8);
     $area->id = $srvArea->create($area);
     $this->area = $area;
     // Discount profile
     $srvProfile = new DiscountProfilesService();
     $profile = new DiscountProfile("Discount profile", 1.0);
     $profile->id = $srvProfile->create($profile);
     $this->discountProfile = $profile;
     // Customer
     $srvCust = new CustomersService();
     $cust = new Customer(1, "Cust", "It's me", "card", null, null, 50.0, 10.0, 5.0, stdtimefstr("2012-01-01 00:00:00"), "It's", "me", "*****@*****.**", "012345", "23456", "11111", "Address1", "Address2", "59000", "City", "Region", "France", "Note", true);
     $cust->id = $srvCust->create($cust);
     $this->customer = $cust;
     // Location
     $locSrv = new LocationsService();
     $loc = new Location("Location");
     $loc->id = $locSrv->create($loc);
     $this->location = $loc;
     // Cash
     $srvCashReg = new CashRegistersService();
     $cashReg = new CashRegister("CashReg", $loc->id, 1);
     $cashReg->id = $srvCashReg->create($cashReg);
     $srvCash = new CashesService();
     $cash = $srvCash->add($cashReg->id);
     $cash->openDate = stdtimefstr("2000-02-02 02:02:02");
     $srvCash->update($cash);
     $this->cash = $cash;
     // User
     $srvUsers = new UsersService();
     $user = new User("User", null, null, "0", true, false);
     $user->id = $srvUsers->create($user);
     $this->user = $user;
     // Currency
     $curr = new Currency("Eur", "€", ",", ".", "#,##0.00\$", 1, true, false);
     $srvCurr = new CurrenciesService();
     $curr->id = $srvCurr->create($curr);
     $this->currency = $curr;
 }