diff --git a/api/controllers/users.go b/api/controllers/users.go index d9fbd69..b74b9da 100644 --- a/api/controllers/users.go +++ b/api/controllers/users.go @@ -156,11 +156,34 @@ func DeleteUser(c *gin.Context) error { // user godoc // @Router /api/users/onboard [post] +// @in header // @ID onboardUser // @Tags users // @Summary Onboard a user using a fingerprint and a video -// @Description Onboard a user using a fingerprint and a video -// @Success 200 +// @Description Onboard a user using a fingerprint and a videossss +// @Accept json +// @Produce json +// @Param user body models.User true "User data" +// @Success 201 {object} models.User func OnboardUser(c *gin.Context) error { + var user models.User + if err := c.ShouldBindJSON(&user); err != nil { + c.JSON(400, gin.H{ + "error": "Invalid user data", + }) + return err + } + + if err := database.OnboardUser(user); err != nil { + c.JSON(500, gin.H{ + "error": "Failed to onboard user", + }) + return err + } + + c.JSON(201, gin.H{ + "message": "User onboarded successfully", + "user": user, + }) return nil } diff --git a/api/data/main.go b/api/data/main.go index 23b976b..aa581d9 100644 --- a/api/data/main.go +++ b/api/data/main.go @@ -7,19 +7,22 @@ import ( "github.com/uug-ai/facial-access-control/api/utils" ) + var Users = []models.User{ - {Id: 0, FirstName: "admin", LastName: "admin", Email: "admin@example.com", Password: "admin", Role: "admin", Language: "en", Status: "pending"}, - {Id: 1, FirstName: "user", LastName: "user", Email: "user@example.com", Password: "user", Role: "user", Language: "en", Status: "invited"}, - {Id: 2, FirstName: "Kilian", LastName: "Smith", Email: "kilian@example.com", Password: "Kilian", Role: "admin", Language: "en", Status: "onboarded"}, - {Id: 3, FirstName: "Cedric", LastName: "Johnson", Email: "cedric@example.com", Password: "Cedric", Role: "admin", Language: "en", Status: "pending"}, - {Id: 4, FirstName: "Johann", LastName: "Brown", Email: "johann@example.com", Password: "Johann", Role: "admin", Language: "en", Status: "invited"}, - {Id: 5, FirstName: "Romain", LastName: "Davis", Email: "romain@example.com", Password: "Romain", Role: "admin", Language: "en", Status: "onboarded"}, - {Id: 6, FirstName: "Alex", LastName: "Wilson", Email: "alex@example.com", Password: "Alex", Role: "admin", Language: "en", Status: "pending"}, - {Id: 7, FirstName: "Mickael", LastName: "Taylor", Email: "mickael@example.com", Password: "Mickael", Role: "admin", Language: "en", Status: "invited"}, - {Id: 8, FirstName: "Mickael", LastName: "Thomas", Email: "mickael1@example.com", Password: "Mickael", Role: "admin", Language: "en", Status: "onboarded"}, - {Id: 9, FirstName: "Mickael", LastName: "Robinson", Email: "mickael2@example.com", Password: "Mickael", Role: "admin", Language: "en", Status: "pending"}, - {Id: 10, FirstName: "Mickael", LastName: "Clark", Email: "mickael3@example.com", Password: "Mickael", Role: "admin", Language: "en", Status: "invited"}, -} + {Id: 0, FirstName: "admin", LastName: "admin", Email: "admin@example.com", Password: "admin", Role: "admin", Language: "en", Status: "pending", VideoPath: ""}, + {Id: 1, FirstName: "user", LastName: "user", Email: "user@example.com", Password: "user", Role: "user", Language: "en", Status: "invited", VideoPath: "/"}, + {Id: 2, FirstName: "Kilian", LastName: "Smith", Email: "kilian@example.com", Password: "Kilian", Role: "admin", Language: "en", Status: "onboarded", VideoPath: "/path/to/kilian-video.mp4"}, + {Id: 3, FirstName: "Cedric", LastName: "Johnson", Email: "cedric@example.com", Password: "Cedric", Role: "admin", Language: "en", Status: "pending", VideoPath: ""}, + {Id: 4, FirstName: "Johann", LastName: "Brown", Email: "johann@example.com", Password: "Johann", Role: "admin", Language: "en", Status: "invited", VideoPath: ""}, + {Id: 5, FirstName: "Romain", LastName: "Davis", Email: "romain@example.com", Password: "Romain", Role: "admin", Language: "en", Status: "onboarded", VideoPath: "/path/to/romain-video.mp4"}, + {Id: 6, FirstName: "Alex", LastName: "Wilson", Email: "alex@example.com", Password: "Alex", Role: "admin", Language: "en", Status: "pending", VideoPath: ""}, + {Id: 7, FirstName: "Mickael", LastName: "Taylor", Email: "mickael@example.com", Password: "Mickael", Role: "admin", Language: "en", Status: "invited", VideoPath: ""}, + {Id: 8, FirstName: "Mickael", LastName: "Thomas", Email: "mickael1@example.com", Password: "Mickael", Role: "admin", Language: "en", Status: "onboarded", VideoPath: "/path/to/mickael1-video.mp4"}, + {Id: 9, FirstName: "Mickael", LastName: "Robinson", Email: "mickael2@example.com", Password: "Mickael", Role: "admin", Language: "en", Status: "pending", VideoPath: ""}, + {Id: 10, FirstName: "Mickael", LastName: "Clark", Email: "mickael3@example.com", Password: "Mickael", Role: "admin", Language: "en", Status: "invited", VideoPath: ""}, + + } + var Locations = []models.Location{ {Id: 1, Name: "Location 1", Address: "Address 1", Lat: 1.0, Lng: 1.0}, {Id: 2, Name: "Location 2", Address: "Address 2", Lat: 2.0, Lng: 2.0}, diff --git a/api/database/file.go b/api/database/file.go index c0b852a..72fe865 100644 --- a/api/database/file.go +++ b/api/database/file.go @@ -71,6 +71,17 @@ func DeleteUserFromFile(id int) error { return errors.New("user not found") } +func OnboardUserToFile(user models.User) error { + if(user.Status == "onboarded") { + return errors.New("user already onboarded") + } + if(user.Status != "invited") { + return errors.New("user must be invited before onboarding") + } + data.Users[user.Id] = user + data.Users[user.Id].Status = "onboarded" + return nil; +} func GetLocationsFromFile() []models.Location { locations := data.Locations diff --git a/api/database/main.go b/api/database/main.go index 3d0e3f2..b3bbd53 100644 --- a/api/database/main.go +++ b/api/database/main.go @@ -19,6 +19,9 @@ func AddUser(user models.User) error { func DeleteUser(id int) error { return DeleteUserFromFile(id) } +func OnboardUser(user models.User) error { + return OnboardUserToFile(user) +} func GetLocations() []models.Location { return GetLocationsFromFile() } @@ -31,3 +34,4 @@ func AddLocation(location models.Location) error { func DeleteLocation(id int) error { return DeleteLocationFromFile(id) } + diff --git a/api/docs/docs.go b/api/docs/docs.go index 7f2d9c4..9acf675 100644 --- a/api/docs/docs.go +++ b/api/docs/docs.go @@ -9,16 +9,7 @@ const docTemplate = `{ "info": { "description": "{{escape .Description}}", "title": "{{.Title}}", - "termsOfService": "https://kerberos.io", - "contact": { - "name": "API Support", - "url": "https://www.kerberos.io", - "email": "support@kerberos.io" - }, - "license": { - "name": "Apache 2.0 - Commons Clause", - "url": "http://www.apache.org/licenses/LICENSE-2.0.html" - }, + "contact": {}, "version": "{{.Version}}" }, "host": "{{.Host}}", @@ -240,6 +231,41 @@ const docTemplate = `{ } } }, + "/api/users/onboard": { + "post": { + "description": "Onboard a user using a fingerprint and a videossss", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "users" + ], + "summary": "Onboard a user using a fingerprint and a video", + "operationId": "onboardUser", + "parameters": [ + { + "description": "User data", + "name": "user", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.User" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/models.User" + } + } + } + } + }, "/api/users/{email}": { "get": { "security": [ @@ -407,27 +433,26 @@ const docTemplate = `{ }, "role": { "type": "string" + }, + "status": { + "type": "string" + }, + "videopath": { + "type": "string" } } } - }, - "securityDefinitions": { - "Bearer": { - "type": "apiKey", - "name": "Authorization", - "in": "header" - } } }` // SwaggerInfo holds exported Swagger Info so clients can modify it var SwaggerInfo = &swag.Spec{ - Version: "1.0", + Version: "", Host: "", - BasePath: "/", + BasePath: "", Schemes: []string{}, - Title: "Swagger Kerberos Agent API", - Description: "This is the API for using and configuring Kerberos Agent.", + Title: "", + Description: "", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, LeftDelim: "{{", diff --git a/api/docs/swagger.json b/api/docs/swagger.json index e64a2aa..7f90634 100644 --- a/api/docs/swagger.json +++ b/api/docs/swagger.json @@ -1,21 +1,8 @@ { "swagger": "2.0", "info": { - "description": "This is the API for using and configuring Kerberos Agent.", - "title": "Swagger Kerberos Agent API", - "termsOfService": "https://kerberos.io", - "contact": { - "name": "API Support", - "url": "https://www.kerberos.io", - "email": "support@kerberos.io" - }, - "license": { - "name": "Apache 2.0 - Commons Clause", - "url": "http://www.apache.org/licenses/LICENSE-2.0.html" - }, - "version": "1.0" + "contact": {} }, - "basePath": "/", "paths": { "/api/locations": { "get": { @@ -233,6 +220,41 @@ } } }, + "/api/users/onboard": { + "post": { + "description": "Onboard a user using a fingerprint and a videossss", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "users" + ], + "summary": "Onboard a user using a fingerprint and a video", + "operationId": "onboardUser", + "parameters": [ + { + "description": "User data", + "name": "user", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.User" + } + } + ], + "responses": { + "201": { + "description": "Created", + "schema": { + "$ref": "#/definitions/models.User" + } + } + } + } + }, "/api/users/{email}": { "get": { "security": [ @@ -400,15 +422,14 @@ }, "role": { "type": "string" + }, + "status": { + "type": "string" + }, + "videopath": { + "type": "string" } } } - }, - "securityDefinitions": { - "Bearer": { - "type": "apiKey", - "name": "Authorization", - "in": "header" - } } } \ No newline at end of file diff --git a/api/docs/swagger.yaml b/api/docs/swagger.yaml index a698b1a..453835b 100644 --- a/api/docs/swagger.yaml +++ b/api/docs/swagger.yaml @@ -1,4 +1,3 @@ -basePath: / definitions: models.Authentication: properties: @@ -49,19 +48,13 @@ definitions: type: string role: type: string + status: + type: string + videopath: + type: string type: object info: - contact: - email: support@kerberos.io - name: API Support - url: https://www.kerberos.io - description: This is the API for using and configuring Kerberos Agent. - license: - name: Apache 2.0 - Commons Clause - url: http://www.apache.org/licenses/LICENSE-2.0.html - termsOfService: https://kerberos.io - title: Swagger Kerberos Agent API - version: "1.0" + contact: {} paths: /api/locations: get: @@ -256,9 +249,27 @@ paths: summary: Get user tags: - users -securityDefinitions: - Bearer: - in: header - name: Authorization - type: apiKey + /api/users/onboard: + post: + consumes: + - application/json + description: Onboard a user using a fingerprint and a videossss + operationId: onboardUser + parameters: + - description: User data + in: body + name: user + required: true + schema: + $ref: '#/definitions/models.User' + produces: + - application/json + responses: + "201": + description: Created + schema: + $ref: '#/definitions/models.User' + summary: Onboard a user using a fingerprint and a video + tags: + - users swagger: "2.0" diff --git a/api/go.mod b/api/go.mod index b8ebf3a..a818dc8 100644 --- a/api/go.mod +++ b/api/go.mod @@ -43,7 +43,7 @@ require ( github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect golang.org/x/arch v0.7.0 // indirect - golang.org/x/crypto v0.23.0 // indirect + golang.org/x/crypto v0.23.0 // direct golang.org/x/net v0.25.0 // indirect golang.org/x/sys v0.20.0 // indirect golang.org/x/text v0.15.0 // indirect diff --git a/api/models/user.go b/api/models/user.go index cf41bbc..864c52f 100644 --- a/api/models/user.go +++ b/api/models/user.go @@ -9,6 +9,7 @@ type User struct { Role string `json:"role" bson:"role"` Language string `json:"language" bson:"language"` Status string `json:"status" bson:"status"` + VideoPath string `json:"videopath" bson:"videopath"` } type Authentication struct { diff --git a/api/routers/http/routes.go b/api/routers/http/routes.go index 4768928..2f3178a 100644 --- a/api/routers/http/routes.go +++ b/api/routers/http/routes.go @@ -12,6 +12,10 @@ func AddRoutes(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware) *gin.RouterG { api.POST("/login", authMiddleware.LoginHandler) + api.POST("/users/onboard", func(c *gin.Context) { + controllers.OnboardUser(c) + }) + // Secured endpoints.. api.Use(authMiddleware.MiddlewareFunc()) { @@ -37,6 +41,8 @@ func AddRoutes(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware) *gin.RouterG api.DELETE("/users/:id", func(c *gin.Context) { controllers.DeleteUser(c) }) + + // End users // Locations