Exemple #1
0
 public function register()
 {
     if ($this->get_uid()) {
         return $this->get_uid();
     }
     $res = db::Query("INSERT INTO users.info DEFAULT VALUES RETURNING uid", [], true);
     return $this->get_login($res->uid);
 }
Exemple #2
0
 private function CheckForRequestFrame($network)
 {
     try {
         $res = db::Query("UPDATE personal.frequency\n          SET last_access=now()\n          WHERE network=\$1\n          AND now() - last_access > min_interval\n          RETURNING *", [$network], true);
         return $res();
     } catch (Exception $e) {
         return false;
     }
 }
Exemple #3
0
 private function new_income($data = [])
 {
     $trans = db::Begin();
     $handle = db::Query("INSERT INTO transactions(system, data) VALUES (\$1, \$2) RETURNING id", ["yandex.wallet", json_encode($data)], true);
     $result = $trans->Commit();
     if (!$result) {
         header('500 Failed to store transaction');
         exit;
     }
 }
Exemple #4
0
 private function get_account_object($account_id)
 {
     if (!empty($this->loaded_accounts[$account_id])) {
         return $this->loaded_accounts[$account_id];
     }
     $account = db::Query("SELECT *\n      FROM personal.tokens\n      WHERE uid=\$1\n        AND account_id=\$2", [db::UID(), $account_id], true);
     phoxy_protected_assert($account(), "Account not found. Please connect again");
     list($obj, $user) = $this->network_signin($account->network, json_decode($account->token_data, true));
     db::Query("UPDATE personal.tokens\n        SET profile_id=\$2\n        WHERE account_id=\$1", [$account_id, $user->id]);
     return $this->loaded_accounts[$account_id] = $obj;
 }
Exemple #5
0
 protected function register()
 {
     if (isset($_POST["register"])) {
         if (!empty($_POST['username']) && !empty($_POST['password'])) {
             $username = $_POST['username'];
             $password = $_POST['password'];
             $sameusers = db::Query("select * from users WHERE username=\$1", [$username]);
             if ($sameusers() == 0) {
                 $useradd = "INSERT INTO users (username,password) VALUES (\$1,\$2) RETURNING id";
                 $result = db::Query($useradd, [$username, $password], true);
                 if ($result() != 0) {
                     return "Аккаунт создан, вы прекрасны";
                 } else {
                     return "Ошибка :p";
                 }
             } else {
                 return "Такой чувак уже есть.";
             }
         } else {
             return "Поля незаполнены!";
         }
     }
 }
Exemple #6
0
 protected function vote($id, $delta)
 {
     return db::Query("UPDATE quotes SET ratio=ratio+\$2 WHERE id=\$1 RETURNING ratio", [$id, $delta], true)->ratio;
 }
Exemple #7
0
<?php

require_once 'vendor/autoload.php';
if (!PRODUCTION) {
    error_reporting(E_ALL);
    ini_set('display_errors', 'On');
}
function phoxy_conf()
{
    $ret = phoxy_default_conf();
    $ret["api_xss_prevent"] = PRODUCTION;
    return $ret;
}
function default_addons()
{
    $ret = ["cache" => PRODUCTION ? ['global' => '10m'] : "no", "result" => "canvas"];
    return $ret;
}
include 'phoxy/phoxy_return_worker.php';
phoxy_return_worker::$add_hook_cb = function ($that) {
    global $USER_SENSITIVE;
    if ($USER_SENSITIVE) {
        $that->obj['cache'] = 'no';
    }
};
phpsql\OneLineConfig(conf()->db->connection_string);
db::Query("INSERT INTO requests(url, get, post, headers, server) VALUES (\$1, \$2, \$3, \$4, \$5)", [$_SERVER['QUERY_STRING'], json_encode($_GET), json_encode($_POST), json_encode(getallheaders()), json_encode($_SERVER)]);
include 'phoxy/load.php';
Exemple #8
0
 public function info($account_id)
 {
     $account = db::Query("SELECT *\n      FROM personal.tokens\n      WHERE uid=\$1 AND account_id=\$2", [db::UID(), $account_id], true);
     phoxy_protected_assert($account(), "Internal issue: account not found");
     return $this->PrepareAccount($account);
 }
Exemple #9
0
 protected function rendertags($id)
 {
     $sql_tags = db::Query("SELECT tag FROM tags WHERE quote_id=\$1", [$id]);
     return ["design" => "quotes/tags", "data" => ["tags" => $sql_tags]];
 }
Exemple #10
0
 public function Update($type, $resource_id, $data, $expiration)
 {
     // TODO: Update if exists
     db::Query("DELETE FROM personal.account_cache WHERE expired < now()");
     db::Query("INSERT INTO personal.account_cache\n        (account_id, type, resource_id, data, expired)\n        VALUES (\$1, \$2, \$3, \$4, 'epoch'::timestamp + \$5::int8 * '1 second'::interval)", [$this->AccountID(), $type, $resource_id, json_encode($data, true), $expiration]);
 }
Exemple #11
0
}
function SQLLoad($file)
{
    header("SQL: {$file}", false);
    $con = db::RawConnection();
    $sql = file_get_contents($file);
    pg_send_query($con, $sql);
    if (($error = pg_last_error($con)) !== '') {
        die("Failure at loading {{$file}} with {{$error}}");
    }
    while (pg_connection_busy($con)) {
        sleep(1);
    }
    while (pg_get_result($con) !== false) {
        if (($error = pg_last_error($con)) !== '') {
            die("Failure at loading {{$file}} with {{$error}}");
        }
    }
}
if (db::RawConnection() == false) {
    EmergencyCreateDB();
}
$res = @db::Query("SELECT * FROM quotes LIMIT 1");
if (is_string($res)) {
    // then its error
    SQLLoad("sql/schema.sql");
} else {
    if (!$res()) {
    }
}
header("SQL: OK", false);
Exemple #12
0
 public function Register()
 {
     return db::Query("INSERT INTO personal.users DEFAULT VALUES RETURNING uid", [], true)->uid;
 }