Beispiel #1
0
func (cm *CookieManager) GetUser() {
	id_str := cm.GetString("user_id")
	if id_str != "" {
		user := model.User{}
		id, _ := strconv.Atoi(id_str)
		user.GetByID(id)
		cm.Context.Set("me", user)
	}

}
Beispiel #2
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, "/")
	}
}