Remove api token
This commit is contained in:
parent
065f7f904f
commit
be99e947c0
10 changed files with 33 additions and 108 deletions
|
@ -18,8 +18,8 @@ $(function() {
|
|||
*/
|
||||
/** API */
|
||||
$.fn.api.settings.api = {
|
||||
'get wishlists' : '/?page=api&module=wishlists&api_token={apitoken}',
|
||||
'get wishlists by priority' : '/?page=api&module=wishlists&api_token={apitoken}&style={style}&wishlist_id={wishlistid}&priority={priority}',
|
||||
'get wishlists' : '/?page=api&module=wishlists',
|
||||
'get wishlists by priority' : '/?page=api&module=wishlists&style={style}&wishlist_id={wishlistid}&priority={priority}',
|
||||
'delete wishlist' : '/?page=api&module=wishlists',
|
||||
'update wish status' : '/?page=api&module=wishes',
|
||||
'delete wish' : '/?page=api&module=wishes',
|
||||
|
|
|
@ -4,7 +4,6 @@ $(function() {
|
|||
*/
|
||||
const params_statistics = new URLSearchParams(
|
||||
{
|
||||
'api_token' : wishthis.api.token,
|
||||
'module' : 'statistics',
|
||||
'page' : 'api',
|
||||
|
||||
|
@ -68,7 +67,6 @@ $(function() {
|
|||
*/
|
||||
const params_news = new URLSearchParams(
|
||||
{
|
||||
'api_token' : wishthis.api.token,
|
||||
'module' : 'blog',
|
||||
'page' : 'api',
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ window.addEventListener("load", (event) => {
|
|||
.then(canvas => {
|
||||
var data = new URLSearchParams();
|
||||
data.append('preview', canvas.toDataURL());
|
||||
data.append('api_token', wishthis.api.token);
|
||||
data.append('page', wishthis.$_GET.page);
|
||||
|
||||
/** Save page preview */
|
||||
|
|
|
@ -17,11 +17,6 @@ global $options;
|
|||
wishthis.locale = '<?= str_replace('_', '-', $this->language) ?>';
|
||||
wishthis.$_GET = JSON.parse('<?= isset($_GET) ? json_encode($_GET) : json_encode(array()) ?>');
|
||||
|
||||
/** API */
|
||||
wishthis.api = {
|
||||
'token' : "<?= $options->getOption('api_token'); ?>",
|
||||
};
|
||||
|
||||
/** Wish */
|
||||
wishthis.wish = {
|
||||
'status' : {
|
||||
|
|
|
@ -10,9 +10,6 @@ $(function () {
|
|||
})
|
||||
.api({
|
||||
'action' : 'get wishlists by priority',
|
||||
'urlData' : {
|
||||
'apitoken' : wishthis.api.token,
|
||||
},
|
||||
beforeSend : function (settings) {
|
||||
settings.urlData.style = $('input[name="style"]').val();
|
||||
settings.urlData.priority = $('.ui.dropdown.filter.priority').dropdown('get value');
|
||||
|
|
|
@ -16,9 +16,6 @@ $(function () {
|
|||
var wishlists = [];
|
||||
var wishlists_api = {
|
||||
'action' : 'get wishlists',
|
||||
'urlData' : {
|
||||
'apitoken' : wishthis.api.token,
|
||||
},
|
||||
onSuccess : function(response, dropdown_wishlists, xhr) {
|
||||
/** Save response for later use */
|
||||
wishlists = response.results;
|
||||
|
@ -68,7 +65,6 @@ $(function () {
|
|||
/** Get wishlist */
|
||||
const get_wishlist = new URLSearchParams(
|
||||
{
|
||||
'api_token' : wishthis.api.token,
|
||||
'module' : 'wishlists',
|
||||
'page' : 'api',
|
||||
|
||||
|
@ -99,7 +95,6 @@ $(function () {
|
|||
|
||||
const params_url = new URLSearchParams(
|
||||
{
|
||||
'api_token' : wishthis.api.token,
|
||||
'module' : 'url',
|
||||
'page' : 'api',
|
||||
|
||||
|
@ -125,7 +120,6 @@ $(function () {
|
|||
/*
|
||||
const get_wishes = new URLSearchParams(
|
||||
{
|
||||
'api_token' : wishthis.api.token,
|
||||
'module' : 'wishes',
|
||||
'page' : 'api',
|
||||
|
||||
|
@ -247,7 +241,6 @@ $(function () {
|
|||
|
||||
const params_cache = new URLSearchParams(
|
||||
{
|
||||
'api_token' : wishthis.api.token,
|
||||
'module' : 'wishes',
|
||||
'page' : 'api',
|
||||
|
||||
|
@ -313,7 +306,6 @@ $(function () {
|
|||
|
||||
var formRename = modalRename.find('.form.wishlist-rename');
|
||||
var formData = new URLSearchParams(new FormData(formRename[0]));
|
||||
formData.append('api_token', wishthis.api.token);
|
||||
formData.append('wishlist_id', wishthis.$_GET.id);
|
||||
|
||||
fetch('/?page=api&module=wishlists', {
|
||||
|
@ -397,8 +389,6 @@ $(function () {
|
|||
action: 'delete wishlist',
|
||||
method: 'DELETE',
|
||||
data: {
|
||||
'api_token' : wishthis.api.token,
|
||||
|
||||
'wishlistID' : wishlist_id
|
||||
},
|
||||
on: 'now',
|
||||
|
@ -442,8 +432,6 @@ $(function () {
|
|||
action : 'update wish status',
|
||||
method : 'PUT',
|
||||
data : {
|
||||
'api_token' : wishthis.api.token,
|
||||
|
||||
'wish_id' : card.attr('data-id'),
|
||||
'wish_status' : wishthis.strings.wish.status.fulfilled,
|
||||
},
|
||||
|
@ -485,7 +473,6 @@ $(function () {
|
|||
|
||||
var wishFormData = new URLSearchParams(
|
||||
{
|
||||
'api_token' : wishthis.api.token,
|
||||
'module' : 'wishes',
|
||||
'page' : 'api',
|
||||
|
||||
|
@ -574,9 +561,7 @@ $(function () {
|
|||
action : 'delete wish',
|
||||
method : 'DELETE',
|
||||
data : {
|
||||
'api_token' : wishthis.api.token,
|
||||
|
||||
'wish_id': card.attr('data-id'),
|
||||
'wish_id' : card.attr('data-id'),
|
||||
},
|
||||
on : 'now',
|
||||
onSuccess : function () {
|
||||
|
@ -678,7 +663,6 @@ $(function () {
|
|||
buttonCreate.addClass('loading');
|
||||
|
||||
var formData = new URLSearchParams(new FormData(formWishlistCreate[0]));
|
||||
formData.append('api_token', wishthis.api.token);
|
||||
|
||||
fetch('/?page=api&module=wishlists', {
|
||||
method : 'POST',
|
||||
|
@ -735,7 +719,6 @@ $(function () {
|
|||
if (wishURLCurrent) {
|
||||
const params_url = new URLSearchParams(
|
||||
{
|
||||
'api_token' : wishthis.api.token,
|
||||
'module' : 'wishes',
|
||||
'page' : 'api',
|
||||
|
||||
|
@ -775,8 +758,6 @@ $(function () {
|
|||
|
||||
const formData = new URLSearchParams(
|
||||
{
|
||||
'api_token' : wishthis.api.token,
|
||||
|
||||
'wish_url_current' : modalValidate.find('input.current').val(),
|
||||
'wish_url_proposed' : modalValidate.find('input.proposed').val(),
|
||||
}
|
||||
|
@ -805,7 +786,6 @@ $(function () {
|
|||
/** Save form edit fields */
|
||||
/** This code block is a duplicate, please refactor */
|
||||
var formData = new URLSearchParams(new FormData(formAddOrEdit[0]));
|
||||
formData.append('api_token', wishthis.api.token);
|
||||
formData.append('wishlist_id', wishthis.$_GET.id);
|
||||
|
||||
fetch('/?page=api&module=wishes', {
|
||||
|
@ -838,7 +818,6 @@ $(function () {
|
|||
/** Save form edit fields */
|
||||
/** This code block is a duplicate, please refactor */
|
||||
var formData = new URLSearchParams(new FormData(formAddOrEdit[0]));
|
||||
formData.append('api_token', wishthis.api.token);
|
||||
formData.append('wishlist_id', wishthis.$_GET.id);
|
||||
|
||||
fetch('/?page=api&module=wishes', {
|
||||
|
|
|
@ -47,8 +47,6 @@ $(function() {
|
|||
action : 'update wish status',
|
||||
method : 'PUT',
|
||||
data : {
|
||||
'api_token' : wishthis.api.token,
|
||||
|
||||
'wish_id' : card.attr('data-id'),
|
||||
'wish_status' : wishthis.wish.status.temporary,
|
||||
},
|
||||
|
@ -68,8 +66,6 @@ $(function() {
|
|||
action : 'update wish status',
|
||||
method : 'PUT',
|
||||
data : {
|
||||
'api_token' : wishthis.api.token,
|
||||
|
||||
'wish_id' : card.attr('data-id'),
|
||||
'wish_status' : wishthis.wish.status.unavailable,
|
||||
},
|
||||
|
@ -90,8 +86,6 @@ $(function() {
|
|||
|
||||
var formData = new URLSearchParams(
|
||||
{
|
||||
'api_token' : wishthis.api.token,
|
||||
|
||||
'wishlist' : $('[data-wishlist]').attr('data-wishlist'),
|
||||
}
|
||||
);
|
||||
|
@ -121,7 +115,6 @@ $(function() {
|
|||
/** Determine if list is saved */
|
||||
const params_ws_saved = new URLSearchParams(
|
||||
{
|
||||
'api_token' : wishthis.api.token,
|
||||
'module' : 'wishlists-saved',
|
||||
'page' : 'api',
|
||||
}
|
||||
|
@ -168,8 +161,6 @@ $(function() {
|
|||
|
||||
var formData = new URLSearchParams(
|
||||
{
|
||||
'api_token' : wishthis.api.token,
|
||||
|
||||
'locale' : wishlist_locale,
|
||||
'wishlist-id' : wishlist_id,
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@ class API
|
|||
private string $module_path;
|
||||
private array $input;
|
||||
|
||||
public string $token;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
global $options;
|
||||
|
@ -27,19 +25,11 @@ class API
|
|||
|
||||
$this->module = $this->input['module'] ?? '';
|
||||
$this->module_path = ROOT . '/src/api/' . $this->module . '.php';
|
||||
$this->token = $options->getOption('api_token');
|
||||
|
||||
/** For installer */
|
||||
if (empty($this->token)) {
|
||||
$this->token = sha1(ROOT);
|
||||
}
|
||||
}
|
||||
|
||||
public function do()
|
||||
{
|
||||
if (file_exists($this->module_path)) {
|
||||
if (!empty(trim($this->input['api_token']))) {
|
||||
if ($this->input['api_token'] === $this->token) {
|
||||
ob_start();
|
||||
|
||||
$response = array();
|
||||
|
@ -50,20 +40,6 @@ class API
|
|||
|
||||
header('Content-type: application/json; charset=utf-8');
|
||||
echo json_encode($response);
|
||||
} else {
|
||||
http_response_code(403);
|
||||
?>
|
||||
<h1>Forbidden</h1>
|
||||
<p>The specified API token "<?= $this->input['api_token'] ?>" is invalid.</p>
|
||||
<?php
|
||||
}
|
||||
} else {
|
||||
http_response_code(403);
|
||||
?>
|
||||
<h1>Forbidden</h1>
|
||||
<p>Please specify an API token.</p>
|
||||
<?php
|
||||
}
|
||||
} else {
|
||||
http_response_code(404);
|
||||
?>
|
||||
|
|
|
@ -43,7 +43,6 @@ switch ($step) {
|
|||
|
||||
<form class="ui form" action="<?= Page::PAGE_INSTALL ?>" method="POST">
|
||||
<input type="hidden" name="step" value="<?= $step + 1; ?>" />
|
||||
<input type="hidden" name="api_token" value="<?= sha1(ROOT) ?>">
|
||||
|
||||
<div class="ui error message"></div>
|
||||
|
||||
|
@ -251,8 +250,7 @@ switch ($step) {
|
|||
`options` (`key`, `value`)
|
||||
VALUES
|
||||
("isInstalled", true),
|
||||
("version", "' . VERSION . '"),
|
||||
("api_token", UUID())
|
||||
("version", "' . VERSION . '")
|
||||
;'
|
||||
);
|
||||
|
||||
|
|
|
@ -1,11 +1,3 @@
|
|||
/**
|
||||
* Options
|
||||
*/
|
||||
INSERT INTO
|
||||
`options` (`key`, `value`)
|
||||
VALUES
|
||||
('api_token', UUID());
|
||||
|
||||
/**
|
||||
* Sessions
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue