Ejemplo n.º 1
0
func PostLogin(c *gin.Context) {
	var u model.User
	u.Email = c.Request.FormValue("email")
	password := c.Request.FormValue("password")

	row := util.DB.QueryRow(u.StmtGetByEmail())
	err := row.Scan(&u.Id, &u.Accountid, &u.Name, &u.Email, &u.Password, &u.Active)

	if err != nil || bcrypt.CompareHashAndPassword([]byte(u.Password), []byte(password)) != nil {
		log.Printf(".... auth fail from db " + u.Password)
		log.Printf(".... from form         " + password)
		http.Redirect(c.Writer, c.Request, "webapp/app.html?msg=loginfailed", http.StatusMovedPermanently)
	} else {
		SetCookieHandlerAccessOK(c, u.Email, u.Id)
		http.Redirect(c.Writer, c.Request, "webapp/app.html#/loggedin/"+u.Email, http.StatusMovedPermanently)
	}
}