updated ethereum smart contract. Implemented backend of the login library example

This commit is contained in:
arnaucode
2018-01-18 16:03:18 +01:00
parent 9770437d3f
commit 55594e3b45
24 changed files with 632 additions and 26 deletions

View File

@@ -82,11 +82,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 {