github.com/EngineerKamesh/gofullstack@v0.0.0-20180609171605-d41341d7d4ee/volume3/section5/gopherface/models/user.go (about)

     1  package models
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/EngineerKamesh/gofullstack/volume3/section5/gopherface/common/utility"
     7  )
     8  
     9  type User struct {
    10  	UUID              string `json:"uuid" bson:"uuid"`
    11  	Username          string `json:"username" bson:"username"`
    12  	FirstName         string `json:"firstName" bson:"firstName"`
    13  	LastName          string `json:"lastName" bson:"lastName"`
    14  	Email             string `json:"email" bson:"email"`
    15  	PasswordHash      string `json:"passwordHash" bson:"passwordHash"`
    16  	TimestampCreated  int64  `json:"timestampCreated" bson:"timestampCreated"`
    17  	TimestampModified int64  `json:"timestampModified" bson:"timestampModified"`
    18  }
    19  
    20  func NewUser(username string, firstName string, lastName string, email string, password string) *User {
    21  
    22  	passwordHash := utility.SHA256OfString(password)
    23  	now := time.Now()
    24  	unixTimestamp := now.Unix()
    25  	u := User{UUID: utility.GenerateUUID(), Username: username, FirstName: firstName, LastName: lastName, Email: email, PasswordHash: passwordHash, TimestampCreated: unixTimestamp}
    26  	return &u
    27  }