daily pastebin goal
28%
SHARE
TWEET

Untitled

a guest Mar 25th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Create : func creating user
  2. func (users *Users) Create() map[string]interface{} {
  3.  
  4.     if resp, ok := users.Validate(); !ok {
  5.         return resp
  6.     }
  7.     hashedPassword, _ := bcrypt.GenerateFromPassword([]byte(users.Password), bcrypt.DefaultCost)
  8.     // hashedPassword, _ := getPasswordHash(users)
  9.     users.Password = string(hashedPassword)
  10.     users.Role = "member"
  11.     //Create new JWT token for the newly registered user
  12.     tk := &Token{UserID: users.ID}
  13.     token := jwt.NewWithClaims(jwt.GetSigningMethod("HS256"), tk)
  14.     tokenString, _ := token.SignedString([]byte(os.Getenv("token_password")))
  15.     users.Token = tokenString
  16.     GetDB().Create(users)
  17.     if users.ID <= 0 {
  18.         return u.Message(false, "Failed to create user, connection error.")
  19.     }
  20.  
  21.     users.Token = tokenString
  22.     users.Password = "" //delete password
  23.     response := u.Message(true, "Account has been created")
  24.     response["users"] = users
  25.     return response
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top