api for initial widgets

This commit is contained in:
Gabe Farrell 2023-04-10 22:39:51 -04:00
parent 36f751a69f
commit 4aa8a2f822
14 changed files with 864 additions and 11 deletions

View file

@ -18,6 +18,7 @@ import (
)
func CreateAccount(w http.ResponseWriter, r *http.Request) {
log.Println("* /auth/createaccount")
// prepare DB
err := db.Client.Ping(context.Background(), readpref.Primary())
if err != nil {
@ -26,7 +27,7 @@ func CreateAccount(w http.ResponseWriter, r *http.Request) {
var userCollection = db.Client.Database("budgetbuddy").Collection("users")
// var v contains POST credentials
var v UserSchema
var v db.UserSchema
r.ParseForm()
v.Email = r.FormValue("email")
v.Password = r.FormValue("password")
@ -72,6 +73,8 @@ func CreateAccount(w http.ResponseWriter, r *http.Request) {
// add the new user to the database
v.Session = sessionID
v.Password = string(hashedPass)
v.Balance.Currency = "USD"
v.Budget.Currency = "USD"
_, err = userCollection.InsertOne(r.Context(), v)
if err != nil {
log.Println("* Error inserting new user")