示例#1
0
require_once '../lib/UploadFile.class.php';
/* $_POST['user_id']=1;
$_POST['access_token']='9e5cd477f4ff4a04d915b3892e58c033';
$_POST['canteen_id']=1;
$_POST['content']='哈哈哈哈'; */
if (isset($_POST['user_id']) && isset($_POST['access_token']) && isset($_POST['canteen_id']) && isset($_POST['content'])) {
    //用户是否合法
    $db = Db::getInstance(array('autocommit' => false));
    try {
        $db->connect();
    } catch (Exception $e) {
        echo getJsonResponse(1, '数据库连接错误', null);
        Log::error_log("数据库连接错误");
        exit;
    }
    if (!checkUserToken($db, $_POST['user_id'], $_POST['access_token'])) {
        echo getJsonResponse(2, '用户token错误', null);
        exit;
    }
    $content = stringToDb($_POST['content']);
    $sql = "insert into canteen_complaints values(null,{$_POST['user_id']},{$_POST['canteen_id']},'{$content}',now());\n\t\tselect last_insert_id();";
    if (!$db->startTransaction()) {
        //transiton
        echo getJsonResponse(1, "事务启动失败", null);
        $db->close();
        exit;
    }
    $mysqli = $db->getMysqli();
    $complaint_id;
    if ($mysqli->multi_query($sql)) {
        //第一条查询
示例#2
0
文件: auth.php 项目: AgoraUS1516/G03
/**
 * \brief Token correcto
 * \details Comprobar que un usuario está autenticado, usando el
 * nombre de usuario en el token.
 * \param $token Token.
 * \return Boolean
 */
function tokenIsCorrect($token)
{
    $username = explode(':', $token)[0];
    return checkUserToken($token, $username);
}
示例#3
0
文件: index.php 项目: AgoraUS1516/G03
/**
 * \brief Comprobar usuario
 * \details Comprobar si un usuario dado está ya autenticado en el sistema,
 * comprobando un token.
 * \return JSON
 */
function checkTokenUser($token, $user)
{
    header('HTTP/1.1 200 OK');
    header('Content-type: application/json');
    $result['valid'] = checkUserToken($token, $user);
    echo json_encode($result);
    return json_encode($result);
}
示例#4
0
function getUserShoppingCartTotal($customerToken, &$response)
{
    //$store = Mage::getSingleton('core/store')->load(1);
    if (!is_null($customerToken)) {
        $userId = checkUserToken($customerToken);
    } else {
        $userId = true;
    }
    if ($userId !== false) {
        $tax = 0;
        $shipping = 0;
        $subTotal = 0;
        $grandTotal = 0;
        $quote = Mage::getSingleton('checkout/session')->getQuote();
        $items = $quote->getAllVisibleItems();
        if (!empty($items)) {
            $totals = $quote->getTotals();
            $tax = $quote->getShippingAddress()->getData('tax_amount');
            $shipping = isset($totals["shipping"]) ? $totals["shipping"]->getValue() : 0;
            //$grandTotal = $totals["grand_total"]->getValue();
            foreach ($items as $item) {
                $subTotal = $subTotal + intval($item->getQty() * $item->getPrice());
            }
            $grandTotal = $subTotal + $tax + $shipping;
        }
        $response = array('total' => "\$ " . number_format($grandTotal, 2), 'tax' => number_format($tax, 2), 'shipping' => number_format($shipping, 2), 'subtotal' => number_format($subTotal, 2));
    } else {
        $response["error"] = "User token is not valid";
    }
}
示例#5
0
 /**
  * \brief Test negativo de checkTokenUser()
  * @expectedException PHPUnit_Framework_ExpectationFailedException
  */
 public function testNegative_checkTokenUser()
 {
     $username = "******";
     $password = "******";
     $token = getToken($username, $password);
     $this->assertTrue(checkUserToken($token, $username));
 }