diff options
author | Tom Smeding <tom@tomsmeding.com> | 2022-09-06 23:11:57 +0200 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2022-09-06 23:11:57 +0200 |
commit | efb81ae3be0ec88193847f2865df124c1a2c6543 (patch) | |
tree | bb603c68c07cae231f846c73bd28ff3ae2e15bfa /modules/timetrack3/unknownuser.html | |
parent | ee25ef17677c9360bb03b2d665d5e33ba0d7b9bc (diff) |
timetrack3
Diffstat (limited to 'modules/timetrack3/unknownuser.html')
-rw-r--r-- | modules/timetrack3/unknownuser.html | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/modules/timetrack3/unknownuser.html b/modules/timetrack3/unknownuser.html new file mode 100644 index 0000000..c7d237f --- /dev/null +++ b/modules/timetrack3/unknownuser.html @@ -0,0 +1,87 @@ +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<title>TimeTrack: Unknown user</title> +<script> +"use strict"; + +var ROOT_ENDPOINT="/timetrack3"; + +function fetch(method,url,data/*?*/,creds/*?*/,cb){ + if(!creds){ + cb=data; + data=undefined; + creds=undefined; + } else if(!cb){ + cb=creds; + creds=undefined; + } + if(!cb)throw new Error("No callback passed to fetch"); + var xhr=new XMLHttpRequest(); + xhr.onreadystatechange=function(ev){ + if(xhr.readyState<4)return; + cb(xhr.status,xhr.responseText); + }; + if(creds){ + xhr.open(method,url,true,creds[0],creds[1]); + } else { + xhr.open(method,url); + } + xhr.send(data); +} + +function asciiValid(str){ + var i,c; + for(i=0;i<str.length;i++){ + c=str.charCodeAt(i); + if(c<32||c>=127)return false; + } + return true; +} + +function logoutReload(){ + fetch("GET",ROOT_ENDPOINT+"/authfail",undefined,["baduser","badpass"],function(status,body){ + location.href=location.href; + }); +} + +function doCreateUser(){ + var username=document.getElementById("username").value; + var password=document.getElementById("password").value; + var fail=false; + [["Username",username],["Password",password]].forEach(function(name,value){ + if(value.length<3){fail=true;alert(name+" too short!");} + else if(value.length>32){fail=true;alert(name+" too long!");} + else if(!asciiValid(value)){fail=true;alert("Invalid "+name.toLowerCase()+"! Please use only ASCII characters.");} + }); + if(fail)return; + + fetch("POST",ROOT_ENDPOINT+"/createuser",undefined,[username,password],function(status,body){ + if(status==200){ + alert("User \""+username+"\" created successfully. Please login."); + logoutReload(); + } else { + alert("Error: "+body); + } + }); +} +</script> +<style> +body{ + font-family:Georgia,Times,serif; + font-size:14px; +} +</style> +</head> +<body> +<h1>TimeTrack: Unknown user</h1> +<p>The user you entered is not known in the system. You can use the form below to create a new user. +Be aware: this system is not secure.</p> +Username: <input type="text" id="username" placeholder="username"><br> +Password: <input type="password" id="password" placeholder="password"><br> +<input type="button" value="Create user" onclick="doCreateUser();"> +<br><br> +<p>You can also <input type="button" onclick="logoutReload();" value="log out and try again"> if you just can't type.</p> +</body> +</html> |