Skip to content

Instantly share code, notes, and snippets.

@muhammadqazi
Created February 6, 2022 10:50
Show Gist options
  • Save muhammadqazi/be14c1ca550149cc694274db3b1af9f8 to your computer and use it in GitHub Desktop.
Save muhammadqazi/be14c1ca550149cc694274db3b1af9f8 to your computer and use it in GitHub Desktop.
Go-Authentication
func HandleDatabaseInsert(DBname string, CollectionName string, email string, phone int, password string, fname string, lname string, uid string, created time.Time, updated time.Time, token string, code int, agent interface{}) bool {
ctx, client := HandleDBConnection()
collection := client.Database(DBname).Collection(CollectionName)
_, errInsert := collection.InsertOne(ctx, bson.M{
"email": email,
"phone": phone,
"password": password,
"first_name": fname,
"last_name": lname,
"user_id": uid,
"created_at": created,
"updated_at": updated,
"UserAgent": agent,
})
HandleInsertToken(DBname, "tokens", token, code, created)
if errInsert != nil {
return false
}
defer client.Disconnect(ctx)
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment