Skip to content

Commit

Permalink
Merge pull request #1 from fuxiaohei/develop
Browse files Browse the repository at this point in the history
release v0.1
  • Loading branch information
fuxiaohei committed Jan 2, 2014
2 parents 22339e6 + 142bb45 commit b044aa8
Show file tree
Hide file tree
Showing 65 changed files with 1,576 additions and 2,367 deletions.
Binary file removed GoBlog.exe
Binary file not shown.
14 changes: 7 additions & 7 deletions app/handler/admin.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package handler

import (
"github.com/fuxiaohei/GoInk/Core"
"strings"
"github.com/fuxiaohei/GoBlog/app/model"
"github.com/fuxiaohei/GoInk/Core"
"strconv"
"strings"
)

func Admin(context *Core.Context) interface {} {
context.Render("admin:admin/dashboard.html", map[string]interface {}{
"IsDashboard":true,
"Title":"控制台",
})
func Admin(context *Core.Context) interface{} {
context.Render("admin:admin/dashboard.html", map[string]interface{}{
"IsDashboard": true,
"Title": "控制台",
})
return nil
}

Expand Down
43 changes: 30 additions & 13 deletions app/handler/admin_article.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ func AdminArticle(context *Core.Context) interface{} {
}
articles, pager := model.ArticleM.GetPaged(page, 10, false)
context.Render("admin:admin/article.html", map[string]interface{}{
"Title": "文章",
"IsArticle": true,
"Articles": articles,
"Pager": pager,
})
"Title": "文章",
"IsArticle": true,
"Articles": articles,
"Pager": pager,
})
return nil
}

func AdminArticleNew(context *Core.Context) interface{} {
context.Render("admin:admin/article_new.html", map[string]interface{}{
"Title": "写文章",
"Categories": model.CategoryM.GetAll(),
})
"Title": "写文章",
"Categories": model.CategoryM.GetAll(),
})
return nil
}

Expand Down Expand Up @@ -84,11 +84,11 @@ func AdminArticleEdit(context *Core.Context) interface{} {
return nil
}
context.Render("admin:admin/article_edit.html", map[string]interface{}{
"Title": "修改文章",
"IsArticle": true,
"Article": article,
"Categories": model.CategoryM.GetAll(),
})
"Title": "修改文章",
"IsArticle": true,
"Article": article,
"Categories": model.CategoryM.GetAll(),
})
return nil
}

Expand Down Expand Up @@ -133,3 +133,20 @@ func AdminArticleEditPost(context *Core.Context) interface{} {
})
return nil
}

func AdminArticleDelete(context *Core.Context) interface {} {
id, _ := strconv.Atoi(context.Param(3))
article := model.ArticleM.GetArticleById(id)
if article == nil {
context.Redirect("/admin/article/")
return nil
}
// delete comments
model.CommentM.DeleteCommentsInContent(article.Id)
// delete article
model.ArticleM.DeleteArticle(article.Id)
// update category counts
model.CategoryM.CountArticle()
context.Redirect(context.Referer)
return nil
}
49 changes: 25 additions & 24 deletions app/handler/admin_category.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
package handler

import (
"github.com/fuxiaohei/GoInk/Core"
"github.com/fuxiaohei/GoBlog/app"
"github.com/fuxiaohei/GoBlog/app/model"
"github.com/fuxiaohei/GoInk/Core"
"strconv"
"github.com/fuxiaohei/GoBlog/app"
)

