user_create.go 989 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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/form"
  10. "github.com/miniflux/miniflux/ui/session"
  11. "github.com/miniflux/miniflux/ui/view"
  12. )
  13. // CreateUser shows the user creation form.
  14. func (c *Controller) CreateUser(w http.ResponseWriter, r *http.Request) {
  15. ctx := context.New(r)
  16. sess := session.New(c.store, ctx)
  17. view := view.New(c.tpl, ctx, sess)
  18. user, err := c.store.UserByID(ctx.UserID())
  19. if err != nil {
  20. html.ServerError(w, err)
  21. return
  22. }
  23. if !user.IsAdmin {
  24. html.Forbidden(w)
  25. return
  26. }
  27. view.Set("form", &form.UserForm{})
  28. view.Set("menu", "settings")
  29. view.Set("user", user)
  30. view.Set("countUnread", c.store.CountUnreadEntries(user.ID))
  31. html.OK(w, r, view.Render("create_user"))
  32. }