Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Alert user when limit is reached.
Browse files Browse the repository at this point in the history
When the user tries to create more configurations than are allow an
alert will pop up.
  • Loading branch information
spetzreborn committed Mar 19, 2020
1 parent 1c2c27a commit cea0434
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
14 changes: 14 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,21 @@ func (s *Server) CreateClient(w http.ResponseWriter, r *http.Request, ps httprou
if *maxNumberClientConfig > 0 {
if len(c.Clients) >= *maxNumberClientConfig {
log.Error(fmt.Errorf("user %q have too many configs", c.Name))

e := struct {
Error string
}{
Error: "Max number of configs: " + strconv.Itoa(*maxNumberClientConfig),
}

j, err := json.Marshal(e)
if err != nil {
log.Error(err)
return
}

w.WriteHeader(http.StatusTooManyRequests)
fmt.Fprintf(w, string(j))
return
}
}
Expand Down
16 changes: 13 additions & 3 deletions ui/src/Clients.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@
async function handleNewClick(event) {
const res = await fetch(clientsUrl, {
method: "POST",
});
let newClient = await res.json();
console.log("New client added", newClient);
})
.then(response => {
return response.json()
})
.then(data => {
if (typeof data.Error != "undefined") {
console.log(data.Error);
alert(data.Error);
} else {
console.log("New client added", data);
}
});
await getClients();
}
onMount(getClients);
</script>

Expand Down

0 comments on commit cea0434

Please sign in to comment.