commit 54c681ef31086b42815a44aed169ce349fcde5b6 Author: kalipso Date: Mon Apr 6 22:57:57 2026 +0200 init diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/controllers/userController.go b/controllers/userController.go new file mode 100644 index 0000000..f17261a --- /dev/null +++ b/controllers/userController.go @@ -0,0 +1,224 @@ +package controllers + +import ( + "errors" + "fmt" + "net/http" + + "github.com/gin-gonic/gin" + _ "github.com/swaggo/swag/example/celler/httputil" + "gorm.io/gorm" + + "git.dynamicdiscord.de/harakat/backend/models" + "git.dynamicdiscord.de/harakat/backend/repositories" + "git.dynamicdiscord.de/harakat/backend/services" +) + +type UserController struct{} + +func NewUserController() UserController { + return UserController{} +} + +type EmptyResponse struct{} + +type LoginRequest struct { + Email string `json:"email" binding:"required"` + Password string `json:"password" binding:"required"` +} + +type RegisterRequest struct { + LoginRequest + Name string `json:"name" binding:"required"` +} + +// Register godoc +// @Summary Register user with invite token +// @Description register user with invite token +// @Tags user +// @Accept json +// @Produce json +// @Param token path string false "invite token" +// @Param user body RegisterRequest true "user data" +// @Success 200 {object} EmptyResponse +// @Failure 400 {object} httputil.HTTPError +// @Failure 404 {object} httputil.HTTPError +// @Failure 500 {object} httputil.HTTPError +// @Router /user/register/{token} [post] +func (uc *UserController) Register(c *gin.Context) { + var body RegisterRequest + err := c.BindJSON(&body) + + if err != nil { + fmt.Println("Error: ", err) + c.JSON(http.StatusBadRequest, gin.H{ + "error": err.Error(), + }) + return + } + + name := body.Name + email := body.Email + password := body.Password + + //first registered user is admin + isEmpty, _ := repositories.Users.IsEmpty() + if isEmpty { + _, err := services.Users.Register(name, email, password, true) + if err != nil { + fmt.Println("Error: ", err) + c.JSON(http.StatusBadRequest, gin.H{ + "error": "Failed to create user", + }) + + return + } + + c.JSON(http.StatusOK, gin.H{}) + return + } + + //for any other user token is required + token := c.PostForm("token") + + if token == "" { + c.JSON(http.StatusForbidden, gin.H{ + "error": "No valid token was given.", + }) + return + } + + tokenExists, err := repositories.Tokens.Exists(token) + + if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + c.JSON(http.StatusBadRequest, gin.H{ + "error": err.Error(), + }) + return + } + + if !tokenExists { + c.JSON(http.StatusForbidden, gin.H{ + "error": "No valid token was given.", + }) + return + } + + _, err = services.Users.Register(name, email, password, false) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{ + "error": "Registration failed", + }) + return + } + + err = repositories.Tokens.Delete(token) + + if err != nil { + fmt.Println("Could not delete RegisterToken: ", err) + } + + c.JSON(http.StatusOK, gin.H{}) +} + +// Login godoc +// @Summary Login user +// @Description Login user +// @Tags user +// @Accept json +// @Produce json +// @Param user body LoginRequest true "user data" +// @Success 200 {object} EmptyResponse +// @Failure 400 {object} httputil.HTTPError +// @Failure 401 {object} httputil.HTTPError +// @Failure 500 {object} httputil.HTTPError +// @Router /user/login [post] +func (uc *UserController) Login(c *gin.Context) { + //Get the email/passwd off req body + var body LoginRequest + err := c.Bind(&body) + + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{ + "error": "Login Failed", + }) + + return + } + + tokenString, err := services.Users.Login(body.Email, body.Password) + + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{ + "error": "Login Failed", + }) + + return + } + + user, _ := repositories.Users.GetByEmail(body.Email) + c.Set("user", user) + + // send it back + c.SetSameSite(http.SameSiteLaxMode) + c.SetCookie("Authorization", tokenString, 3600*24, "", "", false, true) + c.JSON(http.StatusOK, gin.H{}) +} + +// Login godoc +// @Summary User Status +// @Description Get user status of current session +// @Tags user +// @Accept json +// @Produce json +// @Success 200 {object} EmptyResponse +// @Failure 400 {object} httputil.HTTPError +// @Failure 500 {object} httputil.HTTPError +// @Router /user/status [get] +func (uc *UserController) Status(c *gin.Context) { + user, exists := c.Get("user") + + if exists { + c.JSON(http.StatusOK, gin.H{ + "message": fmt.Sprintf("Logged in with userID: %d", user.(models.User).ID), + }) + } else { + c.JSON(http.StatusOK, gin.H{ + "message": "Currently not logged in.", + }) + } +} + +func CreateSessionData(c *gin.Context, extra any) gin.H { + user, exists := c.Get("user") + userImpl, _ := user.(models.User) + + return gin.H{ + "loggedIn": exists, + "isAdmin": userImpl.IsAdmin, + "data": extra, + } +} + +func (rc *UserController) InitAdmin(c *gin.Context) { + isEmpty, err := repositories.Users.IsEmpty() + + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{ + "error": err.Error(), + }) + return + } + + fmt.Println("FOOO") + if !isEmpty { + c.JSON(http.StatusForbidden, gin.H{ + "error": "Registration is closed", + }) + return + + } + + fmt.Println("FOOO") + rc.Register(c) +} diff --git a/docs/docs.go b/docs/docs.go new file mode 100644 index 0000000..b90877f --- /dev/null +++ b/docs/docs.go @@ -0,0 +1,252 @@ +// Package docs Code generated by swaggo/swag. DO NOT EDIT +package docs + +import "github.com/swaggo/swag" + +const docTemplate = `{ + "schemes": {{ marshal .Schemes }}, + "swagger": "2.0", + "info": { + "description": "{{escape .Description}}", + "title": "{{.Title}}", + "termsOfService": "TODO", + "contact": { + "name": "TODO", + "url": "TODO", + "email": "TODO" + }, + "license": { + "name": "TODO", + "url": "TODO" + }, + "version": "{{.Version}}" + }, + "host": "{{.Host}}", + "basePath": "{{.BasePath}}", + "paths": { + "/user/login": { + "post": { + "description": "Login user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "user" + ], + "summary": "Login user", + "parameters": [ + { + "description": "user data", + "name": "user", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/controllers.LoginRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.EmptyResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + } + }, + "/user/register/{token}": { + "post": { + "description": "register user with invite token", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "user" + ], + "summary": "Register user with invite token", + "parameters": [ + { + "type": "string", + "description": "invite token", + "name": "token", + "in": "path" + }, + { + "description": "user data", + "name": "user", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/controllers.RegisterRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.EmptyResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + } + }, + "/user/status": { + "get": { + "description": "Get user status of current session", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "user" + ], + "summary": "User Status", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.EmptyResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + } + } + }, + "definitions": { + "controllers.EmptyResponse": { + "type": "object" + }, + "controllers.LoginRequest": { + "type": "object", + "required": [ + "email", + "password" + ], + "properties": { + "email": { + "type": "string" + }, + "password": { + "type": "string" + } + } + }, + "controllers.RegisterRequest": { + "type": "object", + "required": [ + "email", + "name", + "password" + ], + "properties": { + "email": { + "type": "string" + }, + "name": { + "type": "string" + }, + "password": { + "type": "string" + } + } + }, + "httputil.HTTPError": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 400 + }, + "message": { + "type": "string", + "example": "status bad request" + } + } + } + }, + "securityDefinitions": { + "BasicAuth": { + "type": "basic" + } + }, + "externalDocs": { + "description": "OpenAPI", + "url": "https://swagger.io/resources/open-api/" + } +}` + +// SwaggerInfo holds exported Swagger Info so clients can modify it +var SwaggerInfo = &swag.Spec{ + Version: "0.1", + Host: "localhost:8080", + BasePath: "/api/v0", + Schemes: []string{}, + Title: "Harakat Rest-API", + Description: "This is harakat backend server.", + InfoInstanceName: "swagger", + SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", +} + +func init() { + swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) +} diff --git a/docs/swagger.json b/docs/swagger.json new file mode 100644 index 0000000..4acbeef --- /dev/null +++ b/docs/swagger.json @@ -0,0 +1,228 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is harakat backend server.", + "title": "Harakat Rest-API", + "termsOfService": "TODO", + "contact": { + "name": "TODO", + "url": "TODO", + "email": "TODO" + }, + "license": { + "name": "TODO", + "url": "TODO" + }, + "version": "0.1" + }, + "host": "localhost:8080", + "basePath": "/api/v0", + "paths": { + "/user/login": { + "post": { + "description": "Login user", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "user" + ], + "summary": "Login user", + "parameters": [ + { + "description": "user data", + "name": "user", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/controllers.LoginRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.EmptyResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + } + }, + "/user/register/{token}": { + "post": { + "description": "register user with invite token", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "user" + ], + "summary": "Register user with invite token", + "parameters": [ + { + "type": "string", + "description": "invite token", + "name": "token", + "in": "path" + }, + { + "description": "user data", + "name": "user", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/controllers.RegisterRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.EmptyResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + } + }, + "/user/status": { + "get": { + "description": "Get user status of current session", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "user" + ], + "summary": "User Status", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controllers.EmptyResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/httputil.HTTPError" + } + } + } + } + } + }, + "definitions": { + "controllers.EmptyResponse": { + "type": "object" + }, + "controllers.LoginRequest": { + "type": "object", + "required": [ + "email", + "password" + ], + "properties": { + "email": { + "type": "string" + }, + "password": { + "type": "string" + } + } + }, + "controllers.RegisterRequest": { + "type": "object", + "required": [ + "email", + "name", + "password" + ], + "properties": { + "email": { + "type": "string" + }, + "name": { + "type": "string" + }, + "password": { + "type": "string" + } + } + }, + "httputil.HTTPError": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 400 + }, + "message": { + "type": "string", + "example": "status bad request" + } + } + } + }, + "securityDefinitions": { + "BasicAuth": { + "type": "basic" + } + }, + "externalDocs": { + "description": "OpenAPI", + "url": "https://swagger.io/resources/open-api/" + } +} \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml new file mode 100644 index 0000000..100bb1a --- /dev/null +++ b/docs/swagger.yaml @@ -0,0 +1,152 @@ +basePath: /api/v0 +definitions: + controllers.EmptyResponse: + type: object + controllers.LoginRequest: + properties: + email: + type: string + password: + type: string + required: + - email + - password + type: object + controllers.RegisterRequest: + properties: + email: + type: string + name: + type: string + password: + type: string + required: + - email + - name + - password + type: object + httputil.HTTPError: + properties: + code: + example: 400 + type: integer + message: + example: status bad request + type: string + type: object +externalDocs: + description: OpenAPI + url: https://swagger.io/resources/open-api/ +host: localhost:8080 +info: + contact: + email: TODO + name: TODO + url: TODO + description: This is harakat backend server. + license: + name: TODO + url: TODO + termsOfService: TODO + title: Harakat Rest-API + version: "0.1" +paths: + /user/login: + post: + consumes: + - application/json + description: Login user + parameters: + - description: user data + in: body + name: user + required: true + schema: + $ref: '#/definitions/controllers.LoginRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controllers.EmptyResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/httputil.HTTPError' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/httputil.HTTPError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/httputil.HTTPError' + summary: Login user + tags: + - user + /user/register/{token}: + post: + consumes: + - application/json + description: register user with invite token + parameters: + - description: invite token + in: path + name: token + type: string + - description: user data + in: body + name: user + required: true + schema: + $ref: '#/definitions/controllers.RegisterRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controllers.EmptyResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/httputil.HTTPError' + "404": + description: Not Found + schema: + $ref: '#/definitions/httputil.HTTPError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/httputil.HTTPError' + summary: Register user with invite token + tags: + - user + /user/status: + get: + consumes: + - application/json + description: Get user status of current session + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controllers.EmptyResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/httputil.HTTPError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/httputil.HTTPError' + summary: User Status + tags: + - user +securityDefinitions: + BasicAuth: + type: basic +swagger: "2.0" diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a66c51f --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1775036866, + "narHash": "sha256-ZojAnPuCdy657PbTq5V0Y+AHKhZAIwSIT2cb8UgAz/U=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "6201e203d09599479a3b3450ed24fa81537ebc4e", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7416d3a --- /dev/null +++ b/flake.nix @@ -0,0 +1,36 @@ +{ + description = "A very basic flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + }; + + inputs.utils.url = "github:numtide/flake-utils"; + + outputs = { self, nixpkgs, utils, ... }: + + nixpkgs.lib.attrsets.recursiveUpdate + (utils.lib.eachSystem (utils.lib.defaultSystems) ( system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in rec + { + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + go + gotools + go-swag + ]; + + buildInputs = with pkgs; [ + go + gotools + go-swag + ]; + }; + })) { + + + }; +} + diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..e0e2759 --- /dev/null +++ b/go.mod @@ -0,0 +1,72 @@ +module git.dynamicdiscord.de/harakat/backend + +go 1.25.5 + +require ( + github.com/gin-gonic/gin v1.12.0 + github.com/golang-jwt/jwt/v5 v5.3.1 + github.com/joho/godotenv v1.5.1 + github.com/pdfcpu/pdfcpu v0.11.1 + github.com/swaggo/files v1.0.1 + github.com/swaggo/gin-swagger v1.6.1 + github.com/swaggo/swag v1.16.6 + github.com/swaggo/swag/example/celler v0.0.0-20260319030453-652e82cfb75b + golang.org/x/crypto v0.48.0 + gorm.io/driver/sqlite v1.6.0 + gorm.io/gorm v1.31.1 +) + +require ( + github.com/KyleBanks/depth v1.2.1 // indirect + github.com/PuerkitoBio/purell v1.1.1 // indirect + github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect + github.com/bytedance/gopkg v0.1.3 // indirect + github.com/bytedance/sonic v1.15.0 // indirect + github.com/bytedance/sonic/loader v0.5.0 // indirect + github.com/clipperhouse/uax29/v2 v2.2.0 // indirect + github.com/cloudwego/base64x v0.1.6 // indirect + github.com/gabriel-vasile/mimetype v1.4.12 // indirect + github.com/gin-contrib/sse v1.1.0 // indirect + github.com/go-openapi/jsonpointer v0.19.5 // indirect + github.com/go-openapi/jsonreference v0.19.6 // indirect + github.com/go-openapi/spec v0.20.4 // indirect + github.com/go-openapi/swag v0.19.15 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.30.1 // indirect + github.com/goccy/go-json v0.10.5 // indirect + github.com/goccy/go-yaml v1.19.2 // indirect + github.com/gofrs/uuid v4.2.0+incompatible // indirect + github.com/hhrutter/lzw v1.0.0 // indirect + github.com/hhrutter/pkcs7 v0.2.0 // indirect + github.com/hhrutter/tiff v1.0.2 // indirect + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/jinzhu/now v1.1.5 // indirect + github.com/josharian/intern v1.0.0 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/cpuid/v2 v2.3.0 // indirect + github.com/leodido/go-urn v1.4.0 // indirect + github.com/mailru/easyjson v0.7.6 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mattn/go-runewidth v0.0.19 // indirect + github.com/mattn/go-sqlite3 v1.14.22 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pelletier/go-toml/v2 v2.2.4 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/quic-go/qpack v0.6.0 // indirect + github.com/quic-go/quic-go v0.59.0 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.3.1 // indirect + go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect + golang.org/x/arch v0.22.0 // indirect + golang.org/x/image v0.32.0 // indirect + golang.org/x/mod v0.32.0 // indirect + golang.org/x/net v0.51.0 // indirect + golang.org/x/sync v0.19.0 // indirect + golang.org/x/sys v0.41.0 // indirect + golang.org/x/text v0.34.0 // indirect + golang.org/x/tools v0.41.0 // indirect + google.golang.org/protobuf v1.36.10 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..c8937a0 --- /dev/null +++ b/go.sum @@ -0,0 +1,209 @@ +github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= +github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= +github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI= +github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= +github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M= +github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM= +github.com/bytedance/sonic v1.15.0 h1:/PXeWFaR5ElNcVE84U0dOHjiMHQOwNIx3K4ymzh/uSE= +github.com/bytedance/sonic v1.15.0/go.mod h1:tFkWrPz0/CUCLEF4ri4UkHekCIcdnkqXw9VduqpJh0k= +github.com/bytedance/sonic/loader v0.5.0 h1:gXH3KVnatgY7loH5/TkeVyXPfESoqSBSBEiDd5VjlgE= +github.com/bytedance/sonic/loader v0.5.0/go.mod h1:AR4NYCk5DdzZizZ5djGqQ92eEhCCcdf5x77udYiSJRo= +github.com/clipperhouse/uax29/v2 v2.2.0 h1:ChwIKnQN3kcZteTXMgb1wztSgaU+ZemkgWdohwgs8tY= +github.com/clipperhouse/uax29/v2 v2.2.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM= +github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M= +github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw= +github.com/gabriel-vasile/mimetype v1.4.12/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s= +github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4= +github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk= +github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w= +github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM= +github.com/gin-gonic/gin v1.12.0 h1:b3YAbrZtnf8N//yjKeU2+MQsh2mY5htkZidOM7O0wG8= +github.com/gin-gonic/gin v1.12.0/go.mod h1:VxccKfsSllpKshkBWgVgRniFFAzFb9csfngsqANjnLc= +github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= +github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonreference v0.19.6 h1:UBIxjkht+AWIgYzCDSv2GN+E/togfwXUJFRTWhl2Jjs= +github.com/go-openapi/jsonreference v0.19.6/go.mod h1:diGHMEHg2IqXZGKxqyvWdfWU/aim5Dprw5bqpKkTvns= +github.com/go-openapi/spec v0.20.4 h1:O8hJrt0UMnhHcluhIdUgCLRWyM2x7QkBXRvOs7m+O1M= +github.com/go-openapi/spec v0.20.4/go.mod h1:faYFR1CvsJZ0mNsmsphTMSoRrNV3TEDoAM7FOEWeq8I= +github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM= +github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.30.1 h1:f3zDSN/zOma+w6+1Wswgd9fLkdwy06ntQJp0BBvFG0w= +github.com/go-playground/validator/v10 v10.30.1/go.mod h1:oSuBIQzuJxL//3MelwSLD5hc2Tu889bF0Idm9Dg26cM= +github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= +github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= +github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM= +github.com/goccy/go-yaml v1.19.2/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= +github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZgBrnJfGa0= +github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= +github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY= +github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/hhrutter/lzw v1.0.0 h1:laL89Llp86W3rRs83LvKbwYRx6INE8gDn0XNb1oXtm0= +github.com/hhrutter/lzw v1.0.0/go.mod h1:2HC6DJSn/n6iAZfgM3Pg+cP1KxeWc3ezG8bBqW5+WEo= +github.com/hhrutter/pkcs7 v0.2.0 h1:i4HN2XMbGQpZRnKBLsUwO3dSckzgX142TNqY/KfXg+I= +github.com/hhrutter/pkcs7 v0.2.0/go.mod h1:aEzKz0+ZAlz7YaEMY47jDHL14hVWD6iXt0AgqgAvWgE= +github.com/hhrutter/tiff v1.0.2 h1:7H3FQQpKu/i5WaSChoD1nnJbGx4MxU5TlNqqpxw55z8= +github.com/hhrutter/tiff v1.0.2/go.mod h1:pcOeuK5loFUE7Y/WnzGw20YxUdnqjY1P0Jlcieb/cCw= +github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= +github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y= +github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA= +github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw= +github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs= +github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= +github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/pdfcpu/pdfcpu v0.11.1 h1:htHBSkGH5jMKWC6e0sihBFbcKZ8vG1M67c8/dJxhjas= +github.com/pdfcpu/pdfcpu v0.11.1/go.mod h1:pP3aGga7pRvwFWAm9WwFvo+V68DfANi9kxSQYioNYcw= +github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= +github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8= +github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII= +github.com/quic-go/quic-go v0.59.0 h1:OLJkp1Mlm/aS7dpKgTc6cnpynnD2Xg7C1pwL6vy/SAw= +github.com/quic-go/quic-go v0.59.0/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/swaggo/files v1.0.1 h1:J1bVJ4XHZNq0I46UU90611i9/YzdrF7x92oX1ig5IdE= +github.com/swaggo/files v1.0.1/go.mod h1:0qXmMNH6sXNf+73t65aKeB+ApmgxdnkQzVTAj2uaMUg= +github.com/swaggo/gin-swagger v1.6.1 h1:Ri06G4gc9N4t4k8hekMigJ9zKTFSlqj/9paAQCQs7cY= +github.com/swaggo/gin-swagger v1.6.1/go.mod h1:LQ+hJStHakCWRiK/YNYtJOu4mR2FP+pxLnILT/qNiTw= +github.com/swaggo/swag v1.16.6 h1:qBNcx53ZaX+M5dxVyTrgQ0PJ/ACK+NzhwcbieTt+9yI= +github.com/swaggo/swag v1.16.6/go.mod h1:ngP2etMK5a0P3QBizic5MEwpRmluJZPHjXcMoj4Xesg= +github.com/swaggo/swag/example/celler v0.0.0-20260319030453-652e82cfb75b h1:f1vzEnqO2WzOTNI8chYLp3lnAHcHQsM+PMS4Y+tJ28w= +github.com/swaggo/swag/example/celler v0.0.0-20260319030453-652e82cfb75b/go.mod h1:jgwFcEjW/2uNf0mnTg4shntwCwLhuQyhEHUwq/KrFj8= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/ugorji/go/codec v1.3.1 h1:waO7eEiFDwidsBN6agj1vJQ4AG7lh2yqXyOXqhgQuyY= +github.com/ugorji/go/codec v1.3.1/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE= +go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= +go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= +go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= +golang.org/x/arch v0.22.0 h1:c/Zle32i5ttqRXjdLyyHZESLD/bB90DCU1g9l/0YBDI= +golang.org/x/arch v0.22.0/go.mod h1:dNHoOeKiyja7GTvF9NJS1l3Z2yntpQNzgrjh1cU103A= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts= +golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos= +golang.org/x/image v0.32.0 h1:6lZQWq75h7L5IWNk0r+SCpUJ6tUVd3v4ZHnbRKLkUDQ= +golang.org/x/image v0.32.0/go.mod h1:/R37rrQmKXtO6tYXAjtDLwQgFLHmhW+V6ayXlxzP2Pc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.32.0 h1:9F4d3PHLljb6x//jOyokMv3eX+YDeepZSEo3mFJy93c= +golang.org/x/mod v0.32.0/go.mod h1:SgipZ/3h2Ci89DlEtEXWUk/HteuRin+HHhN+WbNhguU= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo= +golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4= +golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k= +golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk= +golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc= +golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE= +google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/driver/sqlite v1.6.0 h1:WHRRrIiulaPiPFmDcod6prc4l2VGVWHz80KspNsxSfQ= +gorm.io/driver/sqlite v1.6.0/go.mod h1:AO9V1qIQddBESngQUKWL9yoH93HIeA1X6V633rBwyT8= +gorm.io/gorm v1.31.1 h1:7CA8FTFz/gRfgqgpeKIBcervUn3xSyPUmr6B2WXJ7kg= +gorm.io/gorm v1.31.1/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs= diff --git a/main.go b/main.go new file mode 100644 index 0000000..524efa7 --- /dev/null +++ b/main.go @@ -0,0 +1,70 @@ +package main + +import ( + "fmt" + + "github.com/gin-gonic/gin" + "github.com/joho/godotenv" + swaggerFiles "github.com/swaggo/files" + ginSwagger "github.com/swaggo/gin-swagger" + + "git.dynamicdiscord.de/harakat/backend/controllers" + _ "git.dynamicdiscord.de/harakat/backend/docs" + "git.dynamicdiscord.de/harakat/backend/middlewares" + "git.dynamicdiscord.de/harakat/backend/repositories" +) + +var ( + userController controllers.UserController = controllers.NewUserController() + authValidator middlewares.AuthValidator = middlewares.AuthValidator{} +) + +func LoadEnvVariables() { + err := godotenv.Load(".env") + + if err != nil { + fmt.Println("Error loading .env file") + } +} + +// @title Harakat Rest-API +// @version 0.1 +// @description This is harakat backend server. +// @termsOfService TODO + +// @contact.name TODO +// @contact.url TODO +// @contact.email TODO + +// @license.name TODO +// @license.url TODO + +// @host localhost:8080 +// @BasePath /api/v0 + +// @securityDefinitions.basic BasicAuth + +// @externalDocs.description OpenAPI +// @externalDocs.url https://swagger.io/resources/open-api/ +func main() { + LoadEnvVariables() + + repositories.InitRepositories() + + server := gin.New() + server.Use(gin.Recovery()) + server.Use(gin.Logger()) + + // use ginSwagger middleware to serve the API docs + server.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) + + apiRoutes := server.Group("/api/v0", authValidator.OptionalAuth) + { + apiRoutes.POST("/user/login", userController.Login) + apiRoutes.POST("/user/register", userController.InitAdmin) + apiRoutes.POST("/user/register/:token", userController.Register) + apiRoutes.GET("/user/status", userController.Status) + } + + server.Run() +} diff --git a/middlewares/requireAuth.go b/middlewares/requireAuth.go new file mode 100644 index 0000000..bf1c21e --- /dev/null +++ b/middlewares/requireAuth.go @@ -0,0 +1,163 @@ +package middlewares + +import ( + "fmt" + "github.com/gin-gonic/gin" + "github.com/golang-jwt/jwt/v5" + "net/http" + "os" + "time" + + "git.dynamicdiscord.de/harakat/backend/repositories" +) + +type AuthValidator struct { +} + +func (av *AuthValidator) RequireAuth(c *gin.Context) { + // Get Cookie + tokenString, err := c.Cookie("Authorization") + + if err != nil { + c.AbortWithStatus(http.StatusUnauthorized) + return + } + + //Validate + token, err := jwt.Parse(tokenString, func(token *jwt.Token) (any, error) { + // Don't forget to validate the alg is what you expect: + if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok { + return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"]) + } + + // hmacSampleSecret is a []byte containing your secret, e.g. []byte("my_secret_key") + return []byte(os.Getenv("SECRET")), nil + }) + + if err != nil { + c.AbortWithStatus(http.StatusUnauthorized) + return + } + + if claims, ok := token.Claims.(jwt.MapClaims); ok { + //Check Expiration + if float64(time.Now().Unix()) > claims["exp"].(float64) { + //expired + c.AbortWithStatus(http.StatusUnauthorized) + return + } + + //Find user + user, err := repositories.Users.GetById(claims["sub"]) + + if err != nil { + c.AbortWithStatus(http.StatusUnauthorized) + return + } + + //Attach to req + c.Set("user", user) + + // Coninue + c.Next() + return + } + + c.AbortWithStatus(http.StatusUnauthorized) +} + +func (av *AuthValidator) RequireAdmin(c *gin.Context) { + // Get Cookie + tokenString, err := c.Cookie("Authorization") + + if err != nil { + c.AbortWithStatus(http.StatusUnauthorized) + return + } + + //Validate + token, err := jwt.Parse(tokenString, func(token *jwt.Token) (any, error) { + // Don't forget to validate the alg is what you expect: + if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok { + return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"]) + } + + // hmacSampleSecret is a []byte containing your secret, e.g. []byte("my_secret_key") + return []byte(os.Getenv("SECRET")), nil + }) + + if err != nil { + c.AbortWithStatus(http.StatusUnauthorized) + return + } + + if claims, ok := token.Claims.(jwt.MapClaims); ok { + //Check Expiration + if float64(time.Now().Unix()) > claims["exp"].(float64) { + //expired + c.AbortWithStatus(http.StatusUnauthorized) + return + } + + //Find user + user, err := repositories.Users.GetById(claims["sub"]) + + if err != nil { + c.AbortWithStatus(http.StatusUnauthorized) + return + } + + if !user.IsAdmin { + c.AbortWithStatus(http.StatusUnauthorized) + return + } + + //Attach to req + c.Set("user", user) + + // Coninue + c.Next() + return + } + + c.AbortWithStatus(http.StatusUnauthorized) +} + +func (av *AuthValidator) OptionalAuth(c *gin.Context) { + defer c.Next() + + // Get Cookie + tokenString, err := c.Cookie("Authorization") + + if err != nil { + return + } + + //Validate + token, err := jwt.Parse(tokenString, func(token *jwt.Token) (any, error) { + if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok { + return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"]) + } + return []byte(os.Getenv("SECRET")), nil + }) + + if err != nil { + return + } + + if claims, ok := token.Claims.(jwt.MapClaims); ok { + if float64(time.Now().Unix()) > claims["exp"].(float64) { + return + } + + //Find user + user, err := repositories.Users.GetById(claims["sub"]) + + if err != nil { + return + } + + //Attach to req + c.Set("user", user) + } +} diff --git a/models/user.go b/models/user.go new file mode 100644 index 0000000..b646fdc --- /dev/null +++ b/models/user.go @@ -0,0 +1,18 @@ +package models + +import ( + "gorm.io/gorm" +) + +type RegisterToken struct { + gorm.Model + Token string `json:"token" binding:"required" gorm:"unique;not null"` +} + +type User struct { + gorm.Model + Name string `json:"name" binding:"required" gorm:"unique;not null"` + Password string `json:"password" binding:"required" gorm:"not null"` + Email string `json:"email" binding:"required,email" gorm:"unique;not null"` + IsAdmin bool `json:"isAdmin" gorm:"default:false;not null"` +} diff --git a/repositories/registerTokenRepository.go b/repositories/registerTokenRepository.go new file mode 100644 index 0000000..d1c3817 --- /dev/null +++ b/repositories/registerTokenRepository.go @@ -0,0 +1,86 @@ +package repositories + +import ( + "errors" + "fmt" + + "gorm.io/gorm" + + "git.dynamicdiscord.de/harakat/backend/models" + "git.dynamicdiscord.de/harakat/backend/utils" +) + +type RegisterTokenRepository interface { + Create() (models.RegisterToken, error) + GetAll() ([]models.RegisterToken, error) + Exists(string) (bool, error) + Delete(string) error +} + +type GORMRegisterTokenRepository struct { + DB *gorm.DB +} + +func NewGORMRegisterTokenRepository(db *gorm.DB) RegisterTokenRepository { + return &GORMRegisterTokenRepository{ + DB: db, + } +} + +func (t *GORMRegisterTokenRepository) Create() (models.RegisterToken, error) { + token := utils.GenerateToken() + + exists, err := t.Exists(token) + if err != nil { + return models.RegisterToken{}, err + } + + if exists { + return t.Create() + } + + newToken := models.RegisterToken{ + Token: token, + } + result := t.DB.Create(&newToken) + + if result.Error != nil { + return models.RegisterToken{}, result.Error + } + + return newToken, nil +} + +func (t *GORMRegisterTokenRepository) GetAll() ([]models.RegisterToken, error) { + var tokens []models.RegisterToken + result := t.DB.Find(&tokens) + + return tokens, result.Error +} + +func (t *GORMRegisterTokenRepository) Exists(tokenString string) (bool, error) { + var token models.RegisterToken + result := t.DB.First(&token, "token = ?", tokenString) + + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrRecordNotFound) { + return false, nil + } + + return false, result.Error + } + + return true, nil +} + +func (t *GORMRegisterTokenRepository) Delete(token string) error { + result := t.DB.Where("token = ?", token).Delete(&models.RegisterToken{}) + + if result.Error != nil { + return result.Error + } else if result.RowsAffected == 0 { + return fmt.Errorf("Token not found, could not be deleted") + } + + return nil +} diff --git a/repositories/repository.go b/repositories/repository.go new file mode 100644 index 0000000..8502e17 --- /dev/null +++ b/repositories/repository.go @@ -0,0 +1,33 @@ +package repositories + +import ( + "gorm.io/driver/sqlite" + "gorm.io/gorm" + "os" + + "git.dynamicdiscord.de/harakat/backend/models" +) + +var ( + Users UserRepository + Tokens RegisterTokenRepository +) + +func InitRepositories() { + db, err := gorm.Open(sqlite.Open(os.Getenv("SQLITE_DB")), &gorm.Config{}) + if err != nil { + panic("failed to connect to database") + } + + err = db.AutoMigrate( + &models.User{}, + &models.RegisterToken{}, + ) + + if err != nil { + panic("failed to migrate database") + } + + Users = NewGORMUserRepository(db) + Tokens = NewGORMRegisterTokenRepository(db) +} diff --git a/repositories/userRepository.go b/repositories/userRepository.go new file mode 100644 index 0000000..7a1851b --- /dev/null +++ b/repositories/userRepository.go @@ -0,0 +1,71 @@ +package repositories + +import ( + "gorm.io/gorm" + + "git.dynamicdiscord.de/harakat/backend/models" +) + +type UserRepository interface { + Create(models.User) (models.User, error) + GetByEmail(string) (models.User, error) + GetById(interface{}) (models.User, error) + IsEmpty() (bool, error) +} + +type GORMUserRepository struct { + DB *gorm.DB +} + +func NewGORMUserRepository(db *gorm.DB) UserRepository { + return &GORMUserRepository{ + DB: db, + } +} + +func (u *GORMUserRepository) Create(user models.User) (models.User, error) { + result := u.DB.Create(&user) + + if result.Error != nil { + return models.User{}, result.Error + } + + return user, nil +} + +func (u *GORMUserRepository) GetByEmail(email string) (models.User, error) { + var user models.User + result := u.DB.First(&user, "email = ?", email) + + if result.Error != nil { + return models.User{}, result.Error + } + + return user, nil +} + +func (u *GORMUserRepository) GetById(id interface{}) (models.User, error) { + var user models.User + result := u.DB.First(&user, id) + + if result.Error != nil { + return models.User{}, result.Error + } + + return user, nil +} + +func (u *GORMUserRepository) IsEmpty() (bool, error) { + var user models.User + result := u.DB.First(&user) + + if result.Error != nil { + if result.Error == gorm.ErrRecordNotFound { + return true, nil + } else { + return false, result.Error + } + } + + return false, nil +} diff --git a/services/userService.go b/services/userService.go new file mode 100644 index 0000000..766574c --- /dev/null +++ b/services/userService.go @@ -0,0 +1,68 @@ +package services + +import ( + "golang.org/x/crypto/bcrypt" + "os" + "time" + + "github.com/golang-jwt/jwt/v5" + + "git.dynamicdiscord.de/harakat/backend/models" + "git.dynamicdiscord.de/harakat/backend/repositories" +) + +var ( + Users UserService = UserService{} +) + +type UserService struct{} + +func (u *UserService) Register(name string, email string, password string, isAdmin bool) (models.User, error) { + //hash pw + hash, err := bcrypt.GenerateFromPassword([]byte(password), 10) + + if err != nil { + return models.User{}, err + } + + user := models.User{Name: name, Email: email, Password: string(hash), IsAdmin: isAdmin} + _, err = repositories.Users.Create(user) + + if err != nil { + return models.User{}, err + } + + return user, nil +} + +// return jwt tokenstring on success +func (u *UserService) Login(email string, password string) (string, error) { + //lookup requested user + user, err := repositories.Users.GetByEmail(email) + + if err != nil { + return "", err + } + + // compare sent with saved pass + err = bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password)) + + if err != nil { + return "", err + } + + //generate jwt token + token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{ + "sub": user.ID, + "exp": time.Now().Add(time.Hour * 24).Unix(), + }) + + // Sign and get the complete encoded token as a string using the secret + tokenString, err := token.SignedString([]byte(os.Getenv("SECRET"))) + + if err != nil { + return "", err + } + + return tokenString, nil +} diff --git a/test.db b/test.db new file mode 100644 index 0000000..ba14a3a Binary files /dev/null and b/test.db differ diff --git a/utils/utils.go b/utils/utils.go new file mode 100644 index 0000000..2299e37 --- /dev/null +++ b/utils/utils.go @@ -0,0 +1,32 @@ +package utils + +import ( + "crypto/rand" + "encoding/hex" + "fmt" + "github.com/pdfcpu/pdfcpu/pkg/api" +) + +func GenerateSessionId(length int) string { + bytes := make([]byte, length) // 16 bytes = 128 bits + _, err := rand.Read(bytes) + if err != nil { + panic("failed to generate session ID") + } + return hex.EncodeToString(bytes) +} + +func GenerateToken() string { + return GenerateSessionId(16) +} + +func CountPagesAtPath(path string) (pages int) { + ctx, err := api.ReadContextFile(path) + if err != nil { + fmt.Println("Error reading PDF:", err) + return + } + + pages = ctx.PageCount + return +}