Skip to content

Commit

Permalink
remove uuid and jwt
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Lin committed Aug 22, 2018
1 parent 1f8d235 commit 57f09d0
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 20 deletions.
2 changes: 0 additions & 2 deletions src/entity/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ type LoginCredential struct {
// User is the structure for user info
type User struct {
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"`
DisplayName string `bson:"displayName" json:"displayName" validate:"required"`
Role string `bson:"role" json:"role" validate:"required,eq=root|eq=user|eq=guest"`
Expand Down
4 changes: 2 additions & 2 deletions src/server/backend/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// GenerateToken is for generating token
func GenerateToken(userUUID string, role string) (string, error) {
func GenerateToken(userID string, role string) (string, error) {
token := jwt.New(jwt.SigningMethodHS256)
token.Claims = jwt.MapClaims{
// issuer of the claim
Expand All @@ -17,7 +17,7 @@ func GenerateToken(userUUID string, role string) (string, error) {
// user role
"role": role,
// the subject of this token. This is the user associated with the relevant action
"sub": userUUID,
"sub": userID,
}
return token.SignedString([]byte(SecretKey))
}
4 changes: 2 additions & 2 deletions src/server/backend/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"gopkg.in/mgo.v2/bson"
)

func FindUserByUUID(session *mongo.Session, uuid string) (entity.User, error) {
func FindUserByID(session *mongo.Session, ID bson.ObjectId) (entity.User, error) {
var user entity.User
if err := session.FindOne(
entity.UserCollectionName,
bson.M{"uuid": uuid},
bson.M{"_id": ID},
&user,
); err != nil {
return entity.User{}, err
Expand Down
4 changes: 2 additions & 2 deletions src/server/handler_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

func createNetworkHandler(ctx *web.Context) {
sp, req, resp := ctx.ServiceProvider, ctx.Request, ctx.Response
uuid, ok := req.Attribute("UserID").(string)
mgoID, ok := req.Attribute("UserID").(string)
if !ok {
response.Unauthorized(req.Request, resp.ResponseWriter, fmt.Errorf("Unauthorized: User ID is empty"))
return
Expand Down Expand Up @@ -63,7 +63,7 @@ func createNetworkHandler(ctx *web.Context) {
network.ID = bson.NewObjectId()
network.CreatedAt = timeutils.Now()
// create by who
user, err := backend.FindUserByUUID(session, uuid)
user, err := backend.FindUserByID(session, bson.ObjectId(mgoID))
if err != nil {
switch err {
case mgo.ErrNotFound:
Expand Down
4 changes: 2 additions & 2 deletions src/server/handler_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

func createPodHandler(ctx *web.Context) {
sp, req, resp := ctx.ServiceProvider, ctx.Request, ctx.Response
uuid, ok := req.Attribute("UserID").(string)
mgoID, ok := req.Attribute("UserID").(string)
if !ok {
response.Unauthorized(req.Request, resp.ResponseWriter, fmt.Errorf("Unauthorized: User ID is empty"))
return
Expand Down Expand Up @@ -62,7 +62,7 @@ func createPodHandler(ctx *web.Context) {
return
}
// create by who
user, err := backend.FindUserByUUID(session, uuid)
user, err := backend.FindUserByID(session, bson.ObjectId(mgoID))
if err != nil {
switch err {
case mgo.ErrNotFound:
Expand Down
4 changes: 2 additions & 2 deletions src/server/handler_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

func createServiceHandler(ctx *web.Context) {
sp, req, resp := ctx.ServiceProvider, ctx.Request, ctx.Response
uuid, ok := req.Attribute("UserID").(string)
mgoID, ok := req.Attribute("UserID").(string)
if !ok {
response.Unauthorized(req.Request, resp.ResponseWriter, fmt.Errorf("Unauthorized: User ID is empty"))
return
Expand Down Expand Up @@ -58,7 +58,7 @@ func createServiceHandler(ctx *web.Context) {
return
}
// create by who
user, err := backend.FindUserByUUID(session, uuid)
user, err := backend.FindUserByID(session, bson.ObjectId(mgoID))
if err != nil {
switch err {
case mgo.ErrNotFound:
Expand Down
7 changes: 1 addition & 6 deletions src/server/handler_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/linkernetworks/vortex/src/server/backend"
"github.com/linkernetworks/vortex/src/web"

"github.com/satori/go.uuid"
mgo "gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
)
Expand All @@ -28,8 +27,6 @@ func signUpUserHandler(ctx *web.Context) {
return
}

user.UUID = uuid.Must(uuid.NewV4()).String()

encryptedPassword, err := backend.HashPassword(user.LoginCredential.Password)
if err != nil {
response.BadRequest(req.Request, resp.ResponseWriter, err)
Expand Down Expand Up @@ -105,7 +102,7 @@ func signInUserHandler(ctx *web.Context) {
}

// Passed
tokenString, err := backend.GenerateToken(authenticatedUser.UUID, authenticatedUser.Role)
tokenString, err := backend.GenerateToken(authenticatedUser.ID.Hex(), authenticatedUser.Role)
if err != nil {
response.InternalServerError(req.Request, resp.ResponseWriter, err)
return
Expand All @@ -126,8 +123,6 @@ func createUserHandler(ctx *web.Context) {
return
}

user.UUID = uuid.Must(uuid.NewV4()).String()

encryptedPassword, err := backend.HashPassword(user.LoginCredential.Password)
if err != nil {
response.BadRequest(req.Request, resp.ResponseWriter, err)
Expand Down
4 changes: 2 additions & 2 deletions src/server/handler_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

func createVolume(ctx *web.Context) {
sp, req, resp := ctx.ServiceProvider, ctx.Request, ctx.Response
uuid, ok := req.Attribute("UserID").(string)
mgoID, ok := req.Attribute("UserID").(string)
if !ok {
response.Unauthorized(req.Request, resp.ResponseWriter, fmt.Errorf("Unauthorized: User ID is empty"))
return
Expand Down Expand Up @@ -57,7 +57,7 @@ func createVolume(ctx *web.Context) {
}
}
// create by who
user, err := backend.FindUserByUUID(session, uuid)
user, err := backend.FindUserByID(session, bson.ObjectId(mgoID))
if err != nil {
switch err {
case mgo.ErrNotFound:
Expand Down

0 comments on commit 57f09d0

Please sign in to comment.