func AdminCategory(context *Core.Context) interface {} {
context.Render("admin:admin/category.html", map[string]interface {}{
"Title":"分类",
"IsMeta":true,
"IsCategory":true,
"Categories":model.CategoryM.GetAll(),
func AdminCategory(context *Core.Context) interface{} {
context.Render("admin:admin/category.html", map[string]interface{}{
"Title": "分类",
"IsMeta": true,
"IsCategory": true,
"Categories": model.CategoryM.GetAll(),
})
return nil
}

func AdminCategoryEdit(context *Core.Context) interface {} {
func AdminCategoryEdit(context *Core.Context) interface{} {
cid, _ := strconv.Atoi(context.Param(3))
if cid < 1 {
context.Redirect("/admin/category/")
return nil
}
context.Render("admin:admin/category_edit.html", map[string]interface {}{
"Title":"分类",
"IsMeta":true,
"IsCategory":true,
"Category":model.CategoryM.GetCategoryById(cid),
context.Render("admin:admin/category_edit.html", map[string]interface{}{
"Title": "分类",
"IsMeta": true,
"IsCategory": true,
"Category": model.CategoryM.GetCategoryById(cid),
})
return nil
}

func AdminCategoryEditPost(context *Core.Context) interface {} {
func AdminCategoryEditPost(context *Core.Context) interface{} {
cid, _ := strconv.Atoi(context.Param(3))
if cid < 1 {
context.Redirect("/admin/category/")
Expand All @@ -41,7 +41,7 @@ func AdminCategoryEditPost(context *Core.Context) interface {} {
data := context.Input()
// check slug exist
c := model.CategoryM.GetCategoryBySlug(data["slug"])
if c.Id != cid {
if c == nil || c.Id != cid {
context.Redirect(context.Referer+"?err=1")
return nil
}
Expand All @@ -51,16 +51,16 @@ func AdminCategoryEditPost(context *Core.Context) interface {} {
return nil
}

func AdminCategoryNew(context *Core.Context) interface {} {
context.Render("admin:admin/category_new.html", map[string]interface {}{
"Title":"分类",
"IsMeta":true,
"IsCategory":true,
func AdminCategoryNew(context *Core.Context) interface{} {
context.Render("admin:admin/category_new.html", map[string]interface{}{
"Title": "分类",
"IsMeta": true,
"IsCategory": true,
})
return nil
}

func AdminCategoryNewPost(context *Core.Context) interface {} {
func AdminCategoryNewPost(context *Core.Context) interface{} {
data := context.Input()
c := model.CategoryM.GetCategoryBySlug(data["slug"])
if c != nil {
Expand All @@ -73,15 +73,16 @@ func AdminCategoryNewPost(context *Core.Context) interface {} {
return nil
}

func AdminCategoryDelete(context *Core.Context) interface {} {
func AdminCategoryDelete(context *Core.Context) interface{} {
data := context.Input()
if data["category"] == data["move"] {
context.Redirect("/admin/category/?err=1")
return nil
}
category , _ := strconv.Atoi(data["category"])
category, _ := strconv.Atoi(data["category"])
move, _ := strconv.Atoi(data["move"])
model.CategoryM.DeleteCategory(category, move)
go model.ArticleM.Reset()
context.Redirect("/admin/category/?move=1")
app.Ink.Listener.EmitAll("mode.category.move", category, move)
return nil
Expand Down
93 changes: 93 additions & 0 deletions app/handler/admin_comment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package handler

import (
"github.com/fuxiaohei/GoInk/Core"
"strconv"
"github.com/fuxiaohei/GoBlog/app/model"
"github.com/fuxiaohei/GoBlog/app/utils"
"strings"
)

func AdminComment(context *Core.Context) interface{} {
page := 1
if context.Param(2) == "page" {
page, _ = strconv.Atoi(context.Param(3))
if page < 1 {
page = 1
}
}
comments, pager := model.CommentM.GetPaged(page, 8, false)
context.Render("admin:admin/comment.html", map[string]interface{}{
"Title": "评论",
"IsComment": true,
"Comments":comments,
"Pager":pager,
})
return nil
}

func AdminCommentStatusPost(context *Core.Context) interface {} {
status := context.String("status")
id := context.Int("id")
if len(status) < 1 || id < 1 {
context.Json(map[string]interface {}{
"res":false,
"msg":"审核失败",
})
return nil
}
model.CommentM.ChangeCommentStatus(id, status)
model.ArticleM.CountComments()
context.Json(map[string]interface {}{
"res":true,
})
return nil
}

func AdminCommentReplyPost(context *Core.Context) interface {} {
pid := context.Int("pid")
pComment := model.CommentM.GetCommentById(pid)
if pComment == nil {
context.Json(map[string]interface {}{
"res":false,
"msg":"回复失败",
})
return nil
}
uid, _ := strconv.Atoi(context.Cookie("admin-user"))
user := model.UserM.GetUserById(uid)
data := context.Input()
c := new(model.Comment)
c.Author = user.Display
c.Email = user.Email
c.Site = user.Site
c.Content = strings.Replace(data["content"], "\n", "<br/>", -1)
c.ContentId = pComment.ContentId
c.Pid = pid
c.Avatar = utils.Gravatar(c.Email, "50")
c.UserId = user.Id
c.IsAdmin = true
c = model.CommentM.CreateComment(c)
context.Json(map[string]interface {}{
"res":true,
"comment":c,
})
return nil
}

func AdminCommentDeletePost(context *Core.Context) interface {} {
id := context.Int("id")
if id < 1 {
context.Json(map[string]interface {}{
"res":false,
"msg":"删除",
})
return nil
}
model.CommentM.DeleteComment(id)
model.ArticleM.CountComments()
context.Json(map[string]interface {}{
"res":true,
})
return nil
}
40 changes: 20 additions & 20 deletions app/handler/admin_profile.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package handler

import (
"github.com/fuxiaohei/GoInk/Core"
"strconv"
"github.com/fuxiaohei/GoBlog/app"
"github.com/fuxiaohei/GoBlog/app/model"
"github.com/fuxiaohei/GoBlog/app/utils"
"github.com/fuxiaohei/GoBlog/app"
"github.com/fuxiaohei/GoInk/Core"
"strconv"
)

func AdminProfile(context *Core.Context) interface {} {
func AdminProfile(context *Core.Context) interface{} {
uid, _ := strconv.Atoi(context.Cookie("admin-user"))
context.Render("admin:admin/profile.html", map[string]interface {}{
"IsProfile":true,
"User":model.UserM.GetUserById(uid),
"Title":"个人资料",
"Update":context.String("update"),
})
context.Render("admin:admin/profile.html", map[string]interface{}{
"IsProfile": true,
"User": model.UserM.GetUserById(uid),
"Title": "个人资料",
"Update": context.String("update"),
})
return nil
}

func AdminProfilePost(context *Core.Context) interface {} {
func AdminProfilePost(context *Core.Context) interface{} {
data := context.Input()
uid, _ := strconv.Atoi(context.Cookie("admin-user"))
model.UserM.SaveProfile(uid, data["login"], data["display"], data["email"], data["site"], utils.Gravatar(data["email"], "180"))
Expand All @@ -28,18 +28,18 @@ func AdminProfilePost(context *Core.Context) interface {} {
return nil
}

func AdminPassword(context *Core.Context) interface {} {
context.Render("admin:admin/password.html", map[string]interface {}{
"IsProfile":true,
"IsPasswprd":true,
"Title":"修改密码",
"Update":context.String("update"),
"Error":context.String("error"),
})
func AdminPassword(context *Core.Context) interface{} {
context.Render("admin:admin/password.html", map[string]interface{}{
"IsProfile": true,
"IsPasswprd": true,
"Title": "修改密码",
"Update": context.String("update"),
"Error": context.String("error"),
})
return nil
}

func AdminPasswordPost(context *Core.Context) interface {} {
func AdminPasswordPost(context *Core.Context) interface{} {
data := context.Input()
if data["new"] != data["confirm"] {
context.Redirect("/admin/password?error=1")
Expand Down
33 changes: 33 additions & 0 deletions app/handler/admin_setting.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package handler

import (
"github.com/fuxiaohei/GoInk/Core"
"github.com/fuxiaohei/GoBlog/app/model"
)

func AdminSetting(context *Core.Context) interface {} {
context.Render("admin:admin/setting.html", map[string]interface {}{
"Title":"配置",
"IsSetting":true,
})
return nil
}

func AdminSettingPost(context *Core.Context) interface {} {
data := context.Input()
settingsMap := make([]map[string]string, len(data))
i := 0
for key, v := range data {
settingsMap[i] = map[string]string{
"key":key,
"value":v,
}
i++
}
model.SettingM.SaveSetting(settingsMap...)
context.Json(map[string]interface {}{
"res":true,
})
return nil
}

Loading

0 comments on commit b044aa8

Please sign in to comment.