blob: 8033413a90c0d1651f460eca40989353e21f447d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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;
}
|