implement auto-login on login page
This commit is contained in:
parent
487478649b
commit
343de86101
5 changed files with 45 additions and 41 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
|||
*.pem
|
||||
server.py
|
||||
config.js
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// note: this is just the default config
|
||||
const CONFIG = {
|
||||
API_BASE_URL: "http://127.0.0.1:5000"
|
||||
API_BASE_URL: "http://192.168.1.177:5000"
|
||||
};
|
||||
3
config_example.js
Normal file
3
config_example.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
const CONFIG = {
|
||||
API_BASE_URL: "backendurl"
|
||||
};
|
||||
|
|
@ -59,7 +59,7 @@
|
|||
</label>
|
||||
</div>
|
||||
<div class="hb-checkbox">
|
||||
<input id="remember_box" name="rememberMe" type="checkbox"/>
|
||||
<input id="remember_box" name="rememberMe" type="checkbox" value="true"/>
|
||||
<label for="remember_box">Remember Me</label>
|
||||
</div>
|
||||
<input class="hb-btn hb-is-decide" id="btn_text" type="submit" value="Sign In"/>
|
||||
|
|
@ -71,39 +71,13 @@
|
|||
<footer class="hb-footer">
|
||||
<div class="hb-footer-wrapper">
|
||||
<div class="hb-footer-link">
|
||||
<a class="hb-icon-external" href="../../../site_policy/">Terms & Privacy Policy</a>
|
||||
<a class="hb-icon-external" href="/site_policy/">Terms & Privacy Policy</a>
|
||||
<a class="hb-icon-external" href="https://git.crafterpika.cc/kittentm/splatnet/issues">Contact/Help</a>
|
||||
</div>
|
||||
<p class="hb-footer-copyright">©Nintendo</p>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
var form = $("#auth-form");
|
||||
//hotfix cuz fastapi is strict
|
||||
$("#frontend_origin").val(window.location.origin);
|
||||
var path = form.attr("action");
|
||||
form.attr("action", CONFIG.API_BASE_URL + path);
|
||||
$("form").submit(function() {
|
||||
var self = this;
|
||||
$(":submit", self).prop("disabled", true);
|
||||
setTimeout(function() {
|
||||
$(":submit", self).prop("disabled", false);
|
||||
}, 10000);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
var globalLocale = 'en-US';
|
||||
$(document).ready(function () {
|
||||
$('#language-select').val(globalLocale);
|
||||
$('#language-select').change(function () {
|
||||
var selectedLang = $(this).val();
|
||||
redirect(location.href, {lang: selectedLang});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script type="text/javascript">_satellite.pageBottom();</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,17 +1,43 @@
|
|||
window.onload = function() {
|
||||
$(document).ready(function () {
|
||||
const form = $("#auth-form");
|
||||
const errorContainer = $("#auth-error");
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const apiBase = CONFIG.API_BASE_URL;
|
||||
|
||||
$("#frontend_origin").val(window.location.origin);
|
||||
|
||||
form.attr("action", apiBase + "/api/v2/sso/spfn/generate_token");
|
||||
|
||||
async function checkExistingSession() {
|
||||
try {
|
||||
const response = await fetch(apiBase + "/api/v1/users/me", {
|
||||
method: 'GET',
|
||||
credentials: 'include'
|
||||
});
|
||||
if (response.ok) {
|
||||
window.location.href = "/friend_list/";
|
||||
}
|
||||
} catch (err) {
|
||||
console.log("auth check failed");
|
||||
}
|
||||
}
|
||||
|
||||
if (!urlParams.has('error')) {
|
||||
checkExistingSession();
|
||||
}
|
||||
|
||||
if (urlParams.has('error')) {
|
||||
const errorContainer = document.getElementById("auth-error");
|
||||
if (errorContainer) {
|
||||
errorContainer.textContent = "Invalid SFID or Password";
|
||||
errorContainer.style.display = "block"; // Show the red text
|
||||
errorContainer.text("Invalid SFID or Password").show();
|
||||
if (urlParams.has('username')) {
|
||||
$("input[name='username']").val(urlParams.get('username'));
|
||||
}
|
||||
}
|
||||
|
||||
//user convenience.....grrr
|
||||
const userField = document.getElementsByName("username")[0];
|
||||
if (userField && urlParams.has('username')) {
|
||||
userField.value = urlParams.get('username');
|
||||
}
|
||||
}
|
||||
}
|
||||
form.submit(function() {
|
||||
const submitBtn = $(":submit", this);
|
||||
submitBtn.prop("disabled", true).val("Signing In...");
|
||||
setTimeout(function() {
|
||||
submitBtn.prop("disabled", false).val("Sign In");
|
||||
}, 10000);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue