Skip to content

Commit

Permalink
move authenticate handler to users
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Lin committed Jul 30, 2018
1 parent 1d348b7 commit 2ec1fa2
Show file tree
Hide file tree
Showing 15 changed files with 691 additions and 158 deletions.
245 changes: 199 additions & 46 deletions API.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Vortex API

## Table of Contents
* [User](#user)
+ [Sign Up](#signup)
+ [Sign In](#signin)
+ [Create User](#create-user)
+ [List User](#list-user)
+ [Get User](#get-user)
+ [Delete User](#delete-user)
* [Network](#network)
+ [Create Network](#create-network)
+ [List Network](#list-network)
Expand Down Expand Up @@ -40,48 +47,205 @@



## Network
## User

### Create Network
### Signup

**POST /v1/networks**
**POST /v1/user/signup**

No need to give a role, server will assign a "user" role.

Example:

```json
{
"loginCredential":{
"email":"[email protected]",
"password":"password"
},
"username":"John Doe",
"firstName":"John",
"lastName":"Doe",
"phoneNumber":"0911111111"
}
```
curl -X POST \
http://172.17.8.100:7890/v1/networks \
-H 'Content-Type: application/json' \
-d '{
"type":"system",
"isDPDKPort":false,
"name":"my network-3",
"vlanTags":[
100,
200
],
"routes":[
{
"dstCIDR":"224.0.0.0/4",
"gateway":"0.0.0.0"
}
],
"bridgeName":"ovsbr0",
"nodes":[
{
"name":"vortex-dev",
"physicalInterfaces":[
{
"name":"eth0",
"pciID":""
}
]
}
]

Response Data:

```json
{
"id": "5b5b418c760aab15e771bde2",
"uuid": "44b4646a-d009-457c-9fdd-1cc0bf226543",
"jwt": "",
"loginCredential": {
"email": "[email protected]",
"password": "$2a$14$XO4OOUCaiTNQHm.ZTzHU5..WwtP2ec2Q2HPPQuMHP1WoXCjXiRrxa"
},
"username": "John Doe",
"role": "user",
"firstName": "John",
"lastName": "Doe",
"phoneNumber": "0911111111",
"createdAt": "2018-07-28T00:00:12.632011379+08:00"
}
```

### Signin

**POST /v1/users/signin**

Example:

```json
{
"email":"[email protected]",
"password":"password"
}
'
```

Response Data:

```json
{
"error": false,
"message": "MY_JWT_TOKEN"
}
```


### Create User

**POST /v1/user**

Example:

role can only be "root", "user", "guest".
```json
{
"loginCredential":{
"email":"[email protected]",
"password":"password"
},
"role": "guest",
"username":"John Doe",
"firstName":"John",
"lastName":"Doe",
"phoneNumber":"0911111111"
}
```

Response Data:

```json
{
"id": "5b5b418c760aab15e771bde2",
"uuid": "44b4646a-d009-457c-9fdd-1cc0bf226543",
"jwt": "",
"loginCredential": {
"email": "[email protected]",
"password": "$2a$14$XO4OOUCaiTNQHm.ZTzHU5..WwtP2ec2Q2HPPQuMHP1WoXCjXiRrxa"
},
"username": "John Doe",
"role": "guest",
"firstName": "John",
"lastName": "Doe",
"phoneNumber": "0911111111",
"createdAt": "2018-07-28T00:00:12.632011379+08:00"
}
```

### List User

Request

```
GET /v1/users
```


Response Data:

```json
[
{
"id": "5b5b4173760aab15e771bde0",
"uuid": "52870ee9-4bfd-44ea-8cca-a9ce7826b1bd",
"jwt": "",
"loginCredential": {
"email": "[email protected]",
"password": "$2a$14$CQasyFUsBuqwmmpk/i9t9.9j2BTyPzK3PyWATMgb/7g8do57c9oHe"
},
"username": "John Doe",
"role": "root",
"firstName": "John",
"lastName": "Doe",
"phoneNumber": "0911111111",
"createdAt": "2018-07-27T23:59:47.564+08:00"
},
{
"id": "5b5b4184760aab15e771bde1",
"uuid": "a4604f7d-06a8-4226-9792-765e72b14f9c",
"jwt": "",
"loginCredential": {
"email": "[email protected]",
"password": "$2a$14$SzULcUvWqsCy6XeelPdsRutCDJkdsrM4mi2HXpXPEaEugV.jJsMNC"
},
"username": "John Doe",
"role": "user",
"firstName": "John",
"lastName": "Doe",
"phoneNumber": "0911111111",
"createdAt": "2018-07-28T00:00:04.261+08:00"
},
{
"id": "5b5b418c760aab15e771bde2",
"uuid": "44b4646a-d009-457c-9fdd-1cc0bf226543",
"jwt": "",
"loginCredential": {
"email": "[email protected]",
"password": "$2a$14$XO4OOUCaiTNQHm.ZTzHU5..WwtP2ec2Q2HPPQuMHP1WoXCjXiRrxa"
},
"username": "John Doe",
"role": "guest",
"firstName": "John",
"lastName": "Doe",
"phoneNumber": "0911111111",
"createdAt": "2018-07-28T00:00:12.632+08:00"
}
]
```

### Get User

TODO


### Delete User

Request

```
DELETE /v1/users/5b5aba2d7a3172bca6f1e280
```

Response Data

``` json
{
"error": false,
"message": "User Deleted Success"
}
```


## Network

### Create Network

**POST /v1/networks**

Example:

Request Data:

```json
Expand Down Expand Up @@ -277,12 +441,6 @@ In the NFS server, there're two parametes we need to provide, the `server IP add

Example:

```
curl -X POST -H "Content-Type: application/json" \
-d '{"type":"nfs","name":"My First Storage","ip":"172.17.8.100","path":"/nfs"}' \
http://localhost:7890/v1/storage
```

Request Data:
```json
{
Expand All @@ -291,7 +449,7 @@ Request Data:
"ip":"172.17.8.100",
"path":"/nfs"
}

```
Response Data:

```json
Expand Down Expand Up @@ -364,12 +522,6 @@ capacity: The capacity of the volume,

Example:

```
curl -X POST -H "Content-Type: application/json" \
-d '{"storageName":"My First Storage","name":"My Log","accessMode":"ReadWriteMany","capacity":"300Gi"}' \
http://localhost:7890/v1/storage
```

Request Data:
```json
{
Expand All @@ -378,6 +530,7 @@ Request Data:
"accessMode":"ReadWriteMany",
"capacity":"300Gi"
}
```

Response Data:

Expand Down
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
SERVER_VERSION = v0.1.6
## Folder content generated files
BUILD_FOLDER = ./build
UNAME := $(shell uname)

PROJECT_URL = github.com/linkernetworks/vortex
## command
GO = go
GO_VENDOR = govendor
MKDIR_P = mkdir -p

## Random Alphanumeric String
SECRET_KEY = $(shell cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)

## UNAME
UNAME := $(shell uname)

################################################

.PHONY: all
Expand Down Expand Up @@ -46,7 +51,9 @@ govendor-sync:
src.build:
$(GO) build -v ./src/...
$(MKDIR_P) $(BUILD_FOLDER)/src/cmd/vortex/
$(GO) build -v -o $(BUILD_FOLDER)/src/cmd/vortex/vortex -ldflags="-X github.com/linkernetworks/vortex/src/version.version=$(SERVER_VERSION)" ./src/cmd/vortex/...
$(GO) build -v -o $(BUILD_FOLDER)/src/cmd/vortex/vortex \
-ldflags="-X $(PROJECT_URL)/src/version.version=$(SERVER_VERSION) -X $(PROJECT_URL)/src/server/backend.SecretKey=$(SECRET_KEY)" \
./src/cmd/vortex/...

.PHONY: src.test
src.test:
Expand Down
2 changes: 1 addition & 1 deletion config/local.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
"version": "local",
"logFileName": "access_log"
}
}
}
27 changes: 16 additions & 11 deletions src/entity/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package entity
import (
"time"

"github.com/satori/go.uuid"
"gopkg.in/mgo.v2/bson"
)

Expand All @@ -12,18 +11,24 @@ const (
UserCollectionName string = "users"
)

// LoginCredential is the structure for a user login credential
type LoginCredential struct {
Email string `bson:"email" json:"email" validate:"required,email"`
Password string `bson:"password" json:"password" validate:"required"`
}

// User is the structure for user info
type User struct {
ID bson.ObjectId `bson:"_id,omitempty" json:"id" validate:"-"`
UUID uuid.UUID `bson:"uuid" json:"uuid" validate:"required"`
JWT string `bson:"jwt" json:"jwt" validate:"-"`
Username string `bson:"username" json:"username" validate:"required"`
Email string `bson:"email" json:"email" validate:"required,email"`
Password string `bson:"password" json:"password" validate:"required"`
FirstName string `bson:"firstname" json:"firstName" validate:"required"`
LastName string `bson:"lastName" json:"lastName" validate:"required"`
PhoneNumber string `bson:"phoneNumber" json:"phoneNumber" validate:"required,numeric"`
CreatedAt *time.Time `bson:"createdAt,omitempty" json:"createdAt,omitempty" validate:"-"`
ID bson.ObjectId `bson:"_id,omitempty" json:"id" validate:"-"`
UUID string `bson:"uuid" json:"uuid" validate:"required,uuid4"`
JWT string `bson:"jwt" json:"jwt" validate:"-"`
LoginCredential LoginCredential `bson:"loginCredential" json:"loginCredential" validate:"required"`
Username string `bson:"username" json:"username" validate:"required"`
Role string `bson:"role" json:"role" validate:"required,eq=root|eq=user|eq=guest"`
FirstName string `bson:"firstname" json:"firstName" validate:"required"`
LastName string `bson:"lastName" json:"lastName" validate:"required"`
PhoneNumber string `bson:"phoneNumber" json:"phoneNumber" validate:"required,numeric"`
CreatedAt *time.Time `bson:"createdAt,omitempty" json:"createdAt,omitempty" validate:"-"`
}

// GetCollection - get model mongo collection name.
Expand Down
Loading

0 comments on commit 2ec1fa2

Please sign in to comment.