aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2023-05-06 17:41:12 +0300
committerArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2023-05-06 17:41:12 +0300
commit3be6a02ba0a6200e71bd0b97a040075966dfc302 (patch)
treeb1d444156fc909eebc438b324bf5571a11a6ec67 /backend
parentMerge pull request #41 from Nidboj132/main (diff)
downloadlphub-3be6a02ba0a6200e71bd0b97a040075966dfc302.tar.gz
lphub-3be6a02ba0a6200e71bd0b97a040075966dfc302.tar.bz2
lphub-3be6a02ba0a6200e71bd0b97a040075966dfc302.zip
feat: get token endpoint
Diffstat (limited to 'backend')
-rw-r--r--backend/controllers/loginController.go24
-rw-r--r--backend/routes/routes.go1
2 files changed, 25 insertions, 0 deletions
diff --git a/backend/controllers/loginController.go b/backend/controllers/loginController.go
index c533757..06cc0ba 100644
--- a/backend/controllers/loginController.go
+++ b/backend/controllers/loginController.go
@@ -83,6 +83,30 @@ func Login(c *gin.Context) {
83 } 83 }
84} 84}
85 85
86// GET Token
87//
88// @Summary Gets the token cookie value from the user.
89// @Tags auth
90// @Produce json
91//
92// @Success 200 {object} models.Respnose{data=models.LoginResponse}
93// @Failure 404 {object} models.Response
94// @Router /token [get]
95func GetCookie(c *gin.Context) {
96 cookie, err := c.Cookie("token")
97 if err != nil {
98 c.JSON(http.StatusNotFound, models.ErrorResponse("No token cookie found."))
99 return
100 }
101 c.JSON(http.StatusOK, models.Response{
102 Success: true,
103 Message: "Token cookie successfully retrieved.",
104 Data: models.LoginResponse{
105 Token: cookie,
106 },
107 })
108}
109
86func GetPlayerSummaries(steamId, apiKey string) (*models.PlayerSummaries, error) { 110func GetPlayerSummaries(steamId, apiKey string) (*models.PlayerSummaries, error) {
87 url := fmt.Sprintf("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=%s&steamids=%s", apiKey, steamId) 111 url := fmt.Sprintf("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=%s&steamids=%s", apiKey, steamId)
88 resp, err := http.Get(url) 112 resp, err := http.Get(url)
diff --git a/backend/routes/routes.go b/backend/routes/routes.go
index 2554fa4..19382ab 100644
--- a/backend/routes/routes.go
+++ b/backend/routes/routes.go
@@ -16,6 +16,7 @@ func InitRoutes(router *gin.Engine) {
16 v1.GET("/", func(c *gin.Context) { 16 v1.GET("/", func(c *gin.Context) {
17 c.File("docs/index.html") 17 c.File("docs/index.html")
18 }) 18 })
19 v1.GET("/token", controllers.GetCookie)
19 v1.GET("/home", middleware.CheckAuth, controllers.Home) 20 v1.GET("/home", middleware.CheckAuth, controllers.Home)
20 v1.GET("/login", controllers.Login) 21 v1.GET("/login", controllers.Login)
21 v1.GET("/profile", middleware.CheckAuth, controllers.Profile) 22 v1.GET("/profile", middleware.CheckAuth, controllers.Profile)