Use a constant to mark requests coming from frontend

This commit is contained in:
merumelu
2016-10-14 21:04:54 +02:00
parent a0c26036fc
commit 4a2ad38cc4
7 changed files with 15 additions and 11 deletions

View File

@@ -14,6 +14,10 @@ if (PHP_SAPI == 'cli-server') {
require __DIR__ . '/../vendor/autoload.php';
if (!defined('FRONTEND')) {
define('FRONTEND', false);
}
// Instantiate the app
$settings = require __DIR__ . '/../src/settings.php';
$local_settings = require __DIR__ . '/../src/settings-local.php';

View File

@@ -1,4 +1,4 @@
<?php
$frontend = true;
define('FRONTEND', true);
include(__DIR__ . '/api/index.php');

View File

@@ -1,6 +1,6 @@
<?php
if(isset($frontend) && $frontend) {
if(FRONTEND) {
$container = $app->getContainer();
$app->get('/', function ($request, $response) {

View File

@@ -2,11 +2,11 @@
// Asset routes
// Searches through the list of assets
$app->get('/asset', function ($request, $response, $args) { global $frontend;
$app->get('/asset', function ($request, $response, $args) {
$params = $request->getQueryParams();
$category = '%';
if(isset($frontend) && $frontend) {
if(FRONTEND) {
$category_type = $this->constants['category_type']['any'];
} else {
$category_type = $this->constants['category_type']['addon'];
@@ -186,7 +186,7 @@ $get_asset = function ($request, $response, $args) {
};
// Binding to multiple routes
$app->get('/asset/{id:[0-9]+}', $get_asset);
if(isset($frontend) && $frontend) {
if(FRONTEND) {
$app->get('/asset/{id:[0-9]+}/edit', $get_asset);
}

View File

@@ -405,7 +405,7 @@ $get_edit = function ($request, $response, $args) {
// Binding to multiple routes
$app->get('/asset/edit/{id:[0-9]+}', $get_edit);
if(isset($frontend) && $frontend) {
if(FRONTEND) {
$app->get('/asset/edit/{id:[0-9]+}/edit', $get_edit);
}

View File

@@ -3,7 +3,7 @@
// Initializes the connection by sending all categories available
$app->get('/configure', function ($request, $response, $args) { global $frontend;
$app->get('/configure', function ($request, $response, $args) {
$params = $request->getQueryParams();
$category_type = $this->constants['category_type']['addon'];
@@ -29,7 +29,7 @@ $app->get('/configure', function ($request, $response, $args) { global $frontend
'categories' => $query->fetchAll(),
'token' => $token,
'login_url' => $_SERVER['HTTP_HOST'] .
(isset($frontend) && $frontend ? dirname($request->getUri()->getBasePath()) : $request->getUri()->getBasePath()) .
(FRONTEND ? dirname($request->getUri()->getBasePath()) : $request->getUri()->getBasePath()) .
'/login#' . urlencode($token),
// ^ TODO: Make those routes actually work
], 200);
@@ -138,7 +138,7 @@ $app->post('/login', function ($request, $response, $args) {
}
});
if(isset($frontend) && $frontend) { // Doesn't work for non-frontend, since we can't unissue tokens -- to logout from api/ just drop the token.
if(FRONTEND) { // Doesn't work for non-frontend, since we can't unissue tokens -- to logout from api/ just drop the token.
$app->get('/logout', function ($request, $response, $args) {
return $response->withJson([
'authenticated' => false,

View File

@@ -43,6 +43,6 @@ $get_feed = function ($request, $response, $args) {
// Binding to multiple routes
$app->post('/user/feed', $get_feed);
if(isset($frontend) && $frontend) {
$app->get('/user/feed', $get_feed);
if(FRONTEND) {
$app->get('/user/feed', $get_feed);
}