protected function doCommit(BulkWrite $bulk, bool $doCommit) : bool { if ($doCommit !== false) { $return = Mongo::get()->executeBulkWrite($this->collection, $bulk); return count($return->getWriteErrors()) == 0; } return false; }
public function saveAll(array $docs) : bool { $bulk = new BulkWrite(['ordered' => true]); foreach ($docs as $doc) { $doc->save($bulk); } $return = Mongo::get()->executeBulkWrite($this->collection, $bulk); return count($return->getWriteErrors()) == 0; }
public function doGet($view, $params) { unset($params); $this->validate($view); $ownerDetails = $this->getOwnerDetails(); $id = $ownerDetails->getID(); $user = Mongo::get()->findDoc("users", ['id' => $id], null, true); $user->setAll(["id" => $id, "name" => $ownerDetails->getName(), "email" => $ownerDetails->getEmail(), "image" => $ownerDetails->getAvatar(), "oauth2" => "google"]); $user->save(); Session::getSession()->set("userID", $id); $view->redirect('/', 302); }
public function doGet($view, $params) { unset($params); $auth = Config::getInstance()->get("oauth2"); $eve = $auth['eve']; $sso = new CrestSSO($eve['client_id'], $eve['client_secret'], $eve['redirect_uris'][0], $eve['scopes'], '/'); $code = filter_input(INPUT_GET, 'code'); $state = filter_input(INPUT_GET, 'state'); $userInfo = $sso->handleCallback($code, $state, Session::getSession()); $charID = $userInfo['characterID']; $id = "auth:eve:" . $charID; $user = Mongo::get()->findDoc("users", ['id' => $id], null, true); $user->setAll(["id" => $id, "name" => $userInfo['characterName'], "email" => null, "image" => "https://imageserver.eveonline.com/Character/{$charID}_256.jpg", "oauth2" => "eve", "refresh_token" => $userInfo['refreshToken']]); $user->save(); Session::getSession()->set("userID", $id); $view->redirect('/', 302); }
public function doPost($render, $params) { $userID = strtolower(filter_input(INPUT_POST, 'userid')); $pass = filter_input(INPUT_POST, 'password'); $error = null; $message = null; $user = Mongo::get()->findDoc('users', ['id' => $userID]); $hash = $user !== null ? $user->get('password') : null; if ($hash != null && password_verify($pass, $hash)) { $message = "Successful login."; Session::getSession()->set("userID", $userID); $params['user_name'] = $userID; } else { $error = "No such credentials."; } $params['errorCode'] = $error === null ? 'Success' : 'Error'; $params['errorMessage'] = $error === null ? $message : $error; $render->render('error', $params); }
public function doPost($render, $params) { $userID = strtolower(filter_input(INPUT_POST, 'userid')); $password = filter_input(INPUT_POST, 'password'); $error = null; $message = null; $user = Mongo::get()->findDoc("users", ["id" => $userID]); if ($user != null) { $error = 'User account already exists'; } else { $user = new MongoDoc("users"); $user->set("id", $userID); $user->set("name", $userID); $user->set("password", password_hash($password, PASSWORD_DEFAULT)); $user->save(); $message = "Account created!"; $params['user_name'] = $userID; Session::getSession()->set("userID", $userID); } $params['errorCode'] = $error === null ? 'Success' : 'Error'; $params['errorMessage'] = $error === null ? $message : $error; $render->render('error', $params); }