updated to the same stage than darkID project, but with own blockchain

This commit is contained in:
arnaucode
2018-01-17 23:02:17 +01:00
parent 7734e0926f
commit cc4394265d
39 changed files with 592 additions and 141 deletions

View File

@@ -72,6 +72,7 @@ func Login(w http.ResponseWriter, r *http.Request) {
panic(err)
}
defer r.Body.Close()
//TODO check if the user password exists in the database
fmt.Print("user login: ")
fmt.Println(user)
@@ -83,11 +84,21 @@ func Login(w http.ResponseWriter, r *http.Request) {
rUser := User{}
err = userCollection.Find(bson.M{"email": user.Email}).One(&rUser)
if err != nil {
} else {
//user exists, update with the token
err = userCollection.Update(bson.M{"_id": rUser.Id}, user)
jResp, err := json.Marshal("error login, email not found")
check(err)
fmt.Fprintln(w, string(jResp))
return
}
//user exists, check password
if user.Password != rUser.Password {
jResp, err := json.Marshal("error login, password not match")
check(err)
fmt.Fprintln(w, string(jResp))
return
}
//update with the token
err = userCollection.Update(bson.M{"_id": rUser.Id}, user)
check(err)
jResp, err := json.Marshal(user)
if err != nil {