aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2023-05-06 19:53:25 +0300
committerArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2023-05-06 19:53:25 +0300
commitfbdc0b813944937af29da74f4790e52a2522c480 (patch)
tree94f47aaeec7bdf4eab60db340ef654ac391ed9e9 /backend
parentdoc: token endpoint (diff)
downloadlphub-fbdc0b813944937af29da74f4790e52a2522c480.tar.gz
lphub-fbdc0b813944937af29da74f4790e52a2522c480.tar.bz2
lphub-fbdc0b813944937af29da74f4790e52a2522c480.zip
feat: logout endpoint
Diffstat (limited to 'backend')
-rw-r--r--backend/controllers/loginController.go25
-rw-r--r--backend/routes/routes.go1
2 files changed, 26 insertions, 0 deletions
diff --git a/backend/controllers/loginController.go b/backend/controllers/loginController.go
index 6e1c299..cfe086d 100644
--- a/backend/controllers/loginController.go
+++ b/backend/controllers/loginController.go
@@ -107,6 +107,31 @@ func GetCookie(c *gin.Context) {
107 }) 107 })
108} 108}
109 109
110// DELETE Token
111//
112// @Summary Deletes the token cookie from the user.
113// @Tags auth
114// @Produce json
115//
116// @Success 200 {object} models.Response{data=models.LoginResponse}
117// @Failure 404 {object} models.Response
118// @Router /token [delete]
119func DeleteCookie(c *gin.Context) {
120 cookie, err := c.Cookie("token")
121 if err != nil {
122 c.JSON(http.StatusNotFound, models.ErrorResponse("No token cookie found."))
123 return
124 }
125 c.SetCookie("token", "", -1, "/", "", true, true)
126 c.JSON(http.StatusOK, models.Response{
127 Success: true,
128 Message: "Token cookie successfully deleted.",
129 Data: models.LoginResponse{
130 Token: cookie,
131 },
132 })
133}
134
110func GetPlayerSummaries(steamId, apiKey string) (*models.PlayerSummaries, error) { 135func GetPlayerSummaries(steamId, apiKey string) (*models.PlayerSummaries, error) {
111 url := fmt.Sprintf("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=%s&steamids=%s", apiKey, steamId) 136 url := fmt.Sprintf("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=%s&steamids=%s", apiKey, steamId)
112 resp, err := http.Get(url) 137 resp, err := http.Get(url)
diff --git a/backend/routes/routes.go b/backend/routes/routes.go
index 19382ab..96da1ce 100644
--- a/backend/routes/routes.go
+++ b/backend/routes/routes.go
@@ -17,6 +17,7 @@ func InitRoutes(router *gin.Engine) {
17 c.File("docs/index.html") 17 c.File("docs/index.html")
18 }) 18 })
19 v1.GET("/token", controllers.GetCookie) 19 v1.GET("/token", controllers.GetCookie)
20 v1.DELETE("/token", controllers.DeleteCookie)
20 v1.GET("/home", middleware.CheckAuth, controllers.Home) 21 v1.GET("/home", middleware.CheckAuth, controllers.Home)
21 v1.GET("/login", controllers.Login) 22 v1.GET("/login", controllers.Login)
22 v1.GET("/profile", middleware.CheckAuth, controllers.Profile) 23 v1.GET("/profile", middleware.CheckAuth, controllers.Profile)