diff options
Diffstat (limited to 'api/api_keys.go')
| -rw-r--r-- | api/api_keys.go | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/api/api_keys.go b/api/api_keys.go index 17ed6c9..d636044 100644 --- a/api/api_keys.go +++ b/api/api_keys.go @@ -30,17 +30,22 @@ func CreateAPIKeyContinuation(context *RequestContext, req *http.Request, resp h Errors: []string{}, } - apiKeys, err := database.ListUserAPIKeys(context.DBConn, context.User.ID) + numKeys, err := database.CountUserAPIKeys(context.DBConn, context.User.ID) if err != nil { log.Println(err) resp.WriteHeader(http.StatusInternalServerError) return failure(context, req, resp) } - if len(apiKeys) >= MAX_USER_API_KEYS { + if numKeys >= MAX_USER_API_KEYS { formErrors.Errors = append(formErrors.Errors, "max api keys reached") } + if len(formErrors.Errors) > 0 { + (*context.TemplateData)["FormError"] = formErrors + return failure(context, req, resp) + } + _, err = database.SaveAPIKey(context.DBConn, &database.UserApiKey{ UserID: context.User.ID, Key: utils.RandomId(), @@ -50,8 +55,6 @@ func CreateAPIKeyContinuation(context *RequestContext, req *http.Request, resp h resp.WriteHeader(http.StatusInternalServerError) return failure(context, req, resp) } - - http.Redirect(resp, req, "/keys", http.StatusFound) return success(context, req, resp) } } |
