88 lines
2.8 KiB
HTML
88 lines
2.8 KiB
HTML
<h1 class="title">Login</h1>
|
|
<div class="columns is-mobile">
|
|
<div class="column"></div>
|
|
<div class="column">
|
|
<form action="" class="form">
|
|
<div class="field">
|
|
<input type="text" class="input" id="user" placeholder="Username or E-mail">
|
|
</div>
|
|
<div class="field">
|
|
<input type="password" class="input" id="password" placeholder="Password">
|
|
</div>
|
|
<div class="field">
|
|
<label class="checkbox">
|
|
<input type="checkbox" id="keep">
|
|
Stay logged in
|
|
</label>
|
|
</div>
|
|
<div class="buttons">
|
|
<button type="submit" class="button" id="submit">Submit</button>
|
|
<button class="button is-danger" id="clear">Clear</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
if (settings.accessToken != "") {
|
|
notify("primary", "Attempting auto-login...");
|
|
api.validate(
|
|
settings.accessToken
|
|
).then((res) => {
|
|
if (res.status == 204) {
|
|
api.refresh(
|
|
settings.accessToken
|
|
).then((res) => {
|
|
api.accessToken = res.data.accessToken;
|
|
api.profile = res.data.selectedProfile;
|
|
|
|
settings.accessToken = res.data.accessToken;
|
|
save();
|
|
|
|
notify("success", "Logged in as " + res.data.selectedProfile.name);
|
|
load("/partials/profile.html");
|
|
})
|
|
} else {
|
|
notify("danger", "Login error: " + res.status);
|
|
}
|
|
}).catch((error) => {
|
|
notify("danger", "Login error: " + error.response.data.errorMessage);
|
|
});
|
|
}
|
|
|
|
$("input#user")[0].value = settings.user;
|
|
|
|
$("button#submit").on("click", (e) => {
|
|
e.preventDefault();
|
|
|
|
api.authenticate(
|
|
$("input#user")[0].value,
|
|
$("input#password")[0].value
|
|
).then((res) => {
|
|
api.accessToken = res.data.accessToken;
|
|
api.profile = res.data.selectedProfile;
|
|
|
|
if ($("input#keep")[0].checked) {
|
|
settings.user = $("input#user")[0].value;
|
|
settings.accessToken = res.data.accessToken;
|
|
save();
|
|
}
|
|
|
|
notify("success", "Logged in as " + res.data.selectedProfile.name);
|
|
load("/partials/profile.html");
|
|
}).catch((error) => {
|
|
notify("danger", "Login failed: " + error.response.data.errorMessage);
|
|
})
|
|
});
|
|
|
|
$("button#clear").on("click", (e) => {
|
|
e.preventDefault();
|
|
|
|
$("input#user")[0].value = "";
|
|
$("input#user")[0].value = "";
|
|
$("input#keep")[0].checked = false;
|
|
|
|
settings.user = "";
|
|
save();
|
|
});
|
|
</script> |