mirror of
https://github.com/gabehf/BudgetBuddy.git
synced 2026-03-07 21:48:14 -08: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 v contains POST credentials
|
||||
var v Credentials
|
||||
var v UserSchema
|
||||
r.ParseForm()
|
||||
v.Email = r.FormValue("email")
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
|
@ -79,6 +80,7 @@ func CreateAccount(w http.ResponseWriter, r *http.Request) {
|
|||
// return the account information to the user
|
||||
ret, err := json.Marshal(LoginResponse{
|
||||
Email: v.Email,
|
||||
Name: v.Name,
|
||||
Session: v.Session,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -16,13 +16,15 @@ import (
|
|||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
type Credentials struct {
|
||||
type UserSchema struct {
|
||||
Name string `json:"name" bson:"name"`
|
||||
Email string `json:"email" bson:"email"`
|
||||
Password string `json:"password" bson:"password"`
|
||||
Session string `json:"session" bson:"session"`
|
||||
}
|
||||
|
||||
type LoginResponse struct {
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
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 v contains POST credentials
|
||||
var v Credentials
|
||||
var v UserSchema
|
||||
r.ParseForm()
|
||||
v.Email = r.FormValue("email")
|
||||
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
|
||||
var cmp Credentials
|
||||
var cmp UserSchema
|
||||
|
||||
found := userCollection.FindOne(r.Context(), bson.D{primitive.E{Key: "email", Value: strings.ToLower(v.Email)}})
|
||||
if found.Err() != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue