Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature onboarding user #34

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions api/controllers/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,37 @@ func DeleteUser(c *gin.Context) error {
})
return nil
}

// 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 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
}
26 changes: 14 additions & 12 deletions api/data/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ 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"},
{Id: 1, FirstName: "user", LastName: "user", Email: "user@example.com", Password: "user", Role: "user", Language: "en"},
{Id: 2, FirstName: "Kilian", LastName: "Smith", Email: "kilian@example.com", Password: "Kilian", Role: "admin", Language: "en"},
{Id: 3, FirstName: "Cedric", LastName: "Johnson", Email: "cedric@example.com", Password: "Cedric", Role: "admin", Language: "en"},
{Id: 4, FirstName: "Johann", LastName: "Brown", Email: "johann@example.com", Password: "Johann", Role: "admin", Language: "en"},
{Id: 5, FirstName: "Romain", LastName: "Davis", Email: "romain@example.com", Password: "Romain", Role: "admin", Language: "en"},
{Id: 6, FirstName: "Alex", LastName: "Wilson", Email: "alex@example.com", Password: "Alex", Role: "admin", Language: "en"},
{Id: 7, FirstName: "Mickael", LastName: "Taylor", Email: "mickael@example.com", Password: "Mickael", Role: "admin", Language: "en"},
{Id: 8, FirstName: "Mickael", LastName: "Thomas", Email: "mickael1@example.com", Password: "Mickael", Role: "admin", Language: "en"},
{Id: 9, FirstName: "Mickael", LastName: "Robinson", Email: "mickael2@example.com", Password: "Mickael", Role: "admin", Language: "en"},
{Id: 10, FirstName: "Mickael", LastName: "Clark", Email: "mickael3@example.com", Password: "Mickael", Role: "admin", Language: "en"},
}
{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},
Expand Down
11 changes: 11 additions & 0 deletions api/database/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions api/database/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -31,3 +34,4 @@ func AddLocation(location models.Location) error {
func DeleteLocation(id int) error {
return DeleteLocationFromFile(id)
}

67 changes: 46 additions & 21 deletions api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}",
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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: "{{",
Expand Down
63 changes: 42 additions & 21 deletions api/docs/swagger.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -400,15 +422,14 @@
},
"role": {
"type": "string"
},
"status": {
"type": "string"
},
"videopath": {
"type": "string"
}
}
}
},
"securityDefinitions": {
"Bearer": {
"type": "apiKey",
"name": "Authorization",
"in": "header"
}
}
}
45 changes: 28 additions & 17 deletions api/docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
basePath: /
definitions:
models.Authentication:
properties:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
2 changes: 1 addition & 1 deletion api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions api/models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package models

type User struct {
Id int `json:"id" bson:"id"`
FirstName string `json:"firstname" bson:"firstname"`
FirstName string `json:"firstname" bson:"firstname"`
LastName string `json:"lastname" bson:"lastname"`
Email string `json:"email" bson:"email"`
Password string `json:"password" bson:"password"`
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 {
Expand Down
6 changes: 6 additions & 0 deletions api/routers/http/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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
Expand Down
Loading
Loading