Example #1
0
func AdminProfile(context *GoInk.Context) {
	uid, _ := strconv.Atoi(context.Cookie("token-user"))
	user := model.GetUserById(uid)
	if context.Method == "POST" {
		data := context.Input()
		if !user.ChangeEmail(data["email"]) {
			Json(context, false).Set("msg", "邮箱与别的用户重复").End()
			return
		}
		user.Name = data["user"]
		user.Email = data["email"]
		user.Avatar = utils.Gravatar(user.Email, "180")
		user.Url = data["url"]
		user.Nick = data["nick"]
		user.Bio = data["bio"]
		Json(context, true).End()
		go model.SyncUsers()
		go model.UpdateCommentAdmin(user)
		context.Do("profile_update", user)
		return
	}
	context.Layout("admin/admin")
	context.Render("admin/profile", map[string]interface{}{
		"Title": "个性资料",
		"User":  user,
	})
}
Example #2
0
func ArticleWrite(context *GoInk.Context) {
	if context.Method == "POST" {
		c := new(model.Content)
		c.Id = 0
		data := context.Input()
		if !c.ChangeSlug(data["slug"]) {
			Json(context, false).Set("msg", "固定链接重复").End()
			return
		}
		c.Title = data["title"]
		c.Text = data["content"]
		c.Tags = strings.Split(strings.Replace(data["tag"], ",", ",", -1), ",")
		c.IsComment = data["comment"] == "1"
		c.IsLinked = false
		c.AuthorId, _ = strconv.Atoi(context.Cookie("token-user"))
		c.Template = "blog.html"
		c.Status = data["status"]
		c.Format = "markdown"
		c.Hits = 1
		var e error
		c, e = model.CreateContent(c, "article")
		if e != nil {
			Json(context, false).Set("msg", e.Error()).End()
			return
		}
		Json(context, true).Set("content", c).End()
		context.Do("article_created", c)
		//c.Type = "article"
		return
	}
	context.Layout("admin/admin")
	context.Render("admin/write_article", map[string]interface{}{
		"Title": "撰写文章",
	})
}
Example #3
0
func Comment(context *GoInk.Context) {
	cid, _ := strconv.Atoi(context.Param("id"))
	if cid < 1 {
		Json(context, false).End()
		return
	}
	if model.GetContentById(cid) == nil {
		Json(context, false).End()
		return
	}
	data := context.Input()
	msg := validateComment(data)
	if msg != "" {
		Json(context, false).Set("msg", msg).End()
		return
	}
	co := new(model.Comment)
	co.Author = data["user"]
	co.Email = data["email"]
	co.Url = data["url"]
	co.Content = data["content"]
	co.Avatar = utils.Gravatar(co.Email, "50")
	co.Pid, _ = strconv.Atoi(data["pid"])
	co.Ip = context.Ip
	co.UserAgent = context.UserAgent
	co.IsAdmin = false
	model.CreateComment(cid, co)
	Json(context, true).Set("comment", co.ToJson()).End()
	model.CreateMessage("comment", co)
	context.Do("comment_created", co)
}
Example #4
0
func Login(context *GoInk.Context) {
	if context.Method == "POST" {
		data := context.Input()
		user := model.GetUserByName(data["user"])
		if user == nil {
			Json(context, false).End()
			return
		}
		if !user.CheckPassword(data["password"]) {
			Json(context, false).End()
			return
		}
		exp := 3600 * 24 * 3
		expStr := strconv.Itoa(exp)
		s := model.CreateToken(user, context, int64(exp))
		context.Cookie("token-user", strconv.Itoa(s.UserId), expStr)
		context.Cookie("token-value", s.Value, expStr)
		Json(context, true).End()
		return
	}
	if context.Cookie("token-value") != "" {
		context.Redirect("/admin/")
		return
	}
	context.Render("admin/login", nil)
}
Example #5
0
func PageEdit(context *GoInk.Context) {
	id, _ := strconv.Atoi(context.Param("id"))
	c := model.GetContentById(id)
	if c == nil {
		context.Redirect("/admin/pages/")
		return
	}
	if context.Method == "DELETE" {
		model.RemoveContent(c)
		Json(context, true).End()
		return
	}
	if context.Method == "POST" {
		data := context.Input()
		if !c.ChangeSlug(data["slug"]) {
			Json(context, false).Set("msg", "固定链接重复").End()
			return
		}
		c.Title = data["title"]
		c.Text = data["content"]
		//c.Tags = strings.Split(strings.Replace(data["tag"], ",", ",", -1), ",")
		c.IsComment = data["comment"] == "1"
		c.IsLinked = data["link"] == "1"
		//c.AuthorId, _ = strconv.Atoi(context.Cookie("token-user"))
		//c.Template = "blog.html"
		c.Status = data["status"]
		//c.Format = "markdown"
		model.SaveContent(c)
		Json(context, true).Set("content", c).End()
		context.Do("page_modified", c)
		//c.Type = "article"
		return
	}
	context.Layout("admin/admin")
	context.Render("admin/edit_page", map[string]interface{}{
		"Title": "编辑文章",
		"Page":  c,
	})
}
Example #6
0
func PluginSetting(context *GoInk.Context) {
	key := context.Param("plugin_key")
	if key == "" {
		context.Redirect("/admin/plugins/")
		return
	}
	p := plugin.GetPluginByKey(key)
	if p == nil {
		context.Redirect("/admin/plugins/")
		return
	}
	if context.Method == "POST" {
		p.SetSetting(context.Input())
		Json(context, true).End()
		context.Do("plugin_setting_saved", p)
		return
	}
	context.Layout("admin/admin")
	context.Render("admin/plugin_setting", map[string]interface{}{
		"Title": "插件 - " + p.Name(),
		"Form":  p.Form(),
	})
}
Example #7
0
func AdminSetting(context *GoInk.Context) {
	if context.Method == "POST" {
		data := context.Input()
		for k, v := range data {
			if v == "" {
				if data[k+"_def"] != "" {
					v = data[k+"_def"]
				}
			}
			model.SetSetting(k, v)
		}
		model.SyncSettings()
		Json(context, true).End()
		context.Do("setting_saved")
		return
	}
	context.Layout("admin/admin")
	context.Render("admin/setting", map[string]interface{}{
		"Title":      "配置",
		"Custom":     model.GetCustomSettings(),
		"Navigators": model.GetNavigators(),
	})
}