<?php // Helper functions and includes include_once '/var/www/html/Lux/Core/Helper.php'; $DB = new Db("System"); $collection = $DB->selectCollection("Accounts"); $OUTPUT = new Output(); $REQUEST = new Request(); // get Password and Username from $REQUEST $document = $collection->findOne(array('$or' => array(array("system_info.user" => $REQUEST->get("user")), array("system_info.email" => $REQUEST->get("user"))))); if (password_verify($REQUEST->get("password"), $document["system_info"]["hash"])) { $lAT = bin2hex(openssl_random_pseudo_bytes(16)); // save $lAT into database if ($REQUEST->avail("response_type") && $REQUEST->get("response_type") == "code") { $collection->update(array("_id" => $document["_id"]), array('$addToSet' => array("system_info.OAuth_clients" => array("client_id" => $REQUEST->get("client_id"), "code" => $lAT))), array('multiple' => false, 'upsert' => true)); $OUTPUT->success(1, array("code" => $lAT)); die; } $collection->update(array("_id" => $document["_id"]), array('$set' => array("system_info.access_token" => $lAT)), array('multiple' => false, 'upsert' => true)); $OUTPUT->success(1, array("access_token" => $lAT, "user" => $document["system_info"]["user"])); } else { $OUTPUT->error(0, "Incorrect Username or Password"); }
<?php include_once '/var/www/html/Lux/Core/Helper.php'; $db = new Db("Scoreboard"); $OUTPUT = new Output(); $REQUEST = new Request(); $collection = $db->selectCollection("Users"); $RULES = new Rules(1, "scoreboard"); $REQUEST = new Request(); $quantity = intval($REQUEST->get("quantity", "1")); $asset_id = $REQUEST->get("asset_id"); $document = $collection->findAndModify(array("user_id" => $RULES->getId()), array('$inc' => array("assets." . $asset_id . ".quantity" => $quantity))); $LOG = new Logging("Scoreboard.asset"); $LOG->log($RULES->getId(), 61, $REQUEST->get("asset_id"), $quantity, "User added item to scoreboard Possessions"); $OUTPUT->success(0, $document, null);
<?php include_once '/var/www/html/Lux/Core/Helper.php'; $DB = new Db("SocialNetwork"); $OUTPUT = new Output(); $collection = $DB->selectCollection("Messages"); $REQUEST = new Request(); $RULES = new Rules(1, "social"); $query = array('root' => '1', array('participants' => $RULES->getId())); $options = Helper::formatLimits($REQUEST); $document = $collection->find($query, $options); $OUTPUT->success(0, $document); ?>
<?php // Helpers and includes include_once '/var/www/html/Lux/Core/Helper.php'; $db = new Db("SocialNetwork"); $OUTPUT = new Output(); $REQUEST = new Request(); $collection = $db->selectCollection("Groups"); $update = Helper::updatePermitted($REQUEST); $update = Helper::subDocUpdate($update, "providers.custom"); $options = Helper::formatOptions($REQUEST); if ($REQUEST->avail("id")) { $RULES = new Rules(5, "profile"); $document = $collection->findAndModify($REQUEST->get("id"), $update, $options); } else { $RULES = new Rules(1, "profile"); $document = $collection->findAndModify($RULES->getId(), $update, $options); } $OUTPUT->success(0, $document, null);
<?php include_once '/var/www/html/Lux/Core/Helper.php'; $DB = new Db("Auth"); $OUTPUT = new Output(); $collection = $DB->selectCollection("Clients"); $REQUEST = new Request(); // client_id redirect_uri state response_type:code scope $client_id = $REQUEST->get("client_id"); $redirect_uri = $REQUEST->get("redirect_uri"); $client_doc = $collection->findOne(array("client_id" => $client_id, "redirect_uri" => array('$elemMatch' => array('$in' => array($redirect_uri))))); if ($REQUEST->get("response_type") != "code") { echo "The response_type must be set to 'code' for this OAuth system"; die; } if (is_null($client_doc)) { echo "An error occured, this client does not appear in the database, or the redirect URI does not match"; die; } if ($REQUEST->avail("state")) { $state = $REQUEST->get("state"); $location = "{$redirect_uri}?state={$state}&code="; } else { $location = "{$redirect_uri}?code="; } ?> <html> <head> <script> function Ajax(URL, data, callback){ var request = new XMLHttpRequest();
<?php /* Reformatted 12.11.2015 */ // Helpers and includes include_once '/var/www/html/Lux/Core/Helper.php'; // Create Database Connection $DB = new Db("Inventory"); $OUTPUT = new Output(); // Get Request Data $REQUEST = new Request(); // User needs to be logged in for access $RULES = new Rules(1, "cart"); // Select Collection from Connection $collectionName = Helper::getCollectionName($REQUEST, "Cart"); $collection = $DB->selectCollection($collectionName); // Format Query $query = array("user_id" => $RULES->getId()); // Used for anayltics $LOG = new Logging("OAuth.query"); $LOG->log($RULES->getId(), 72, $query, 100, "OAuth Providers Queried"); // Format Limits (Skip, Limit) $options = Helper::formatLimits($REQUEST); // Find Documents $documents = $collection->find($query, $options); // Output $OUTPUT->success(0, $documents); ?>
<?php // Helper functions and includs include_once '/var/www/html/Lux/Core/Helper.php'; $db = new Db("Inventory"); $OUTPUT = new Output(); $REQUEST = new Request(); $collection = $db->selectCollection("Cart"); $RULES = new Rules(1, "cart"); $REQUEST = new Request(); // get the asset, push it into the cart that is selected $collectionName = $REQUEST->get("collection", "Standard"); $cartName = $REQUEST->get("wishlist", "Default"); $document = $collection->findAndModify(array("user_id" => $RULES->getId()), array('$push' => array("wishlist." . $cartName => MongoDBRef::create($collectionName, $REQUEST->get("id"), "Assets")))); // Used for analytics $LOG = new Logging("Cart.order"); $LOG->log($RULES->getId(), 43, $REQUEST->get("id"), 100, "User Wished for item"); $OUTPUT->success(0, $document, null);
<?php include_once '/var/www/html/Lux/Core/Helper.php'; $DB = new Db("System"); $collection = $DB->selectCollection("Accounts"); $OUTPUT = new Output(); $REQUEST = new Request(); $db2 = new Db("Auth"); $OUTPUT = new Output(); $clients = $db2->selectCollection("Clients"); $client_id = $REQUEST->get("client_id"); $redirect_uri = $REQUEST->get("redirect_uri"); $client_secret = $REQUEST->get("client_secret"); $client_doc = $clients->findOne(array("client_id" => $client_id, "client_secret" => $client_secret, "redirect_uri" => array('$elemMatch' => array('$in' => array($redirect_uri))))); // get Password and Username from $REQUEST // /client_id /redirect_uri /client_secret /code /grant_type:authorization_code if ($REQUEST->get("grant_type") != "authorization_code") { $OUTPUT->error(1, "Grant_type must equal authorization code in this context"); } // find where there is a match $uDoc = $collection->findOne(array('system_info.OAuth_clients' => array('$elemMatch' => array('$in' => array(array("client_id" => $REQUEST->get("client_id"), "code" => $REQUEST->get("code"))))))); if (is_null($uDoc)) { $OUTPUT->error(1, "This code is either invalid or has already been redeemed"); } $lAT = bin2hex(openssl_random_pseudo_bytes(16)); $document = $collection->update(array('_id' => $uDoc["_id"]), array('$pull' => array('system_info.OAuth_clients' => array("client_id" => $REQUEST->get("client_id"), "code" => $REQUEST->get("code")))), array('multiple' => false, 'upsert' => true)); $document = $collection->update(array('_id' => $uDoc["_id"]), array('$addToSet' => array('system_info.OAuth_clients' => array("client_id" => $REQUEST->get("client_id"), "access_token" => $lAT))), array('multiple' => false, 'upsert' => true)); $OUTPUT->success(1, array("access_token" => $lAT)); die;
<?php include_once '/var/www/html/Lux/Core/Helper.php'; $DB = new Db("System"); $collection = $DB->selectCollection("Users"); $RULES = new Rules(1); $OUTPUT = new Output(); $REQUEST = new Request(); $document = $collection->findOne(array('$or' => array(array("system_info.user" => $REQUEST->get("user")), array("system_info.email" => $REQUEST->get("user"))))); if (!is_null($document) && isset($document["system_info"]["email"])) { $password = bin2hex(openssl_random_pseudo_bytes(8)); $hash = password_hash($password, PASSWORD_DEFAULT); $collection->update($document["_id"], array('$set' => array("system_info.hash" => $hash))); $to = $document["system_info"]["email"]; $subject = 'Email Verification'; $message = "A password reset link was sent to your email address. Your new password is {$password}"; $headers = 'From: no-reply@' . $_SERVER["HTTP_HOST"] . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); $OUTPUT->success(0, "Password Reset Email Sent"); } else { $OUTPUT->error(1, "Username/Email was not found in the system"); }
<?php // Helper and includes include_once '/var/www/html/Lux/Core/Helper.php'; $db = new Db("System"); $OUTPUT = new Output(); $collection = $db->selectCollection("Contact"); $REQUEST = new Request(); $query = array("email_id" => $REQUEST->get("email_id")); $document = $collection->findOne($query); // Send mail $to = trim(implode(" , ", $document["address"]), ' , '); $subject = $REQUEST->get("subject"); $message = $REQUEST->get("body"); $sender = $REQUEST->avail("sender") ? $REQUEST->get("sender") : ($document["sender"] ? $document["sender"] : "noreply@" . $_SERVER["HTTP_HOST"]); $headers = 'From: ' . $sender . "\r\n" . 'Reply-To: ' . $sender . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $result = mail($to, $subject, $message, $headers); if ($result == 1) { $OUTPUT->success(0, null, null); } else { $OUTPUT->error(2, "An Error occured in the mail function"); } ?>
<?php // Helper and includes include_once '/var/www/html/Lux/Core/Helper.php'; $DB = new Db("Inventory"); $OUTPUT = new Output(); $collection = $DB->selectCollection("Cart"); // User needs to be logged in to access their cart $RULES = new Rules(1, "cart"); $REQUEST = new Request(); $query = array("status.finalized" => false); $options = Helper::formatLimits($REQUEST); $document = $collection->find($query, $options); $OUTPUT->success(0, $document); ?>
<?php include_once '/var/www/html/Lux/Core/Helper.php'; $DB = new Db("SocialNetwork"); $OUTPUT = new Output(); $collection = $DB->selectCollection("Connections"); $Users = $DB->selectCollection("Users"); $Groups = $DB->selectCollection("Groups"); $REQUEST = new Request(); $RULES = new Rules(1, "social"); // find in user or find in group $query = $REQUEST->get("id"); $user = $Users->find($query); if (is_null($user)) { $user = $Groups->find($query); if (is_null($user)) { $OUTPUT->error(1, "Could not find the specified User or Group"); } else { // create dbRef $user2 = MongoDBRef::create("Groups", $query, "SocialNetwork"); } } else { $user2 = MongoDBRef::create("Users", $query, "SocialNetwork"); } $user1 = MongoDBRef::create("Users", $RULES->getId(), "SocialNetwork"); // format update $permitted = array("description", "connection_type"); $update = Helper::updatePermitted($REQUEST, $permitted); $update = Helper::subDocUpdate($update, "information"); $subQuery1 = array('requestor' => $user1, 'requestee' => $user2); $subQuery2 = array('requestor' => $user2, 'requestee' => $user1);
<?php include_once '/var/www/html/Lux/Core/Helper.php'; $DB = new Db("SocialNetwork"); $OUTPUT = new Output(); $collection = $DB->selectCollection("Connections"); $REQUEST = new Request(); $RULES = new Rules(1, "social"); if ($REQUEST->avail("id")) { $id = $REQUEST->get("id"); } else { $id = $RULES->getId(); } $query = array('$or' => array(array('requestor' => $id), array('requestee' => $id)), 'status.blocked' => 0, '$or' => array(array('status.pending' => 1), array('status.active' => 1))); $options = Helper::formatLimits($REQUEST); $document = $collection->find($query, $options); $OUTPUT->success(0, $document); ?>
<?php include_once '/var/www/html/Lux/Core/Helper.php'; $db = new Db("Inventory"); $OUTPUT = new Output(); $REQUEST = new Request(); $orders = $db->selectCollection("Orders"); $RULES = new Rules(1, "orders"); $REQUEST = new Request(); // get the asset, push it into the cart that is selected $document = $orders->findAndModify(Helper::formatQuery($REQUEST), array("shipper_id" => $RULES->getId(), "status.shipped" => true, "status.recieved" => true, "status.paid" => true, "status.modified" => true, "status.processed" => true, "status.finalized" => true)); $OUTPUT->success(0, $document, null);
public function save($access_token, $sId) { $OUTPUT = new Output(); $SESSION = new Session($sId); $DB1 = new Db("System"); $System_users = $DB1->selectCollection("Users"); $DB2 = new Db("SocialNetwork"); $SN_users = $DB2->selectCollection("Users"); $provider = $SESSION->get("provider"); $base = $provider["base3"]; $params = array("access_token" => $access_token); $meDoc = Helper::curl($base, $params, $access_token); if (isset($meDoc["id"])) { $id = $meDoc["id"]; } else { if (isset($meDoc["_id"])) { $id = $meDoc["_id"]; } } $provider_name = $provider["provider_name"]; $eAT = $SESSION->get("access_token"); if (!isset($eAT) || is_null($eAT)) { // generate Lux access_token // save into Session $lAT = bin2hex(openssl_random_pseudo_bytes(16)); $SESSION->set("access_token", $lAT); } // find One where either access_token = access_token or providers.provider_name.id = $meDoc["id"] // update providers.provider_name.access_token = $access_token $System_users->update(array('$or' => array(array("providers.{$provider_name}.id" => $id), array("system_info.access_token" => $SESSION->get("access_token")))), array('$set' => array("system_info.access_token" => $SESSION->get("access_token"), "providers.{$provider_name}.id" => $id, "providers.{$provider_name}.access_token" => $access_token)), array("upsert" => true, "multiple" => false)); $AuthDoc = $System_users->findOne(array("system_info.access_token" => $SESSION->get("access_token"))); $SNDoc1 = array("providers.{$provider_name}" => $meDoc); if (!isset($AuthDoc["SN_id"]) || is_null($AuthDoc["SN_id"])) { // no SN_id exists $SNDoc2 = array("providers" => array($provider_name => $meDoc)); $SN_users->insert($SNDoc2); // if no SN_id exists, create a new one $System_users->update(array("system_info.access_token" => $SESSION->get("access_token")), array('$set' => array('SN_id' => $SNDoc2["_id"])), array("multiple" => false, "upsert" => false)); } else { // update providers.provider_name = meDoc where _id = SN_id $SN_users->update(array("SN_id" => $AuthDoc["SN_id"]), array('$set' => $SNDoc1), array("multiple" => false, "upsert" => true)); } }
<?php include_once '/var/www/html/Lux/Core/Helper.php'; $DB = new Db("SocialNetwork"); $OUTPUT = new Output(); $Users = $DB->selectCollection("Users"); $Groups = $DB->selectCollection("Groups"); $REQUEST = new Request(); $RULES = new Rules(0, "social"); // find in user or find in group // search by term: $query = array('$or' => array("username" => new MongoRegex("/" . $REQUEST->get("term") . "/i"), "name" => new MongoRegex("/" . $REQUEST->get("term") . "/i"), "stuff" => new MongoRegex("/" . $REQUEST->get("term") . "/i"), "things" => new MongoRegex("/" . $REQUEST->get("term") . "/i"), "text" => new MongoRegex("/" . $REQUEST->get("term") . "/i"), "spetjiomg" => new MongoRegex("/" . $REQUEST->get("term") . "/i"), "adasd" => new MongoRegex("/" . $REQUEST->get("term") . "/i"), "nasdafa" => new MongoRegex("/" . $REQUEST->get("term") . "/i"), "other" => new MongoRegex("/" . $REQUEST->get("term") . "/i"))); $options = Helper::formatLimits($REQUEST); $user = $Users->find($query, $options); $group = $Groups->find($query, $options); $document = array("users" => $user, "groups" => $groups); $OUTPUT->success(0, $document); ?>
<?php include_once '/var/www/html/Lux/Core/Helper.php'; $DB = new Db("SocialNetwork"); $OUTPUT = new Output(); $collection = $DB->selectCollection("Notifications"); $REQUEST = new Request(); $RULES = new Rules(1, "social"); $query = array("user_id" => $RULES->getId()); $update = array("status.seen" => 1); $options = Helper::formatLimits($REQUEST); $options["upsert"] = false; $document = $collection->findAndModify($query, $update, $options); $OUTPUT->success(0, $document); ?>
/** * Select Collection */ public function selectCollection($db_name, $collection_name) { $db = new Db((string) $db_name, $this); $collection = $db->selectCollection($collection_name); return $collection; }
<?php // Helper functions and includes include_once '/var/www/html/Lux/Core/Helper.php'; $db = new Db("Inventory"); $OUTPUT = new Output(); $REQUEST = new Request(); $cart = $db->selectCollection("Cart"); $orders = $db->selectCollection("Orders"); // Must be logged in to place an order $RULES = new Rules(1, "cart"); $REQUEST = new Request(); // get the asset, push it into the cart that is selected $collectionName = $REQUEST->get("collection", "Standard"); $cartName = $REQUEST->get("cart", "Default"); $old = $cart->findAndModify(array("user_id" => $RULES->getId()), array("cart." . $cartName => []), array('new' => false)); // Criteria for an order $document = $orders->insert(array("user_id" => $RULES->getId(), "items" => $old["cart"][$cartName], "status.shipped" => false, "status.recieved" => false, "status.paid" => false, "status.modified" => false, "status.processed" => false, "status.finalized" => false)); // Used for anayltics $LOG = new Logging("Cart.order"); $LOG->log($RULES->getId(), 42, 2, 100, "User Ordered item"); $OUTPUT->success(0, $document, null);
<?php include_once '/var/www/html/Lux/Core/Helper.php'; $DB = new Db("SocialNetwork"); $OUTPUT = new Output(); $collection = $DB->selectCollection("Posts"); $REQUEST = new Request(); $RULES = new Rules(1, "social"); if ($REQUEST->avail("id")) { $id = $REQUEST->get("id"); } else { $id = $RULES->getId(); } $query = array("owner" => $id); $options = Helper::formatLimits($REQUEST); $document = $collection->find($query, $options); $OUTPUT->success(0, $document); ?>
<?php /* Reformatted 12.11.2015 */ // helpers nad includes include_once '/var/www/html/Lux/Core/Helper.php'; // Create Database Connection $db = new Db("SocialNetwork"); $OUTPUT = new Output(); // Get Request Data $REQUEST = new Request(); // No privleges Required $RULES = new Rules(0, "profile"); // Selects collection from Database Connection $collectionName = Helper::getCollectionName($REQUEST, "Groups"); $collection = $db->selectCollection($collectionName); // Format Query $query = Helper::formatQuery($REQUEST, "group_id"); // Used for anayltics $LOG = new Logging("Groups.query"); $LOG->log($RULES->getId(), 72, $query, 100, "Groups Queried"); // Find Documents in Collection $documents = $collection->find($query); // Output $OUTPUT->success(1, $documents); ?>
$postdata = http_build_query(array()); } // build the HTTP request $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata)); // make the HTTP into a "context" $context = stream_context_create($opts); // make the actual request in context $result = file_get_contents($document, false, $context); $OUTPUT->success(1, null, $results); } else { $OUTPUT->error(2, "Service Could not be found"); } $LF = new LuxFunctions(); $OUTPUT = new Output(); $DB = new Db("System"); $providers = $DB->selectCollection("providers"); $users = $DB->selectCollection("Users"); $provider_name = $LF->fetch_avail("provider"); $user = $users->findOne(array("lux_info.access_token" => $LF->fetch_avail("access_token"))); $access_token = $user["providers"][$provider_name]["access_token"]; $provider = $providers->findOne(array("provider_name" => $provider_name)); if (!$LF->is_avail("base")) { $base = $provider["base4"]; } else { $base = $LF->fetch_avail("base"); } $params = $LF->getParameters(); unset($params["base"]); unset($params["provider"]); unset($params["path"]); $params["access_token"] = $access_token;