@@ -7,22 +7,22 @@ import (
77
88 "ctf01d/internal/app/repository"
99 "ctf01d/internal/app/server"
10- "ctf01d/internal/app/utils"
1110 api_helpers "ctf01d/internal/app/utils"
11+
1212 openapi_types "github.com/oapi-codegen/runtime/types"
1313)
1414
15- func (h * Handlers ) PostApiV1AuthSignin (w http.ResponseWriter , r * http.Request ) {
16- var req server.PostApiV1AuthSigninJSONBody
15+ func (h * Handlers ) PostApiV1AuthSignIn (w http.ResponseWriter , r * http.Request ) {
16+ var req server.PostApiV1AuthSignInJSONBody
1717 if err := json .NewDecoder (r .Body ).Decode (& req ); err != nil {
18- slog .Warn (err .Error (), "handler" , "PostApiV1AuthSignin " )
18+ slog .Warn (err .Error (), "handler" , "PostApiV1AuthSignIn " )
1919 http .Error (w , "Invalid request body" , http .StatusBadRequest )
2020 return
2121 }
2222 userRepo := repository .NewUserRepository (h .DB )
2323 user , err := userRepo .GetByUserName (r .Context (), * req .UserName )
2424 if err != nil || ! api_helpers .CheckPasswordHash (* req .Password , user .PasswordHash ) {
25- slog .Warn (err .Error (), "handler" , "PostApiV1AuthSignin " )
25+ slog .Warn (err .Error (), "handler" , "PostApiV1AuthSignIn " )
2626 api_helpers .RespondWithJSON (w , http .StatusUnauthorized , map [string ]string {"error" : "Invalid password or user" })
2727 return
2828 }
@@ -32,7 +32,7 @@ func (h *Handlers) PostApiV1AuthSignin(w http.ResponseWriter, r *http.Request) {
3232
3333 sessionId , err := repo .StoreSessionInDB (r .Context (), user .Id )
3434 if err != nil {
35- slog .Warn (err .Error (), "handler" , "PostApiV1AuthSignin " )
35+ slog .Warn (err .Error (), "handler" , "PostApiV1AuthSignIn " )
3636 api_helpers .RespondWithJSON (w , http .StatusInternalServerError , map [string ]string {"error" : "Failed to store session" })
3737 return
3838 }
@@ -48,17 +48,17 @@ func (h *Handlers) PostApiV1AuthSignin(w http.ResponseWriter, r *http.Request) {
4848 api_helpers .RespondWithJSON (w , http .StatusOK , map [string ]string {"data" : "User logged in" })
4949}
5050
51- func (h * Handlers ) PostApiV1AuthSignout (w http.ResponseWriter , r * http.Request ) {
51+ func (h * Handlers ) PostApiV1AuthSignOut (w http.ResponseWriter , r * http.Request ) {
5252 cookie , err := r .Cookie ("session_id" )
5353 if err != nil {
54- slog .Warn (err .Error (), "handler" , "PostApiV1AuthSignout " )
54+ slog .Warn (err .Error (), "handler" , "PostApiV1AuthSignOut " )
5555 api_helpers .RespondWithJSON (w , http .StatusUnauthorized , map [string ]string {"error" : "No session found" })
5656 return
5757 }
5858 repo := repository .NewSessionRepository (h .DB )
5959 err = repo .DeleteSessionInDB (r .Context (), cookie .Value )
6060 if err != nil {
61- slog .Warn (err .Error (), "handler" , "PostApiV1AuthSignout " )
61+ slog .Warn (err .Error (), "handler" , "PostApiV1AuthSignOut " )
6262 api_helpers .RespondWithJSON (w , http .StatusInternalServerError , map [string ]string {"error" : "Failed to delete session" })
6363 return
6464 }
@@ -74,7 +74,7 @@ func (h *Handlers) PostApiV1AuthSignout(w http.ResponseWriter, r *http.Request)
7474func (h * Handlers ) ValidateSession (w http.ResponseWriter , r * http.Request ) {
7575 cookie , err := r .Cookie ("session_id" )
7676 if err != nil {
77- slog .Warn (err .Error (), "handler" , "PostApiV1AuthSession " )
77+ slog .Warn (err .Error (), "handler" , "ValidateSession " )
7878 api_helpers .RespondWithJSON (w , http .StatusUnauthorized , map [string ]string {"error" : "No session found" })
7979 return
8080 }
@@ -83,7 +83,7 @@ func (h *Handlers) ValidateSession(w http.ResponseWriter, r *http.Request) {
8383 var userId openapi_types.UUID
8484 userId , err = repo .GetSessionFromDB (r .Context (), cookie .Value )
8585 if err != nil {
86- slog .Warn (err .Error (), "handler" , "PostApiV1AuthSession " )
86+ slog .Warn (err .Error (), "handler" , "ValidateSession " )
8787 api_helpers .RespondWithJSON (w , http .StatusUnauthorized , map [string ]string {"error" : "No user or session found" })
8888 return
8989 }
@@ -92,13 +92,13 @@ func (h *Handlers) ValidateSession(w http.ResponseWriter, r *http.Request) {
9292 userRepo := repository .NewUserRepository (h .DB )
9393 user , err := userRepo .GetById (r .Context (), userId )
9494 if err != nil {
95- slog .Warn (err .Error (), "handler" , "PostApiV1AuthSession " )
95+ slog .Warn (err .Error (), "handler" , "ValidateSession " )
9696 api_helpers .RespondWithJSON (w , http .StatusInternalServerError , map [string ]string {"error" : "Could not find user by user id" })
9797 return
9898 }
9999 var res = make (map [string ]string )
100100 res ["name" ] = user .DisplayName
101- res ["role" ] = helpers .ConvertUserRequestRoleToString (user .Role )
101+ res ["role" ] = api_helpers .ConvertUserRequestRoleToString (user .Role )
102102
103103 api_helpers .RespondWithJSON (w , http .StatusOK , res )
104104}
0 commit comments