Start making login functional
This commit is contained in:
parent
27887c2a72
commit
f257c5de22
90
src/main.js
90
src/main.js
@ -45,6 +45,40 @@ function createMainWindow() {
|
||||
});
|
||||
}
|
||||
|
||||
function fetchPlutoniumManifest() {
|
||||
return new Promise(function (resolve, reject) {
|
||||
let request = https.request("https://cdn.plutonium.pw/updater/prod/info.json", {
|
||||
"method": "GET"
|
||||
}, function (response) {
|
||||
if (response.statusCode !== 200) {
|
||||
return reject(new Error("Failed to fetch the Plutonium launcher manifest."));
|
||||
}
|
||||
|
||||
response.setEncoding("utf-8");
|
||||
|
||||
let body = "";
|
||||
response.on("data", function (chunk) {
|
||||
body += chunk;
|
||||
});
|
||||
response.on("end", function () {
|
||||
try {
|
||||
let data = JSON.parse(body);
|
||||
|
||||
resolve(data);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
request.on("error", function (error) {
|
||||
reject(error);
|
||||
});
|
||||
|
||||
request.end();
|
||||
});
|
||||
}
|
||||
|
||||
electron.app.once("ready", function () {
|
||||
createMainWindow();
|
||||
});
|
||||
@ -52,3 +86,59 @@ electron.app.once("ready", function () {
|
||||
electron.app.on("window-all-closed", function () {
|
||||
electron.app.quit();
|
||||
});
|
||||
|
||||
electron.ipcMain.handle("login", function (event, username, password) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
let payload = JSON.stringify({
|
||||
"username": username,
|
||||
"password": password
|
||||
});
|
||||
|
||||
let request = https.request("https://nix.plutonium.pw/api/auth/login", {
|
||||
"method": "POST",
|
||||
"headers": {
|
||||
"Content-Type": "application/json",
|
||||
"Content-Length": payload.length,
|
||||
"Authorization": "UserToken",
|
||||
"X-Plutonium-Revision": String(plutoniumManifest.revision),
|
||||
"User-Agent": "Nix/3.0"
|
||||
}
|
||||
}, function (response) {
|
||||
if (response.statusCode !== 200) {
|
||||
return resolve({
|
||||
"status": "unauthenticated"
|
||||
});
|
||||
}
|
||||
|
||||
response.setEncoding("utf-8");
|
||||
|
||||
let body = "";
|
||||
response.on("data", function (chunk) {
|
||||
body += chunk;
|
||||
});
|
||||
response.on("end", function () {
|
||||
try {
|
||||
let data = JSON.parse(body);
|
||||
|
||||
if (!("token" in data)) {
|
||||
reject(new Error("Login seems to be successful but no token was returned."));
|
||||
}
|
||||
|
||||
resolve({
|
||||
"status": "authenticated",
|
||||
...data
|
||||
});
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
request.on("error", function (error) {
|
||||
reject(error);
|
||||
});
|
||||
|
||||
request.write(payload);
|
||||
request.end();
|
||||
});
|
||||
});
|
||||
|
@ -1,4 +1,12 @@
|
||||
:root {
|
||||
background-color: #181820;
|
||||
color: #F8F8FC;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body, main {
|
||||
margin: 0px;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
10
src/styles/login.css
Normal file
10
src/styles/login.css
Normal file
@ -0,0 +1,10 @@
|
||||
#login-container {
|
||||
width: 256px;
|
||||
height: 384px;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
#login-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
@ -4,12 +4,13 @@
|
||||
<meta charset="utf-8">
|
||||
<title>Open Plutonium Launcher</title>
|
||||
<link rel="stylesheet" href="../styles/common.css" />
|
||||
<link rel="stylesheet" href="../styles/login.css" />
|
||||
<script src="../scripts/login.js" charset="utf-8" type="text/javascript"></script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div>
|
||||
<form>
|
||||
<div id="login-container">
|
||||
<form id="login-form">
|
||||
<label for="username">Username :</label>
|
||||
<input type="text" name="username" id="username-field" placeholder="Your Plutonium username" minLength="2" maxLength="64">
|
||||
<label for="password">Password :</label>
|
||||
|
Loading…
Reference in New Issue
Block a user