implement auto-login on login page

This commit is contained in:
kittentm 2026-02-06 23:01:30 +01:00
commit 343de86101
5 changed files with 45 additions and 41 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
*.pem *.pem
server.py server.py
config.js

View file

@ -1,4 +1,4 @@
// note: this is just the default config // note: this is just the default config
const 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
View file

@ -0,0 +1,3 @@
const CONFIG = {
API_BASE_URL: "backendurl"
};

View file

@ -59,7 +59,7 @@
</label> </label>
</div> </div>
<div class="hb-checkbox"> <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> <label for="remember_box">Remember Me</label>
</div> </div>
<input class="hb-btn hb-is-decide" id="btn_text" type="submit" value="Sign In"/> <input class="hb-btn hb-is-decide" id="btn_text" type="submit" value="Sign In"/>
@ -71,39 +71,13 @@
<footer class="hb-footer"> <footer class="hb-footer">
<div class="hb-footer-wrapper"> <div class="hb-footer-wrapper">
<div class="hb-footer-link"> <div class="hb-footer-link">
<a class="hb-icon-external" href="../../../site_policy/">Terms &amp; Privacy Policy</a> <a class="hb-icon-external" href="/site_policy/">Terms &amp; Privacy Policy</a>
<a class="hb-icon-external" href="https://git.crafterpika.cc/kittentm/splatnet/issues">Contact/Help</a> <a class="hb-icon-external" href="https://git.crafterpika.cc/kittentm/splatnet/issues">Contact/Help</a>
</div> </div>
<p class="hb-footer-copyright">©Nintendo</p> <p class="hb-footer-copyright">©Nintendo</p>
</div> </div>
</footer> </footer>
</div> </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> <script type="text/javascript">_satellite.pageBottom();</script>
</body> </body>
</html> </html>

View file

@ -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 urlParams = new URLSearchParams(window.location.search);
const apiBase = CONFIG.API_BASE_URL;
if (urlParams.has('error')) { $("#frontend_origin").val(window.location.origin);
const errorContainer = document.getElementById("auth-error");
if (errorContainer) { form.attr("action", apiBase + "/api/v2/sso/spfn/generate_token");
errorContainer.textContent = "Invalid SFID or Password";
errorContainer.style.display = "block"; // Show the red text async function checkExistingSession() {
} try {
const response = await fetch(apiBase + "/api/v1/users/me", {
//user convenience.....grrr method: 'GET',
const userField = document.getElementsByName("username")[0]; credentials: 'include'
if (userField && urlParams.has('username')) { });
userField.value = urlParams.get('username'); if (response.ok) {
window.location.href = "/friend_list/";
}
} catch (err) {
console.log("auth check failed");
} }
} }
}
if (!urlParams.has('error')) {
checkExistingSession();
}
if (urlParams.has('error')) {
errorContainer.text("Invalid SFID or Password").show();
if (urlParams.has('username')) {
$("input[name='username']").val(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);
});
});