예제 #1
0
// POST user deletion request
func UserDelete(c *gin.Context) {
	user, _ := models.GetUser(c.Param("id"))
	if err := user.Delete(); err != nil {
		c.HTML(http.StatusInternalServerError, "errors/500", nil)
		return
	} else {
		c.Redirect(http.StatusFound, "/admin/users")
	}
}
예제 #2
0
//+++++++++++++ middlewares +++++++++++++++++++++++
//SharedData fills in common data, such as user info, etc...
func SharedData() gin.HandlerFunc {
	return func(c *gin.Context) {
		session := sessions.Default(c)
		if uId := session.Get("UserId"); uId != nil {
			user, _ := models.GetUser(uId)
			if user.Id != 0 {
				c.Set("User", user)
			}
		}
		if system.GetConfig().SignupEnabled {
			c.Set("SignupEnabled", true)
		}
		c.Next()
	}
}
예제 #3
0
// GET user update form
func UserEdit(c *gin.Context) {
	user, _ := models.GetUser(c.Param("id"))
	if user.Id == 0 {
		c.HTML(http.StatusNotFound, "errors/404", nil)
		return
	}
	h := helpers.DefaultH(c)
	h["Title"] = "Edit user"
	h["Active"] = "users"
	h["User"] = user
	session := sessions.Default(c)
	h["Flash"] = session.Flashes()
	session.Save()
	c.HTML(http.StatusOK, "admin/users/form", h)
}