user_list.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package ui
  5. import (
  6. "net/http"
  7. "github.com/miniflux/miniflux/http/context"
  8. "github.com/miniflux/miniflux/http/response/html"
  9. "github.com/miniflux/miniflux/ui/session"
  10. "github.com/miniflux/miniflux/ui/view"
  11. )
  12. // ShowUsers renders the list of users.
  13. func (c *Controller) ShowUsers(w http.ResponseWriter, r *http.Request) {
  14. ctx := context.New(r)
  15. sess := session.New(c.store, ctx)
  16. view := view.New(c.tpl, ctx, sess)
  17. user, err := c.store.UserByID(ctx.UserID())
  18. if err != nil {
  19. html.ServerError(w, err)
  20. return
  21. }
  22. if !user.IsAdmin {
  23. html.Forbidden(w)
  24. return
  25. }
  26. users, err := c.store.Users()
  27. if err != nil {
  28. html.ServerError(w, err)
  29. return
  30. }
  31. users.UseTimezone(user.Timezone)
  32. view.Set("users", users)
  33. view.Set("menu", "settings")
  34. view.Set("user", user)
  35. view.Set("countUnread", c.store.CountUnreadEntries(user.ID))
  36. html.OK(w, view.Render("users"))
  37. }