session_list.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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/ui/session"
  8. "github.com/miniflux/miniflux/ui/view"
  9. "github.com/miniflux/miniflux/http/context"
  10. "github.com/miniflux/miniflux/http/response/html"
  11. )
  12. // ShowSessions shows the list of active user sessions.
  13. func (c *Controller) ShowSessions(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. sessions, err := c.store.UserSessions(user.ID)
  23. if err != nil {
  24. html.ServerError(w, err)
  25. return
  26. }
  27. sessions.UseTimezone(user.Timezone)
  28. view.Set("currentSessionToken", ctx.UserSessionToken())
  29. view.Set("sessions", sessions)
  30. view.Set("menu", "settings")
  31. view.Set("user", user)
  32. view.Set("countUnread", c.store.CountUnreadEntries(user.ID))
  33. html.OK(w, view.Render("sessions"))
  34. }