Beispiel #1
0
func UserLogin(c *gin.Context) {
	var cookie middleware.CookieManager
	cookie = c.MustGet("CM").(middleware.CookieManager)
	if c.Request.Method == "GET" {
		data := tool.GetTD(c)

		fmt.Println(data)
		c.HTML(http.StatusOK, "login.html", data)
	} else if c.Request.Method == "POST" {

		email := c.PostForm("email")
		password := c.PostForm("password")
		user := model.User{}
		model.T.DB.Debug().Where("email = ? and password = ?", email, password).First(&user)
		if user.Name != "" {
			cookie.Add("user_id", user.ID)
			cookie.WriteCookies()
			c.Redirect(http.StatusMovedPermanently, "/")
		} else {
			cookie.Flash("fail_msg", "login failed :(")
			c.Redirect(http.StatusMovedPermanently, "/user/login")
		}

	}
}
Beispiel #2
0
func ShowIndex(c *gin.Context) {
	data := tool.GetTD(c)
	goods := model.Goods{}
	goods_list := goods.GetAll()
	data["goods_list"] = goods_list
	me := tool.GetMe(c)
	if me.ID > 0 {
		data["address_list"] = me.GetAddressList()
		//data["order_list"] = me.GetOrderList()
	}

	c.HTML(http.StatusOK, "index.html", data)
}