diff options
| author | Lizzy Hunt <lizzy.hunt@usu.edu> | 2024-03-29 16:35:04 -0600 |
|---|---|---|
| committer | Lizzy Hunt <lizzy.hunt@usu.edu> | 2024-03-29 16:35:04 -0600 |
| commit | 5080c566ac31ec622986c04f1812a1e88c88210e (patch) | |
| tree | d8dbaa766ef21b098c5740880facc2989c750295 /api/api_keys.go | |
| parent | 7cc13887eae7dd2a61900751e038d273313d077f (diff) | |
| download | hatecomputers.club-5080c566ac31ec622986c04f1812a1e88c88210e.tar.gz hatecomputers.club-5080c566ac31ec622986c04f1812a1e88c88210e.zip | |
guestbook!
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) } } |
