diff --git a/cmd/server/main.go b/cmd/server/main.go index 759c4df..1766d3a 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -101,6 +101,7 @@ func setAdminRoutes(mux *http.ServeMux) { "home": extendFromBox(userT, box, "pages/home.tmpl"), "change_own_password": extendFromBox(userT, box, "pages/change_own_password.tmpl"), "change_password": extendFromBox(userT, box, "pages/change_password.tmpl"), + "delete_user": extendFromBox(userT, box, "pages/delete_user.tmpl"), "create_user": extendFromBox(userT, box, "pages/create_user.tmpl"), "update_lastfm_api_key": extendFromBox(userT, box, "pages/update_lastfm_api_key.tmpl"), } @@ -128,6 +129,8 @@ func setAdminRoutes(mux *http.ServeMux) { mux.HandleFunc("/admin/unlink_lastfm_do", withUserWare(cont.ServeUnlinkLastFMDo)) mux.HandleFunc("/admin/change_password", withAdminWare(cont.ServeChangePassword)) mux.HandleFunc("/admin/change_password_do", withAdminWare(cont.ServeChangePasswordDo)) + mux.HandleFunc("/admin/delete_user", withAdminWare(cont.ServeDeleteUser)) + mux.HandleFunc("/admin/delete_user_do", withAdminWare(cont.ServeDeleteUserDo)) mux.HandleFunc("/admin/create_user", withAdminWare(cont.ServeCreateUser)) mux.HandleFunc("/admin/create_user_do", withAdminWare(cont.ServeCreateUserDo)) mux.HandleFunc("/admin/update_lastfm_api_key", withAdminWare(cont.ServeUpdateLastFMAPIKey)) diff --git a/go.mod b/go.mod index 2c0d746..bf19859 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/gobuffalo/packr/v2 v2.2.0 github.com/gofrs/uuid v3.2.0+incompatible // indirect github.com/golangci/golangci-lint v1.16.0 // indirect + github.com/gorilla/securecookie v1.1.1 github.com/gorilla/sessions v1.1.3 github.com/jinzhu/gorm v1.9.2 github.com/jinzhu/inflection v0.0.0-20180308033659-04140366298a // indirect diff --git a/handler/admin.go b/handler/admin.go index e5ddc34..6b7ab7c 100644 --- a/handler/admin.go +++ b/handler/admin.go @@ -158,6 +158,31 @@ func (c *Controller) ServeChangePasswordDo(w http.ResponseWriter, r *http.Reques http.Redirect(w, r, "/admin/home", http.StatusSeeOther) } +func (c *Controller) ServeDeleteUser(w http.ResponseWriter, r *http.Request) { + username := r.URL.Query().Get("user") + if username == "" { + http.Error(w, "please provide a username", 400) + return + } + var user db.User + err := c.DB.Where("name = ?", username).First(&user).Error + if gorm.IsRecordNotFoundError(err) { + http.Error(w, "couldn't find a user with that name", 400) + return + } + var data templateData + data.SelectedUser = &user + renderTemplate(w, r, c.Templates["delete_user"], &data) +} + +func (c *Controller) ServeDeleteUserDo(w http.ResponseWriter, r *http.Request) { + username := r.URL.Query().Get("user") + var user db.User + c.DB.Where("name = ?", username).First(&user) + c.DB.Delete(&user) + http.Redirect(w, r, "/admin/home", http.StatusSeeOther) +} + func (c *Controller) ServeCreateUser(w http.ResponseWriter, r *http.Request) { renderTemplate(w, r, c.Templates["create_user"], nil) } diff --git a/static/stylesheets/main.css b/static/stylesheets/main.css index 4f3753a..39642be 100644 --- a/static/stylesheets/main.css +++ b/static/stylesheets/main.css @@ -109,10 +109,6 @@ a:hover { background-color: #f4433669; } -.happy { - background-color: #4caf5069; -} - i.mdi { font-size: 14px; } diff --git a/templates/pages/delete_user.tmpl b/templates/pages/delete_user.tmpl new file mode 100644 index 0000000..385e581 --- /dev/null +++ b/templates/pages/delete_user.tmpl @@ -0,0 +1,15 @@ +{{ define "title" }}home{{ end }} + +{{ define "user" }} +
+
+ deleting user {{ .SelectedUser.Name }} +
+
+ are you sure? +
+
+ +
+
+{{ end }} diff --git a/templates/pages/home.tmpl b/templates/pages/home.tmpl index c05dd81..4cfd201 100644 --- a/templates/pages/home.tmpl +++ b/templates/pages/home.tmpl @@ -20,12 +20,12 @@ update api key
{{ end }} {{ if .CurrentLastFMAPIKey }} + current status {{ if .User.LastFMSession }} - current status - linked + linked + | unlink
{{ else }} - current status unlinked link
{{ end }} @@ -43,9 +43,11 @@
{{ range $user := .AllUsers }} {{ $user.Name }} - created - {{ $user.CreatedAt.Format "jan 02, 2006" }} - change password
+ {{ $user.CreatedAt.Format "jan 02, 2006" }} + | + change password + | + delete
{{ end }} create new