app.go 997 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Copyright 2018 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 user
  7. import (
  8. "gitote/gitote/models"
  9. "gitote/gitote/pkg/context"
  10. api "gitlab.com/gitote/go-gitote-client"
  11. )
  12. func ListAccessTokens(c *context.APIContext) {
  13. tokens, err := models.ListAccessTokens(c.User.ID)
  14. if err != nil {
  15. c.Error(500, "ListAccessTokens", err)
  16. return
  17. }
  18. apiTokens := make([]*api.AccessToken, len(tokens))
  19. for i := range tokens {
  20. apiTokens[i] = &api.AccessToken{tokens[i].Name, tokens[i].Sha1}
  21. }
  22. c.JSON(200, &apiTokens)
  23. }
  24. func CreateAccessToken(c *context.APIContext, form api.CreateAccessTokenOption) {
  25. t := &models.AccessToken{
  26. UID: c.User.ID,
  27. Name: form.Name,
  28. }
  29. if err := models.NewAccessToken(t); err != nil {
  30. c.Error(500, "NewAccessToken", err)
  31. return
  32. }
  33. c.JSON(201, &api.AccessToken{t.Name, t.Sha1})
  34. }