Initial commit. Implemented OAuth, Linodes, volumes, and images
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of Linode Manager Classic.
|
||||
*
|
||||
* Linode Manager Classic is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Linode Manager Classic is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Linode Manager Classic. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { settings, elements, oauthPost, parseParams } from "/global.js";
|
||||
import { clientID } from "/clientID.js";
|
||||
|
||||
(function()
|
||||
{
|
||||
// Data recieved from API calls
|
||||
var data = {};
|
||||
|
||||
// Callback for token revoke
|
||||
var redirect = function(response)
|
||||
{
|
||||
localStorage.clear();
|
||||
location.href = "/";
|
||||
};
|
||||
|
||||
// Initial setup
|
||||
var setup = function()
|
||||
{
|
||||
// Parse URL parameters
|
||||
data.params = parseParams();
|
||||
|
||||
// Revoke only if we have an unexpired token
|
||||
if (localStorage.apiKey && localStorage.apiExpire) {
|
||||
var now = new Date();
|
||||
var expires = new Date(parseInt(localStorage.apiExpire));
|
||||
if (expires > now) {
|
||||
var req = new URLSearchParams();
|
||||
req.set("client_id", clientID);
|
||||
req.set("token", localStorage.apiKey);
|
||||
oauthPost("/revoke", req, redirect);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise clear everything and redirect to login
|
||||
localStorage.clear();
|
||||
location.href = "/";
|
||||
};
|
||||
|
||||
// Attach onload handler
|
||||
window.addEventListener("load", setup);
|
||||
})();
|
||||
Reference in New Issue
Block a user