mirror of
https://github.com/arnaucube/blockchainIDsystem.git
synced 2026-02-07 02:56:43 +01:00
updated to the same stage than darkID project, but with own blockchain
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user