wip
This commit is contained in:
parent
515c748e14
commit
bd4a475923
23 changed files with 1217 additions and 192 deletions
|
|
@ -10,11 +10,9 @@
|
|||
if (navigator.serviceWorker)
|
||||
navigator.serviceWorker.register('/service_worker.js')
|
||||
</script>
|
||||
<!--
|
||||
<script type="importmap">
|
||||
{
|
||||
"imports": {
|
||||
/*
|
||||
"preact": "/js/{{ .VERSION }}/lib/preact/preact.mjs",
|
||||
"preact/hooks": "/js/{{ .VERSION }}/lib/preact/hooks.mjs",
|
||||
"preact/debug": "/js/{{ .VERSION }}/lib/preact/debug.mjs",
|
||||
|
|
@ -22,6 +20,9 @@
|
|||
"@preact/signals-core": "/js/{{ .VERSION }}/lib/signals/signals-core.mjs",
|
||||
"preact/signals": "/js/{{ .VERSION }}/lib/signals/signals.mjs",
|
||||
"htm": "/js/{{ .VERSION }}/lib/htm/htm.mjs",
|
||||
|
||||
"api": "/js/{{ .VERSION }}/api.mjs"
|
||||
{{/*
|
||||
"session": "/js/{{ .VERSION }}/session.mjs",
|
||||
"node": "/js/{{ .VERSION }}/node.mjs",
|
||||
"node_store": "/js/{{ .VERSION }}/node_store.mjs",
|
||||
|
|
@ -29,14 +30,13 @@
|
|||
"crypto": "/js/{{ .VERSION }}/crypto.mjs",
|
||||
"checklist": "/js/{{ .VERSION }}/checklist.mjs",
|
||||
"ws": "/_js/{{ .VERSION }}/websocket.mjs"
|
||||
*/
|
||||
*/}}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript" src="/js/{{ .VERSION }}/lib/sjcl.js"></script>
|
||||
<script type="text/javascript" src="/js/{{ .VERSION }}/lib/node_modules/marked/marked.min.js"></script>
|
||||
<script type="text/javascript" src="/js/{{ .VERSION }}/lib/fullcalendar.min.js"></script>
|
||||
-->
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
{{ define "page" }}
|
||||
<script type="module" src="/js/{{ .VERSION }}/app.mjs"></script>
|
||||
{{ end }}
|
||||
47
views/pages/login.gotmpl
Normal file
47
views/pages/login.gotmpl
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
{{ define "page" }}
|
||||
<link rel="stylesheet" type="text/css" href="/css/{{ .VERSION }}/login.css">
|
||||
<div id="box">
|
||||
<img id="logo" src="/images/v1/logo.svg">
|
||||
<input type="text" id="username" placeholder="Username">
|
||||
<input type="password" id="password" placeholder="Password">
|
||||
<button onclick=window._login.authenticate()>Log in</button>
|
||||
<div id="error"></div>
|
||||
</div>
|
||||
|
||||
<script type="module">
|
||||
import { API } from 'api';
|
||||
|
||||
class Login {
|
||||
constructor() {
|
||||
this.errorDiv = document.getElementById('error')
|
||||
|
||||
document.getElementById('username').focus()
|
||||
|
||||
const username = document.getElementById('username')
|
||||
const password = document.getElementById('password')
|
||||
username.addEventListener('keydown', event=>this.keyHandler(event))
|
||||
password.addEventListener('keydown', event=>this.keyHandler(event))
|
||||
}
|
||||
authenticate() {
|
||||
this.errorDiv.innerText = ''
|
||||
|
||||
const username = document.getElementById('username').value
|
||||
const password = document.getElementById('password').value
|
||||
API.authenticate(username, password)
|
||||
.then(ans=>{
|
||||
location.href = '/notes2'
|
||||
})
|
||||
.catch(e=>{
|
||||
setTimeout(()=>this.errorDiv.innerText = e, 75)
|
||||
})
|
||||
}
|
||||
keyHandler(event) {
|
||||
if (event.key == 'Enter') {
|
||||
this.authenticate()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window._login = new Login()
|
||||
</script>
|
||||
{{ end }}
|
||||
22
views/pages/notes2.gotmpl
Normal file
22
views/pages/notes2.gotmpl
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
{{ define "page" }}
|
||||
|
||||
<script type="module">
|
||||
import { h, Component, render, createRef } from 'preact'
|
||||
import htm from 'htm'
|
||||
{{ if .Data._dev -}}
|
||||
import 'preact/debug'
|
||||
import 'preact/devtools'
|
||||
{{- end }}
|
||||
import { Notes2 } from "/js/{{ .VERSION }}/app.mjs"
|
||||
import { API } from 'api'
|
||||
|
||||
if (!API.hasAuthenticationToken()) {
|
||||
location.href = '/login'
|
||||
} else {
|
||||
const html = htm.bind(h)
|
||||
window._notes2 = createRef()
|
||||
render(html`<${Notes2} ref=${window._notes2} />`, document.getElementById('app'))
|
||||
}
|
||||
</script>
|
||||
|
||||
{{ end }}
|
||||
Loading…
Add table
Add a link
Reference in a new issue