mirror of
https://github.com/gogs/gogs.git
synced 2025-12-23 16:50:02 +01:00
internal: move packages under this directory (#5836)
* Rename pkg -> internal * Rename routes -> route * Move route -> internal/route * Rename models -> db * Move db -> internal/db * Fix route2 -> route * Move cmd -> internal/cmd * Bump version
This commit is contained in:
45
internal/route/api/v1/user/app.go
Normal file
45
internal/route/api/v1/user/app.go
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
api "github.com/gogs/go-gogs-client"
|
||||
|
||||
"gogs.io/gogs/internal/context"
|
||||
"gogs.io/gogs/internal/db"
|
||||
"gogs.io/gogs/internal/db/errors"
|
||||
)
|
||||
|
||||
func ListAccessTokens(c *context.APIContext) {
|
||||
tokens, err := db.ListAccessTokens(c.User.ID)
|
||||
if err != nil {
|
||||
c.ServerError("ListAccessTokens", err)
|
||||
return
|
||||
}
|
||||
|
||||
apiTokens := make([]*api.AccessToken, len(tokens))
|
||||
for i := range tokens {
|
||||
apiTokens[i] = &api.AccessToken{tokens[i].Name, tokens[i].Sha1}
|
||||
}
|
||||
c.JSONSuccess(&apiTokens)
|
||||
}
|
||||
|
||||
func CreateAccessToken(c *context.APIContext, form api.CreateAccessTokenOption) {
|
||||
t := &db.AccessToken{
|
||||
UID: c.User.ID,
|
||||
Name: form.Name,
|
||||
}
|
||||
if err := db.NewAccessToken(t); err != nil {
|
||||
if errors.IsAccessTokenNameAlreadyExist(err) {
|
||||
c.Error(http.StatusUnprocessableEntity, "", err)
|
||||
} else {
|
||||
c.ServerError("NewAccessToken", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusCreated, &api.AccessToken{t.Name, t.Sha1})
|
||||
}
|
||||
Reference in New Issue
Block a user