summaryrefslogtreecommitdiff
path: root/src/web/_views/auth/main.php
blob: 96047707039eb96db838fd462d42e2d975a7f30c (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
78
79
80
81
82
83
84
85
86
87
<?php /* Copyright (c) 2024 Freya Murphy */ ?>
<?php /* vi: syntax=php */ ?>
<main id="main">
	<div class="branding col">
		<h1>xssbook</h1>
		<span><?=ucfirst(lang('login_branding'))?></span>
	</div>
	<div class="form card col">
		<form id="action-login" class="col" action="">
			<div class="form-input mb">
				<input
					type="text"
					name="username"
					id="login-username"
					placeholder=" "
					autofocus="true"
				>
				<label for="username">
					<?=ucfirst(lang('ph_username'))?>
				</label>
			</div>
			<div class="form-input mb">
				<input
					type="password"
					name="password"
					id="login-password"
					placeholder=" "
				>
				<label for="password">
					<?=ucfirst(lang('ph_password'))?>
				</label>
			</div>
			<?=ilang('action_login',
				class: 'btn btn-primary btn-alt grow',
				type: 'button',
				attrs: array('type' => 'submit')
			)?>
			<?/*=ilang('action_forgot_passwd',
				class: 'btn btn-blend btn-primary grow mt'
			)*/?>
		</form>
		<hr>
		<?=ilang('action_create_account',
			id: 'action-register',
			class: 'btn btn-success btn-alt grow',
			type: 'button',
			attrs: array('type' => 'submit')
		)?>
	</div>
	<script>

		const onLogin = function(data) {
			let jwt = data.token;

			$.ajax({
				url: '/auth/update',
				method: 'POST',
				data: JSON.stringify({
					key: 'jwt',
					value: jwt
				}),
				success: function (_) {
					window.location = '/home';
				}
			})
		};

		$('#action-login').on('submit', function(e) {
			e.preventDefault();
			let username = $('#login-username').val();
			let password = $('#login-password').val();

			$.ajax({
				url: '/api/rpc/login',
				method: 'POST',
				data: JSON.stringify({ username, password }),
				success: onLogin
			});
		});

		$('#action-register').on('click', function() {
			$.get( "/_modal/register", function (data) {
				$(document.body).append(data);
			});
		})
	</script>
</main>