Skip to content

Commit a83021f

Browse files
committed
Add 'Delete' to clients list
1 parent cc9e4d4 commit a83021f

File tree

4 files changed

+43
-13
lines changed

4 files changed

+43
-13
lines changed

admin_clients.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ func handleAdminClients(w http.ResponseWriter, req *http.Request, page *pageData
3737
}
3838
page.TemplateData = actClientPageData{Id: client.UUID, Ip: client.IP, Name: client.Name}
3939
page.show("admin-activateclient.html", w)
40+
case "delete":
41+
var err error
42+
if err = m.DeleteClient(clientId); err != nil {
43+
page.session.setFlashMessage("Error removing client: "+err.Error(), "error")
44+
} else {
45+
page.session.setFlashMessage("Client Removed", "success")
46+
}
47+
redirect("/admin/clients", w, req)
4048
case "auth":
4149
email := req.FormValue("email")
4250
password := req.FormValue("password")

assets.go

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

model_clients.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,23 @@ func (m *model) UpdateClient(cl *Client) {
162162
}
163163
m.clientsUpdated = true
164164
}
165+
166+
func (m *model) DeleteClient(id string) error {
167+
idx := -1
168+
for i := range m.clients {
169+
if m.clients[i].UUID == id {
170+
idx = i
171+
break
172+
}
173+
}
174+
if idx == -1 {
175+
return errors.New("Invalid Client ID given")
176+
}
177+
m.clients = append(m.clients[:idx], m.clients[idx+1:]...)
178+
// Now delete it from the DB
179+
if err := m.openDB(); err != nil {
180+
return nil
181+
}
182+
defer m.closeDB()
183+
return m.bolt.DeleteBucket([]string{"clients"}, id)
184+
}

templates/admin-clients.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<th class="only-large">Client ID</th>
1010
<th class="only-large">Last Known IP</th>
1111
<th class="only-large">Authenticated</th>
12+
<th class=""></th>
1213
</tr>
1314
</thead>
1415
<tbody>
@@ -25,6 +26,7 @@
2526
<td class="only-large">{{ $v.UUID }}</td>
2627
<td class="only-large">{{ $v.IP }}</td>
2728
<td class="only-large">{{ if $v.Auth }} Yes {{ else }} No {{ end }}</td>
29+
<td class=""><a href="/admin/clients/{{ $v.UUID }}/delete" class="pure-button pure-button-plain"><i class="fa fa-trash"></i></a></td>
2830
</tr>
2931
{{ end }}
3032
</tbody>

0 commit comments

Comments
 (0)