working on client creation

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2024-07-22 19:55:22 +02:00
parent 59b9976dbf
commit 1c0ef0e257
20 changed files with 167 additions and 85 deletions

View File

@@ -21,7 +21,7 @@ These are clients that are registered with LightOIDC:
</tr>
<tr>
<td>
<button onclick="window.location.href='newclient.html';">Add new site</button>
<button onclick="window.location.href='newclient.html';">Add new client</button>
</td>
</tr>
</table>

View File

@@ -1,11 +1,11 @@
async function handleClients(response){
if (response.status == UNAUTHORIZED) {
window.location.href = 'login.html?return_to='+encodeURI(window.location.href);
redirect('login.html?return_to='+encodeURI(window.location.href))
return;
}
var clients = await response.json();
console.log(clients);
get()
}
fetch(api+"/clients",{method:'POST'}).then(handleClients);

View File

@@ -19,6 +19,10 @@ function getValue(id){
return get(id).value;
}
function redirect(page){
window.location.href = page;
}
function setText(id, text){
get(id).innerHTML = text;
}

View File

@@ -9,8 +9,7 @@ async function handleLogin(response){
function doRedirect(){
let params = new URL(document.location.toString()).searchParams;
let redirect = params.get("return_to") || 'index.html';
window.location.href = redirect,true;
redirect( params.get("return_to") || 'index.html');
return false;
}

View File

@@ -1,7 +1,5 @@
function handleLogout(response){
if (response.ok){
document.body.innerHTML += 'success';
document.location.href='index.html';
}
if (response.ok) document.body.innerHTML += 'success';
redirect('index.html')
}
fetch(api+"/logout").then(handleLogout)

View File

@@ -4,13 +4,19 @@
<title>Light OIDC</title>
<script src="common.js"></script>
<script src="user.js"></script>
<script src="newclient.js"></script>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<nav></nav>
<h1>Add new client</h1>
<fieldset>
<legend>Settings</legend>
<table>
<tr>
<th>client id</th>
<td><input type="text" size="50" id="client-id"></td>
</tr>
<tr>
<th>client name</th>
<td><input type="text" size="50" id="client-name"></td>
@@ -24,6 +30,7 @@
<td><textarea cols="50" rows="5" id="redirect-urls"></textarea></td>
</tr>
</table>
<button id="button" type="button" onclick="addClient()">Add client</button>
</fieldset>
</body>
</html>

View File

@@ -0,0 +1,37 @@
function addClient(){
disable('button');
var newData = {
client_id : getValue('client-id'),
name : getValue('client-name'),
secret : getValue('client-secret'),
redirect_uri : getValue('redirect-urls').split("\n")
};
fetch(api+'/add/client',{
method : 'POST',
headers : {
'Content-Type': 'application/json'
},
body : JSON.stringify(newData)
}).then(handleClientdResponse);
setText('button','sent…');
setTimeout(function(){
setText('button','Add client');
enable('button');
},10000);
}
function handleClientdResponse(response){
if (response.ok){
redirect("clients.html");
} else {
setText('button','Failed!');
enable('button');
}
}
function checkPermissions(){
if (user && !user.permissions.includes('MANAGE_CLIENTS')) redirect("index.html");
}
setTimeout(checkPermissions,100);

View File

@@ -28,7 +28,6 @@ function handlePasswordResponse(response){
function update(){
disable('updateBtn');
setText('updateBtn','sent…');
var newData = {
username : getValue('username'),
email : getValue('email'),
@@ -41,11 +40,11 @@ function update(){
},
body : JSON.stringify(newData)
}).then(handleResponse)
setText('updateBtn','sent…');
}
function updatePass(){
disable('passBtn');
setText('passBtn','sent…');
var newData = {
oldpass : getValue('oldpass'),
newpass : [getValue('newpass1'),getValue('newpass2')],
@@ -58,11 +57,11 @@ function updatePass(){
},
body : JSON.stringify(newData)
}).then(handlePasswordResponse);
setTimeout(function(){
setText('passBtn','Update');
enable('passBtn');
},10000);
setText('passBtn','sent…');
setTimeout(function(){
setText('passBtn','Update');
enable('passBtn');
},10000);
}
function passKeyDown(ev){

View File

@@ -9,4 +9,9 @@ body fieldset {
a {
color: yellow;
}
fieldset th,
form th{
text-align: right;
}

View File

@@ -1,7 +1,7 @@
var user = null;
async function handleUser(response){
if (response.status == UNAUTHORIZED) {
window.location.href = 'login.html?return_to='+encodeURI(window.location.href);
redirect('login.html?return_to='+encodeURI(window.location.href));
return;
}
if (response.ok){