db.go
func Findaccount(myEmail, myPassword string) bool {
collection := Connect.Database("webApp3").Collection("data")
collection.FindOne(context.TODO(), bson.M{"email": myEmail}).Decode(&Account)
err := bcrypt.CompareHashAndPassword([]byte(Account.Password), []byte(myPassword))
return err == nil
}
handler.go
func about(res http.ResponseWriter, req *http.Request) {
if req.Method != http.MethodPost {
tmpl.ExecuteTemplate(res, "about.html", nil)
return
}
email := database.Account.Email
password := database.Account.Password
content := req.FormValue("content")
match := database.Findaccount(email, password)
tmpl.ExecuteTemplate(res, "about.html", nil)
if match == true {
database.Updatedata("about", content)
} else {
fmt.Fprintf(res, "<h1> Error </h1>")
}
}
What I have tried:
In this code, I have an about function that is first verifying the email, and password from the database(MongoDB), and content from the about page form.
When I print all the above variables, they show me the correct data. But when I give the if-statement to check if the email and password are true then the boolean does not work. I don't know why?
How to solve this problem?