mirror of
https://github.com/gabehf/BudgetBuddy.git
synced 2026-03-17 11:16:34 -07:00
updates, added name to schema
This commit is contained in:
parent
272e4e43b1
commit
23463c453c
3 changed files with 1839 additions and 1774 deletions
3599
package-lock.json
generated
3599
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -26,11 +26,12 @@ func CreateAccount(w http.ResponseWriter, r *http.Request) {
|
||||||
var userCollection = db.Client.Database("budgetbuddy").Collection("users")
|
var userCollection = db.Client.Database("budgetbuddy").Collection("users")
|
||||||
|
|
||||||
// var v contains POST credentials
|
// var v contains POST credentials
|
||||||
var v Credentials
|
var v UserSchema
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
v.Email = r.FormValue("email")
|
v.Email = r.FormValue("email")
|
||||||
v.Password = r.FormValue("password")
|
v.Password = r.FormValue("password")
|
||||||
if v.Email == "" || v.Password == "" {
|
v.Name = r.FormValue("name")
|
||||||
|
if v.Email == "" || v.Password == "" || v.Name == "" {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -79,6 +80,7 @@ func CreateAccount(w http.ResponseWriter, r *http.Request) {
|
||||||
// return the account information to the user
|
// return the account information to the user
|
||||||
ret, err := json.Marshal(LoginResponse{
|
ret, err := json.Marshal(LoginResponse{
|
||||||
Email: v.Email,
|
Email: v.Email,
|
||||||
|
Name: v.Name,
|
||||||
Session: v.Session,
|
Session: v.Session,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,15 @@ import (
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Credentials struct {
|
type UserSchema struct {
|
||||||
|
Name string `json:"name" bson:"name"`
|
||||||
Email string `json:"email" bson:"email"`
|
Email string `json:"email" bson:"email"`
|
||||||
Password string `json:"password" bson:"password"`
|
Password string `json:"password" bson:"password"`
|
||||||
Session string `json:"session" bson:"session"`
|
Session string `json:"session" bson:"session"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoginResponse struct {
|
type LoginResponse struct {
|
||||||
|
Name string `json:"name"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Session string `json:"session"`
|
Session string `json:"session"`
|
||||||
}
|
}
|
||||||
|
|
@ -36,7 +38,7 @@ func Login(w http.ResponseWriter, r *http.Request) {
|
||||||
var userCollection = db.Client.Database("budgetbuddy").Collection("users")
|
var userCollection = db.Client.Database("budgetbuddy").Collection("users")
|
||||||
|
|
||||||
// var v contains POST credentials
|
// var v contains POST credentials
|
||||||
var v Credentials
|
var v UserSchema
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
v.Email = r.FormValue("email")
|
v.Email = r.FormValue("email")
|
||||||
v.Password = r.FormValue("password")
|
v.Password = r.FormValue("password")
|
||||||
|
|
@ -46,7 +48,7 @@ func Login(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// cmp struct will be compared with v to verify credentials
|
// cmp struct will be compared with v to verify credentials
|
||||||
var cmp Credentials
|
var cmp UserSchema
|
||||||
|
|
||||||
found := userCollection.FindOne(r.Context(), bson.D{primitive.E{Key: "email", Value: strings.ToLower(v.Email)}})
|
found := userCollection.FindOne(r.Context(), bson.D{primitive.E{Key: "email", Value: strings.ToLower(v.Email)}})
|
||||||
if found.Err() != nil {
|
if found.Err() != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue