Exemple #1
0
func UserLogout(c *gin.Context) {
	var cookie middleware.CookieManager
	cookie = c.MustGet("CM").(middleware.CookieManager)
	cookie.Delete("user_id")
	cookie.WriteCookies()
	c.Redirect(http.StatusMovedPermanently, "/")
}
Exemple #2
0
func DelAddress(c *gin.Context) {

	var cookie middleware.CookieManager
	cookie = c.MustGet("CM").(middleware.CookieManager)
	a_id, _ := strconv.Atoi(c.PostForm("id"))
	address := model.Address{}
	address.Get(a_id)
	fmt.Println(address)
	address.Delete()
	cookie.Flash("success_msg", "address delete success")
	c.JSON(http.StatusOK, address)
}
Exemple #3
0
func UserRegisterHandler(c *gin.Context) {
	var cookie middleware.CookieManager
	if c.Request.Method == "GET" {
		c.HTML(http.StatusOK, "register.html", nil)
	} else if c.Request.Method == "POST" {
		u := model.User{Email: c.PostForm("email"), Name: c.PostForm("name"), Password: c.PostForm("password")}
		if u.InsertToDB() {
			cookie = c.MustGet("CM").(middleware.CookieManager)
			cookie.Add("user_id", u.ID)
			cookie.WriteCookies()
		}

		c.Redirect(http.StatusMovedPermanently, "/")
	}
}
Exemple #4
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")
		}

	}
}
Exemple #5
0
func NewAddress(c *gin.Context) {
	me := tool.GetMe(c)

	if me.ID > 0 {
		var cookie middleware.CookieManager
		cookie = c.MustGet("CM").(middleware.CookieManager)
		province := c.PostForm("province")
		city := c.PostForm("city")
		detail := c.PostForm("detail")
		name := c.PostForm("name")
		phone := c.PostForm("phone")
		address := model.Address{Province: province, City: city, Detail: detail, Name: name, Phone: phone, UserID: int(me.ID)}
		address.Create()
		cookie.Flash("success_msg", "address add success")
		c.Redirect(http.StatusMovedPermanently, "/")
	}

}
Exemple #6
0
func GetTD(c *gin.Context) TD {
	td := make(TD)

	var cookie middleware.CookieManager
	cookie = c.MustGet("CM").(middleware.CookieManager)

	me, exist := c.Get("me")
	if exist {
		td["me"] = me
	}
	cate := model.Category{Top: 0}
	cates := cate.GetTopList()
	td["top_cates"] = cates
	td["fail_msg"] = cookie.GetFlash("fail_msg")
	td["success_msg"] = cookie.GetFlash("success_msg")
	return td

}