diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-05-06 19:53:25 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-05-06 19:53:25 +0300 |
| commit | fbdc0b813944937af29da74f4790e52a2522c480 (patch) | |
| tree | 94f47aaeec7bdf4eab60db340ef654ac391ed9e9 | |
| parent | doc: token endpoint (diff) | |
| download | lphub-fbdc0b813944937af29da74f4790e52a2522c480.tar.gz lphub-fbdc0b813944937af29da74f4790e52a2522c480.tar.bz2 lphub-fbdc0b813944937af29da74f4790e52a2522c480.zip | |
feat: logout endpoint
| -rw-r--r-- | backend/controllers/loginController.go | 25 | ||||
| -rw-r--r-- | backend/routes/routes.go | 1 | ||||
| -rw-r--r-- | docs/docs.go | 35 | ||||
| -rw-r--r-- | docs/swagger.json | 35 | ||||
| -rw-r--r-- | docs/swagger.yaml | 20 |
5 files changed, 116 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] | ||
| 119 | func 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 | |||
| 110 | func GetPlayerSummaries(steamId, apiKey string) (*models.PlayerSummaries, error) { | 135 | func 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) |
diff --git a/docs/docs.go b/docs/docs.go index bb6f6ab..d39fd1c 100644 --- a/docs/docs.go +++ b/docs/docs.go | |||
| @@ -715,6 +715,41 @@ const docTemplate = `{ | |||
| 715 | } | 715 | } |
| 716 | } | 716 | } |
| 717 | } | 717 | } |
| 718 | }, | ||
| 719 | "delete": { | ||
| 720 | "produces": [ | ||
| 721 | "application/json" | ||
| 722 | ], | ||
| 723 | "tags": [ | ||
| 724 | "auth" | ||
| 725 | ], | ||
| 726 | "summary": "Deletes the token cookie from the user.", | ||
| 727 | "responses": { | ||
| 728 | "200": { | ||
| 729 | "description": "OK", | ||
| 730 | "schema": { | ||
| 731 | "allOf": [ | ||
| 732 | { | ||
| 733 | "$ref": "#/definitions/models.Response" | ||
| 734 | }, | ||
| 735 | { | ||
| 736 | "type": "object", | ||
| 737 | "properties": { | ||
| 738 | "data": { | ||
| 739 | "$ref": "#/definitions/models.LoginResponse" | ||
| 740 | } | ||
| 741 | } | ||
| 742 | } | ||
| 743 | ] | ||
| 744 | } | ||
| 745 | }, | ||
| 746 | "404": { | ||
| 747 | "description": "Not Found", | ||
| 748 | "schema": { | ||
| 749 | "$ref": "#/definitions/models.Response" | ||
| 750 | } | ||
| 751 | } | ||
| 752 | } | ||
| 718 | } | 753 | } |
| 719 | }, | 754 | }, |
| 720 | "/users/{id}": { | 755 | "/users/{id}": { |
diff --git a/docs/swagger.json b/docs/swagger.json index 5ba8a71..ad2a659 100644 --- a/docs/swagger.json +++ b/docs/swagger.json | |||
| @@ -708,6 +708,41 @@ | |||
| 708 | } | 708 | } |
| 709 | } | 709 | } |
| 710 | } | 710 | } |
| 711 | }, | ||
| 712 | "delete": { | ||
| 713 | "produces": [ | ||
| 714 | "application/json" | ||
| 715 | ], | ||
| 716 | "tags": [ | ||
| 717 | "auth" | ||
| 718 | ], | ||
| 719 | "summary": "Deletes the token cookie from the user.", | ||
| 720 | "responses": { | ||
| 721 | "200": { | ||
| 722 | "description": "OK", | ||
| 723 | "schema": { | ||
| 724 | "allOf": [ | ||
| 725 | { | ||
| 726 | "$ref": "#/definitions/models.Response" | ||
| 727 | }, | ||
| 728 | { | ||
| 729 | "type": "object", | ||
| 730 | "properties": { | ||
| 731 | "data": { | ||
| 732 | "$ref": "#/definitions/models.LoginResponse" | ||
| 733 | } | ||
| 734 | } | ||
| 735 | } | ||
| 736 | ] | ||
| 737 | } | ||
| 738 | }, | ||
| 739 | "404": { | ||
| 740 | "description": "Not Found", | ||
| 741 | "schema": { | ||
| 742 | "$ref": "#/definitions/models.Response" | ||
| 743 | } | ||
| 744 | } | ||
| 745 | } | ||
| 711 | } | 746 | } |
| 712 | }, | 747 | }, |
| 713 | "/users/{id}": { | 748 | "/users/{id}": { |
diff --git a/docs/swagger.yaml b/docs/swagger.yaml index a39aed4..d62b46b 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml | |||
| @@ -594,6 +594,26 @@ paths: | |||
| 594 | tags: | 594 | tags: |
| 595 | - search | 595 | - search |
| 596 | /token: | 596 | /token: |
| 597 | delete: | ||
| 598 | produces: | ||
| 599 | - application/json | ||
| 600 | responses: | ||
| 601 | "200": | ||
| 602 | description: OK | ||
| 603 | schema: | ||
| 604 | allOf: | ||
| 605 | - $ref: '#/definitions/models.Response' | ||
| 606 | - properties: | ||
| 607 | data: | ||
| 608 | $ref: '#/definitions/models.LoginResponse' | ||
| 609 | type: object | ||
| 610 | "404": | ||
| 611 | description: Not Found | ||
| 612 | schema: | ||
| 613 | $ref: '#/definitions/models.Response' | ||
| 614 | summary: Deletes the token cookie from the user. | ||
| 615 | tags: | ||
| 616 | - auth | ||
| 597 | get: | 617 | get: |
| 598 | produces: | 618 | produces: |
| 599 | - application/json | 619 | - application/json |