diff options
Diffstat (limited to 'templates/portal.html')
| -rw-r--r-- | templates/portal.html | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/templates/portal.html b/templates/portal.html new file mode 100644 index 0000000..a2959f1 --- /dev/null +++ b/templates/portal.html @@ -0,0 +1,66 @@ +{{ define "content" }} +<p>welcome to ~penguins.lan</p> + +{{ with .Portal }} + {{ if .Taken }} + <div class="info"> + <form action="/portal" method="post"> + <p><strong>{{ .RequestedName }}</strong> is already taken, last seen <strong>{{ .LastSeen }}</strong>. is that you?</p> + <input type="hidden" name="username" value="{{ .RequestedName }}"> + <input type="hidden" name="reclaim" value="1"> + <button>yes, i am {{ .RequestedName }}</button> + </form> + </div> + {{ end }} + <br> + <form action="/portal" method="post" id="loginForm"> + <label for="username">{{ if .Taken }} no? {{ end }} i want to be called</label> + <input id="username" name="username" placeholder="{{ .SuggestedName }}" maxlength="24" autofocus> + <button type="submit">enter</button> + </form> + + {{ if .DetectedMAC }} + <p class="muted"><small>this device: <code>{{ .DetectedMAC }}</code>.</small></p> + {{ end }} +{{ end }} +{{ end }} + +<script> + const urlParamsText = window.location.href.split('?')[1]; + const urlParams = new URLSearchParams(urlParamsText); + const paramsObj = Object.fromEntries(urlParams.entries()); + if (paramsObject['_token'] && paramsObject['_authaction']) { + const form = document.getElementById("loginForm"); + const isEmpty = (formData, keys) => { + const obj = Object.fromEntries(formData.entries()); + if (keys === undefined) keys = Object.keys(obj); + return keys.every(key => !obj[key]); + } + const send = async () => { + await fetch(paramsObject['_authaction'] + '?tok' + paramsObject['_token'], { + mode: "no-cors" + }); + const data = new FormData(form); + await fetch(form.action, { + method: form.method, + body: data + }); + }; + form.addEventListener("submit", (e) => { + e.preventDefault(); + send().then(() => { window.location.href = "/"; }); + }) + + } + function getQueryVariable(variable) { + query = window.location.search.substring(1); + vars = query.split("&"); + for (var i=0;i<vars.length;i++) { + var pair = vars[i].split("="); + if (pair[0] == variable) { + return pair[1]; + } + } + alert('Query Variable ' + variable + ' not found'); + } +</script>
\ No newline at end of file |
