user.go 904 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2015 - Present, The Gogs Authors. All rights reserved.
  2. // Copyright 2018 - Present, Gitote. All rights reserved.
  3. //
  4. // This source code is licensed under the MIT license found in the
  5. // LICENSE file in the root directory of this source tree.
  6. package context
  7. import (
  8. "gopkg.in/macaron.v1"
  9. "gitote/gitote/models"
  10. "gitote/gitote/models/errors"
  11. )
  12. // ParamsUser is the wrapper type of the target user defined by URL parameter, namely ':username'.
  13. type ParamsUser struct {
  14. *models.User
  15. }
  16. // InjectParamsUser returns a handler that retrieves target user based on URL parameter ':username',
  17. // and injects it as *ParamsUser.
  18. func InjectParamsUser() macaron.Handler {
  19. return func(c *Context) {
  20. user, err := models.GetUserByName(c.Params(":username"))
  21. if err != nil {
  22. c.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
  23. return
  24. }
  25. c.Map(&ParamsUser{user})
  26. }
  27. }