diff options
| author | Jake Mannens <jake@asger.xyz> | 2026-03-17 03:04:36 +1100 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2026-03-25 01:57:41 +1100 |
| commit | c751709b1b4fe6f16fd84647e8e071455e7b78d6 (patch) | |
| tree | 47734a083d888660606e6cf6cf158c93e69a9807 /Pages/Component/Titlebar.razor | |
v0.1av0.1a
Diffstat (limited to 'Pages/Component/Titlebar.razor')
| -rw-r--r-- | Pages/Component/Titlebar.razor | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/Pages/Component/Titlebar.razor b/Pages/Component/Titlebar.razor new file mode 100644 index 0000000..8033413 --- /dev/null +++ b/Pages/Component/Titlebar.razor @@ -0,0 +1,77 @@ +@inject IJSRuntime jsRuntime +@inject IUserService userService + +<script suppress-error="BL9992"> + async function login() { + var username = document.querySelector('input#username'); + var password = document.querySelector('input#password'); + + var formData = new FormData(); + formData.append('username', username.value); + formData.append('password', password.value); + + var resp = await fetch('/Login', { + method: 'POST', + body: formData + }); + + if(resp.ok) { + window.location.href = '/'; + } else if(resp.status == 403) { + var form = document.querySelector('form.login'); + form.classList.remove('bad-login'); + @* TODO: improve this hacky method of triggering reflow *@ + form.offsetWidth; + form.classList.add('bad-login'); + username.value = password.value = null; + username.focus(); + } else { + alert('Unknown error while attempting to login!'); + } + } + + async function logout() { + var resp = await fetch('/Logout', { method: 'POST' }); + if(resp.ok) { + window.location.href = '/Login'; + } else { + alert('Error logging out!'); + } + } +</script> + +<AuthorizeView> + <Authorized> + <div id="navbar"> + <a href="/">Home</a> + <a href="/TagDefinitions">Tags</a> + <a href="/Gallery?ingest=true">Ingest</a> + <a href="/Upload">Upload</a> + <a href="javascript:;" @onclick=@(() => aboutDialog.Show())>About</a> + + <p id="nsfw-label">NSFW</p> + <div id="nsfw-switch"> + <NsfwSwitch/> + </div> + <form action="/Gallery" method="get"> + <input type="text" name="q" placeholder="Search"/> + </form> + <a href="javascript:logout();">Logout</a> + </div> + <AboutDialog @ref=aboutDialog/> + </Authorized> + <NotAuthorized> + <div id="navbar"> + <h2>Login</h2> + <form class="login" action="javascript:login();"> + <input id="username" placeholder="Username" type="text"/> + <input id="password" placeholder="Password" type="password"/> + </form> + <a href="javascript:login();">Login</a> + </div> + </NotAuthorized> +</AuthorizeView> + +@code { + private AboutDialog aboutDialog; +} |
