13 changed files with 252 additions and 17 deletions
@ -0,0 +1,5 @@ |
|||||||
|
<a href="index.html">Dashboard</a> |
||||||
|
<a href="clients.html" class="MANAGE_CLIENTS">Clients</a> |
||||||
|
<a href="users.html" class="MANAGE_USERS">Users</a> |
||||||
|
<a href="settings.html">Settings</a> |
||||||
|
<a href="logout.html">Logout</a> |
@ -0,0 +1,55 @@ |
|||||||
|
<html> |
||||||
|
<head> |
||||||
|
<meta charset="utf-8"> |
||||||
|
<title>Light OIDC</title> |
||||||
|
<script src="common.js"></script> |
||||||
|
<script src="user.js"></script> |
||||||
|
<script src="settings.js"></script> |
||||||
|
</head> |
||||||
|
<body> |
||||||
|
<nav></nav> |
||||||
|
<h1>Settings</h1> |
||||||
|
<form> |
||||||
|
<fieldset> |
||||||
|
<legend> |
||||||
|
Basic settings |
||||||
|
</legend> |
||||||
|
<table> |
||||||
|
<tr> |
||||||
|
<th>User name</th> |
||||||
|
<td><input id="username" type="text"></td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<th>Email</th> |
||||||
|
<td><input id="email" type="email"></td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<th>ID</th> |
||||||
|
<td><input id="uuid" type="text" disabled="true"></td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
<button id="updateBtn" type="button" onClick="update()">Update</button> |
||||||
|
</fieldset> |
||||||
|
<fieldset> |
||||||
|
<legend> |
||||||
|
Password |
||||||
|
</legend> |
||||||
|
<table> |
||||||
|
<tr> |
||||||
|
<th>Old password</th> |
||||||
|
<td><input id="oldpass1" type="password"></td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<th>Repeat Password</th> |
||||||
|
<td><input id="oldpass2" type="password"></td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<th>New Password</th> |
||||||
|
<td><input id="newpass" type="password"></td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
<button id="passBtn" type="button" onClick="updatePass()">Update</button> |
||||||
|
</fieldset> |
||||||
|
</form> |
||||||
|
</body> |
||||||
|
</html> |
@ -0,0 +1,68 @@ |
|||||||
|
function fillForm(){ |
||||||
|
if (user == null){ |
||||||
|
setTimeout(fillForm,100); |
||||||
|
} else { |
||||||
|
console.log(user); |
||||||
|
setValue('username',user.username); |
||||||
|
setValue('email',user.email); |
||||||
|
setValue('uuid', user.uuid); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
function handleResponse(response){ |
||||||
|
setText('updateBtn',response.ok ? 'saved.' : 'failed!'); |
||||||
|
setTimeout(function(){ |
||||||
|
setText('updateBtn','Update'); |
||||||
|
enable('updateBtn'); |
||||||
|
},10000); |
||||||
|
} |
||||||
|
|
||||||
|
function handlePasswordResponse(response){ |
||||||
|
setText('passBtn',response.ok ? 'saved.' : 'failed!'); |
||||||
|
setTimeout(function(){ |
||||||
|
setText('passBtn','Update'); |
||||||
|
enable('passBtn'); |
||||||
|
},10000); |
||||||
|
} |
||||||
|
|
||||||
|
function update(){ |
||||||
|
disable('updateBtn'); |
||||||
|
setText('updateBtn','sent…'); |
||||||
|
var newData = { |
||||||
|
username : getValue('username'), |
||||||
|
email : getValue('email'), |
||||||
|
uuid : getValue('uuid') |
||||||
|
} |
||||||
|
fetch(api+'/update/user',{ |
||||||
|
method : 'POST', |
||||||
|
headers : { |
||||||
|
'Content-Type': 'application/json' |
||||||
|
}, |
||||||
|
body : JSON.stringify(newData) |
||||||
|
}).then(handleResponse) |
||||||
|
} |
||||||
|
|
||||||
|
function updatePass(){ |
||||||
|
disable('passBtn'); |
||||||
|
setText('passBtn','sent…'); |
||||||
|
var newData = { |
||||||
|
oldpass : [getValue('oldpass1'),getValue('oldpass2')], |
||||||
|
newpass : getValue('newpass'), |
||||||
|
uuid : getValue('uuid') |
||||||
|
} |
||||||
|
fetch(api+'/update/password',{ |
||||||
|
method : 'POST', |
||||||
|
headers : { |
||||||
|
'Content-Type': 'application/json' |
||||||
|
}, |
||||||
|
body : JSON.stringify(newData) |
||||||
|
}).then(handlePasswordResponse); |
||||||
|
|
||||||
|
setTimeout(function(){ |
||||||
|
setText('passBtn','Update'); |
||||||
|
enable('passBtn'); |
||||||
|
},10000); |
||||||
|
} |
||||||
|
|
||||||
|
setTimeout(fillForm,100); |
@ -1,11 +1,27 @@ |
|||||||
|
var user = null; |
||||||
async function handleUser(response){ |
async function handleUser(response){ |
||||||
if (response.status == UNAUTHORIZED) { |
if (response.status == UNAUTHORIZED) { |
||||||
window.location.href = 'login.html?return_to='+encodeURI(window.location.href); |
window.location.href = 'login.html?return_to='+encodeURI(window.location.href); |
||||||
return; |
return; |
||||||
} |
} |
||||||
var user = await response.json(); |
if (response.ok){ |
||||||
// TODO: load navigation
|
user = await response.json(); |
||||||
|
fetch(web+"/navigation.html").then(handleNavigation); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
async function handleNavigation(response){ |
||||||
|
if (response.ok){ |
||||||
|
var content = await response.text(); |
||||||
|
var nav = document.getElementsByTagName('nav')[0]; |
||||||
|
nav.innerHTML = content; |
||||||
|
var links = nav.getElementsByTagName('a'); |
||||||
|
for (var index = 0; index < links.length; index++){ |
||||||
|
var link = links[index]; |
||||||
|
var clazz = link.hasAttribute('class') ? link.getAttribute("class") : null; |
||||||
|
if (clazz != null && !user.permissions.includes(clazz)) nav.removeChild(link); |
||||||
|
} |
||||||
|
} |
||||||
} |
} |
||||||
|
|
||||||
fetch(api+"/user",{method:'POST'}).then(handleUser); |
fetch(api+"/user",{method:'POST'}).then(handleUser); |
Loading…
Reference in new issue