Skip to content

Commit 4d4c90f

Browse files
adelowo6543
authored andcommitted
add check to api routes too
1 parent b8af23c commit 4d4c90f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

routers/api/v1/user/app.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package user
77

88
import (
9+
"errors"
910
"net/http"
1011

1112
"code.gitea.io/gitea/models"
@@ -89,6 +90,12 @@ func CreateAccessToken(ctx *context.APIContext, form api.CreateAccessTokenOption
8990
UID: ctx.User.ID,
9091
Name: form.Name,
9192
}
93+
94+
if models.AccessTokenByNameExists(t) {
95+
ctx.Error(http.StatusBadRequest, "AccessTokenByNameExists", errors.New("access token name has been used already"))
96+
return
97+
}
98+
9299
if err := models.NewAccessToken(t); err != nil {
93100
ctx.Error(http.StatusInternalServerError, "NewAccessToken", err)
94101
return

0 commit comments

Comments
 (0)