func (auth *AuthController) Login(c *gin.Context) {

	var loginInfo entity.User
	if err := c.ShouldBindJSON(&loginInfo); err != nil {
		c.AbortWithStatusJSON(400, gin.H{"error": err.Error()})
		return
	}
	//TODO
	userservice := service.Userservice{}
	user, errf := userservice.Find(&loginInfo)
	if errf != nil {
		c.AbortWithStatusJSON(401, gin.H{"error": "Not found"})
		return
	}

	err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(loginInfo.Password))
	if err != nil {
		c.AbortWithStatusJSON(403, gin.H{"error": "Email or password is invalid."})
		return
	}

	fmt.Println("user email is ", user.Email)
	token, err := user.GetJwtToken()
	if err != nil {
		c.AbortWithStatusJSON(500, gin.H{"error": err.Error()})
		return
	}
	//-------
	c.JSON(200, gin.H{
		"token": token,
	})
}
//Login is to process login request
Login is to process login request
// Login is to process login request
func (auth *AuthController) Login(c *gin.Context) {
	var loginInfo entity.User
	if err := c.ShouldBindJSON(&loginInfo); err != nil {
		c.AbortWithStatusJSON(400, gin.H{"error": err.Error()})
		return
	}
	userservice := service.Userservice{}
	user, errf := userservice.Find(&loginInfo)
	if errf != nil {
		c.AbortWithStatusJSON(401, gin.H{"error": "Not found"})
		return
	}
	err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(loginInfo.Password))
	if err != nil {
		c.AbortWithStatusJSON(403, gin.H{"error": "Email or password is invalid."})
		return
	}
	fmt.Println("user email is ", user.Email)
	token, err := user.GetJwtToken()
	if err != nil {
		c.AbortWithStatusJSON(500, gin.H{"error": err.Error()})
		return
	}
	c.JSON(200, gin.H{
		"token": token,
	})
}
func ( auth * AuthController ) Login ( c * gin . Context ) { var loginInfo entity . User if err := c . ShouldBindJSON ( & loginInfo ) ; err != nil { c . AbortWithStatusJSON ( 400 , gin . H { " " : err . Error ( ) } ) return } userservice := service . Userservice { } user , errf := userservice . Find ( & loginInfo ) if errf != nil { c . AbortWithStatusJSON ( 401 , gin . H { " " : " " } ) return } err := bcrypt . CompareHashAndPassword ( [ ] byte ( user . Password ) , [ ] byte ( loginInfo . Password ) ) if err != nil { c . AbortWithStatusJSON ( 403 , gin . H { " " : " " } ) return } fmt . Println ( " " , user . Email ) token , err := user . GetJwtToken ( ) if err != nil { c . AbortWithStatusJSON ( 500 , gin . H { " " : err . Error ( ) } ) return } c . JSON ( 200 , gin . H { " " : token , } ) }
Login is to process login request
Login is to process login request
//TODO //-------