Esempio n. 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()
		return
	}
	context.Layout("admin")
	context.Render("admin/profile", map[string]interface{}{
		"Title": "个性资料",
		"User":  user,
	})
}
Esempio n. 2
0
func Admin(context *GoInk.Context) {
	uid, _ := strconv.Atoi(context.Cookie("token-user"))
	user := model.GetUserById(uid)
	context.Layout("admin/admin")
	context.Render("admin/home", map[string]interface{}{
		"Title":    "控制台",
		"Statis":   model.NewStatis(),
		"User":     user,
		"Messages": model.GetUnreadMessages(),
	})
}
Esempio n. 3
0
func AdminComments(context *GoInk.Context) {
	if context.Method == "DELETE" {
		id := context.Int("id")
		cmt := model.GetCommentById(id)
		model.RemoveComment(cmt.Cid, id)
		Json(context, true).End()
		context.Do("comment_delete", id)
		return
	}
	if context.Method == "PUT" {
		id := context.Int("id")
		cmt2 := model.GetCommentById(id)
		cmt2.Status = "approved"
		cmt2.GetReader().Active = true
		model.SaveComment(cmt2)
		Json(context, true).End()
		context.Do("comment_change_status", cmt2)
		return
	}
	if context.Method == "POST" {
		// get required data
		pid := context.Int("pid")
		cid := model.GetCommentById(pid).Cid
		uid, _ := strconv.Atoi(context.Cookie("token-user"))
		user := model.GetUserById(uid)

		co := new(model.Comment)
		co.Author = user.Nick
		co.Email = user.Email
		co.Url = user.Url
		co.Content = context.String("content")
		co.Avatar = utils.Gravatar(co.Email, "50")
		co.Pid = pid
		co.Ip = context.Ip
		co.UserAgent = context.UserAgent
		co.IsAdmin = true
		model.CreateComment(cid, co)
		Json(context, true).Set("comment", co.ToJson()).End()
		model.CreateMessage("comment", co)
		context.Do("comment_reply", co)
		return
	}
	page := context.IntOr("page", 1)
	comments, pager := model.GetCommentList(page, 10)
	context.Layout("admin/admin")
	context.Render("admin/comments", map[string]interface{}{
		"Title":    "评论",
		"Comments": comments,
		"Pager":    pager,
	})
}
Esempio n. 4
0
func AdminPassword(context *GoInk.Context) {
	if context.Method == "POST" {
		uid, _ := strconv.Atoi(context.Cookie("token-user"))
		user := model.GetUserById(uid)
		if !user.CheckPassword(context.String("old")) {
			Json(context, false).Set("msg", "旧密码错误").End()
			return
		}
		user.ChangePassword(context.String("new"))
		go model.SyncUsers()
		Json(context, true).End()
		return
	}
	context.Layout("admin")
	context.Render("admin/password", map[string]interface{}{
		"Title": "修改密码",
		//"User":user,
	})
}