From 6ad0364aceda2f18b70ef6606255f9d4776b0deb Mon Sep 17 00:00:00 2001 From: RossAscends <124905043+RossAscends@users.noreply.github.com> Date: Mon, 8 Apr 2024 03:07:53 +0900 Subject: [PATCH] add login --- public/scripts/userManagement.js | 43 ++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/public/scripts/userManagement.js b/public/scripts/userManagement.js index d54869628..eff0b02b3 100644 --- a/public/scripts/userManagement.js +++ b/public/scripts/userManagement.js @@ -30,6 +30,7 @@ async function registerNewUser() { handle: handle, name: name || 'Anonymous', password: password, + enabled: true }; try { @@ -57,6 +58,38 @@ async function registerNewUser() { } } +async function loginUser() { + const password = $("#userPassword").val(); + const handle = $('.userSelect.selected').data('foruser'); + const userInfo = { + handle: handle, + password: password, + }; + + try { + const response = await $.ajax({ + url: '/api/users/login', + type: 'POST', + contentType: 'application/json', + data: JSON.stringify(userInfo), + }); + + console.log(response); + if (response.handle) { + console.log('successfully logged in'); + alert(`logged in as ${handle}!`); + $('#loader').animate({ opacity: 0 }, 300, function () { + // Insert user handle/password verification code here + // .finally: + $('#loader').remove(); + }); + } + } catch (error) { + console.error('Error logging in:', error); + alert(error.responseText); + } +} + export async function populateUserList() { const userList = await getUserList(); @@ -66,6 +99,7 @@ export async function populateUserList() {
Register New SillyTavern User
Username:
+
Display Name:
Password:
Password confirm:
This will create a new subfolder in the /data/ directory. @@ -141,12 +175,5 @@ export async function populateUserList() { $("#registerNewUserBlock").hide() }) - $("#loginButton").off('click').on('click', function () { - $('#loader') - .animate({ opacity: 0 }, 300, function () { - // Insert user handle/password verification code here - //.finally: - $('#loader').remove(); - }); - }); + $("#loginButton").off('click').on('click', loginUser) }