diff options
| -rw-r--r-- | backend/controllers/loginController.go | 24 | ||||
| -rw-r--r-- | backend/routes/routes.go | 1 | ||||
| -rw-r--r-- | docs/docs.go | 37 | ||||
| -rw-r--r-- | docs/swagger.json | 37 | ||||
| -rw-r--r-- | docs/swagger.yaml | 21 | ||||
| -rw-r--r-- | main.go | 9 |
6 files changed, 122 insertions, 7 deletions
diff --git a/backend/controllers/loginController.go b/backend/controllers/loginController.go index c533757..6e1c299 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.Response{data=models.LoginResponse} | ||
| 93 | // @Failure 404 {object} models.Response | ||
| 94 | // @Router /token [get] | ||
| 95 | func 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 | |||
| 86 | func GetPlayerSummaries(steamId, apiKey string) (*models.PlayerSummaries, error) { | 110 | func 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) |
diff --git a/docs/docs.go b/docs/docs.go index cd129f0..bb6f6ab 100644 --- a/docs/docs.go +++ b/docs/docs.go | |||
| @@ -680,6 +680,43 @@ const docTemplate = `{ | |||
| 680 | } | 680 | } |
| 681 | } | 681 | } |
| 682 | }, | 682 | }, |
| 683 | "/token": { | ||
| 684 | "get": { | ||
| 685 | "produces": [ | ||
| 686 | "application/json" | ||
| 687 | ], | ||
| 688 | "tags": [ | ||
| 689 | "auth" | ||
| 690 | ], | ||
| 691 | "summary": "Gets the token cookie value from the user.", | ||
| 692 | "responses": { | ||
| 693 | "200": { | ||
| 694 | "description": "OK", | ||
| 695 | "schema": { | ||
| 696 | "allOf": [ | ||
| 697 | { | ||
| 698 | "$ref": "#/definitions/models.Response" | ||
| 699 | }, | ||
| 700 | { | ||
| 701 | "type": "object", | ||
| 702 | "properties": { | ||
| 703 | "data": { | ||
| 704 | "$ref": "#/definitions/models.LoginResponse" | ||
| 705 | } | ||
| 706 | } | ||
| 707 | } | ||
| 708 | ] | ||
| 709 | } | ||
| 710 | }, | ||
| 711 | "404": { | ||
| 712 | "description": "Not Found", | ||
| 713 | "schema": { | ||
| 714 | "$ref": "#/definitions/models.Response" | ||
| 715 | } | ||
| 716 | } | ||
| 717 | } | ||
| 718 | } | ||
| 719 | }, | ||
| 683 | "/users/{id}": { | 720 | "/users/{id}": { |
| 684 | "get": { | 721 | "get": { |
| 685 | "consumes": [ | 722 | "consumes": [ |
diff --git a/docs/swagger.json b/docs/swagger.json index 442745f..5ba8a71 100644 --- a/docs/swagger.json +++ b/docs/swagger.json | |||
| @@ -673,6 +673,43 @@ | |||
| 673 | } | 673 | } |
| 674 | } | 674 | } |
| 675 | }, | 675 | }, |
| 676 | "/token": { | ||
| 677 | "get": { | ||
| 678 | "produces": [ | ||
| 679 | "application/json" | ||
| 680 | ], | ||
| 681 | "tags": [ | ||
| 682 | "auth" | ||
| 683 | ], | ||
| 684 | "summary": "Gets the token cookie value from the user.", | ||
| 685 | "responses": { | ||
| 686 | "200": { | ||
| 687 | "description": "OK", | ||
| 688 | "schema": { | ||
| 689 | "allOf": [ | ||
| 690 | { | ||
| 691 | "$ref": "#/definitions/models.Response" | ||
| 692 | }, | ||
| 693 | { | ||
| 694 | "type": "object", | ||
| 695 | "properties": { | ||
| 696 | "data": { | ||
| 697 | "$ref": "#/definitions/models.LoginResponse" | ||
| 698 | } | ||
| 699 | } | ||
| 700 | } | ||
| 701 | ] | ||
| 702 | } | ||
| 703 | }, | ||
| 704 | "404": { | ||
| 705 | "description": "Not Found", | ||
| 706 | "schema": { | ||
| 707 | "$ref": "#/definitions/models.Response" | ||
| 708 | } | ||
| 709 | } | ||
| 710 | } | ||
| 711 | } | ||
| 712 | }, | ||
| 676 | "/users/{id}": { | 713 | "/users/{id}": { |
| 677 | "get": { | 714 | "get": { |
| 678 | "consumes": [ | 715 | "consumes": [ |
diff --git a/docs/swagger.yaml b/docs/swagger.yaml index fa1a26d..a39aed4 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml | |||
| @@ -593,6 +593,27 @@ paths: | |||
| 593 | summary: Get all user and map data. | 593 | summary: Get all user and map data. |
| 594 | tags: | 594 | tags: |
| 595 | - search | 595 | - search |
| 596 | /token: | ||
| 597 | get: | ||
| 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: Gets the token cookie value from the user. | ||
| 615 | tags: | ||
| 616 | - auth | ||
| 596 | /users/{id}: | 617 | /users/{id}: |
| 597 | get: | 618 | get: |
| 598 | consumes: | 619 | consumes: |
| @@ -5,7 +5,6 @@ import ( | |||
| 5 | "log" | 5 | "log" |
| 6 | "os" | 6 | "os" |
| 7 | 7 | ||
| 8 | "github.com/gin-gonic/contrib/cors" | ||
| 9 | "github.com/gin-gonic/gin" | 8 | "github.com/gin-gonic/gin" |
| 10 | "github.com/joho/godotenv" | 9 | "github.com/joho/godotenv" |
| 11 | "github.com/pektezol/leastportals/backend/database" | 10 | "github.com/pektezol/leastportals/backend/database" |
| @@ -20,8 +19,8 @@ import ( | |||
| 20 | // @license.name GNU General Public License, Version 2 | 19 | // @license.name GNU General Public License, Version 2 |
| 21 | // @license.url https://www.gnu.org/licenses/old-licenses/gpl-2.0.html | 20 | // @license.url https://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
| 22 | 21 | ||
| 23 | // @host lp.ardapektezol.com/api | 22 | // @host lp.ardapektezol.com/api |
| 24 | // @BasePath /v1 | 23 | // @BasePath /v1 |
| 25 | func main() { | 24 | func main() { |
| 26 | if os.Getenv("ENV") == "PROD" { | 25 | if os.Getenv("ENV") == "PROD" { |
| 27 | gin.SetMode(gin.ReleaseMode) | 26 | gin.SetMode(gin.ReleaseMode) |
| @@ -31,10 +30,6 @@ func main() { | |||
| 31 | log.Fatal("Error loading .env file") | 30 | log.Fatal("Error loading .env file") |
| 32 | } | 31 | } |
| 33 | router := gin.Default() | 32 | router := gin.Default() |
| 34 | config := cors.DefaultConfig() | ||
| 35 | config.AllowAllOrigins = true | ||
| 36 | config.AllowCredentials = true | ||
| 37 | router.Use(cors.New(config)) | ||
| 38 | database.ConnectDB() | 33 | database.ConnectDB() |
| 39 | // For frontend static serving - only for local debug | 34 | // For frontend static serving - only for local debug |
| 40 | // router.Use(static.Serve("/", static.LocalFile("./frontend/build", true))) | 35 | // router.Use(static.Serve("/", static.LocalFile("./frontend/build", true))) |