Skip to content

Commit b34fadc

Browse files
committed
rename signin, signout to sign_in, sign_out
1 parent b6a5fdb commit b34fadc

File tree

6 files changed

+42
-42
lines changed

6 files changed

+42
-42
lines changed

api/openapi.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ servers:
1212
- url: 'http://localhost:4102'
1313
description: Local server
1414
paths:
15-
/api/v1/auth/signin:
15+
/api/v1/auth/sign_in:
1616
post:
1717
tags:
1818
- Sessions
@@ -60,7 +60,7 @@ paths:
6060
'500':
6161
description: Internal Server Error
6262
parameters: []
63-
/api/v1/auth/signout:
63+
/api/v1/auth/sign_out:
6464
post:
6565
tags:
6666
- Sessions

html/assets/js/api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ window.ctf01d_tp_api.game_create = function(game_data) {
2626

2727
window.ctf01d_tp_api.auth_signin = function(auth_data) {
2828
return $.ajax({
29-
url: '/api/v1/auth/signin',
29+
url: '/api/v1/auth/sign_in',
3030
method: 'POST',
3131
contentType: 'application/json',
3232
data: JSON.stringify(auth_data),
@@ -35,7 +35,7 @@ window.ctf01d_tp_api.auth_signin = function(auth_data) {
3535

3636
window.ctf01d_tp_api.auth_signout = function(auth_data) {
3737
return $.ajax({
38-
url: '/api/v1/auth/signout',
38+
url: '/api/v1/auth/sign_out',
3939
method: 'POST',
4040
contentType: 'application/json',
4141
data: JSON.stringify(auth_data),

html/assets/js/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function doSignin() {
145145
password: password,
146146
}).fail(function(res) {
147147
$('#sign_error_info').css({"display": ""});
148-
$('#sign_error_info').html('Signin failed. Check username and password.');
148+
$('#sign_error_info').html('SignIn failed. Check username and password.');
149149
console.error(res);
150150
}).done(function(res) {
151151
console.log(res);

internal/app/handlers/interface.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ func (siw *ServerInterfaceWrapper) UpdateGame(w http.ResponseWriter, r *http.Req
3636
siw.handlers.UpdateGame(w, r, id)
3737
}
3838

39-
func (siw *ServerInterfaceWrapper) PostApiV1AuthSignin(w http.ResponseWriter, r *http.Request) {
40-
siw.handlers.PostApiV1AuthSignin(w, r)
39+
func (siw *ServerInterfaceWrapper) PostApiV1AuthSignIn(w http.ResponseWriter, r *http.Request) {
40+
siw.handlers.PostApiV1AuthSignIn(w, r)
4141
}
4242

43-
func (siw *ServerInterfaceWrapper) PostApiV1AuthSignout(w http.ResponseWriter, r *http.Request) {
44-
siw.handlers.PostApiV1AuthSignout(w, r)
43+
func (siw *ServerInterfaceWrapper) PostApiV1AuthSignOut(w http.ResponseWriter, r *http.Request) {
44+
siw.handlers.PostApiV1AuthSignOut(w, r)
4545
}
4646

4747
func (siw *ServerInterfaceWrapper) ValidateSession(w http.ResponseWriter, r *http.Request) {

internal/app/handlers/sessions.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
7474
func (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
}

internal/app/server/server.gen.go

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)