Skip to content

Commit

Permalink
BlogOne
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakurasan committed Mar 23, 2017
1 parent 0a6ed84 commit 972643a
Show file tree
Hide file tree
Showing 1,431 changed files with 142,347 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": [],
"showLog": true
}
]
}
6 changes: 6 additions & 0 deletions conf/app.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
appname = ONE
httpport = 8080
runmode = dev

uname=admin
pwd=admin
51 changes: 51 additions & 0 deletions controllers/acategory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package controllers

import (
"github.com/astaxie/beego"
"ONE/models"
)

type ACatController struct {
beego.Controller
}

func (this *ACatController) Get() {
this.TplName = "AdminCategory.html"

op := this.Input().Get("op")

switch op {
case "add":
name := this.Input().Get("name")
if len(name) == 0 {
break
}
err := models.AddCategory(name)
if err != nil {
beego.Error(err)
}

this.Redirect("/admin/acategory", 301)

case "del":
id := this.Input().Get("id")
if len(id) == 0 {
break
}

err := models.DeleteCategory(id)
if err != nil {
beego.Error(err)
}
this.Redirect("/admin/acategory", 301)
return

}

var err error
this.Data["Categories"], err = models.GetAllCategories()

if err != nil {
beego.Error(err)
}
}
13 changes: 13 additions & 0 deletions controllers/admin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package controllers

import (
"github.com/astaxie/beego"
)

type AdminController struct {
beego.Controller
}

func (this *AdminController) Get() {
this.TplName = "OneAdmin.html"
}
133 changes: 133 additions & 0 deletions controllers/atopic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package controllers

import (
"github.com/astaxie/beego"
"ONE/models"
"net/http"
)

type ATopicController struct {
beego.Controller
http.Request
}

func (this *ATopicController) Get() {
this.TplName = "AdminTopic.html"

this.Data["IsLogin"] = checkAccount(this.Ctx)
this.Data["IsTopic"] = true

topics, err := models.GetAllTopics("", false, true)

if err != nil {
beego.Error(err)
} else {
this.Data["Topics"] = topics
}
}

func (this *ATopicController) Post() {
if !checkAccount(this.Ctx) {
this.Redirect("/login", 302)
return
}

// 解析表单
tid := this.Input().Get("tid")
title := this.Input().Get("title")
content := this.Input().Get("content")
// content := this.Request.FormValue("editormd-html-code")
category := this.Input().Get("category")
label := this.Input().Get("label")
summary := this.Input().Get("summary")

var err error
if len(tid) == 0 {
err = models.AddTopic(title, category, label, summary, content)
} else {
err = models.ModifyTopic(tid, title, category, summary, content, label)
}

if err != nil {
beego.Error(err)
}

// this.Redirect("/topic", 302)
this.Redirect("/topic/view/"+tid, 302)
}

func (this *ATopicController) Add() {
this.Data["IsLogin"] = checkAccount(this.Ctx)
this.TplName = "topic_add.html"
if !checkAccount(this.Ctx) {
this.Redirect("/login", 302)
return
}

categories, err := models.GetAllCategories()
if err != nil {
beego.Error(err)
}
this.Data["Categories"] = categories
}

func (this *ATopicController) View() {
this.TplName = "topic_view.html"

topic, err := models.GetTopic(this.Ctx.Input.Params()["0"])
if err != nil {
beego.Error(err)
this.Redirect("/", 302)
return
}

this.Data["Topic"] = topic
this.Data["Tid"] = this.Ctx.Input.Params()["0"]

replies, err := models.GetAllReplies(this.Ctx.Input.Params()["0"])
if err != nil {
beego.Error(err)
return
}

this.Data["Replies"] = replies
this.Data["IsLogin"] = checkAccount(this.Ctx)

}

func (this *ATopicController) Modify() {
this.TplName = "topic_modify.html"

tid := this.Input().Get("tid")
topic, err := models.GetTopic(tid)
if err != nil {
beego.Error(err)
this.Redirect("/", 302)
return
}

this.Data["Topic"] = topic
this.Data["Tid"] = tid

categories, err := models.GetAllCategories()
if err != nil {
beego.Error(err)
}
this.Data["Categories"] = categories
}

func (this *ATopicController) Delete() {
this.TplName = "topic.html"
if !checkAccount(this.Ctx) {
this.Redirect("/login", 302)
return
}

err := models.DeleteTopic(this.Input().Get("tid"))
// err := models.DeleteTopic(this.Ctx.Input.Params()["0"])
if err != nil {
beego.Error(err)
}
this.Redirect("/topic", 302)
return
}
53 changes: 53 additions & 0 deletions controllers/category.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package controllers

import (
"github.com/astaxie/beego"
"ONE/models"
)

type CategoryController struct {
beego.Controller
}

func (this *CategoryController) Get() {
this.Data["IsLogin"] = checkAccount(this.Ctx)
op := this.Input().Get("op")

switch op {
case "add":
name := this.Input().Get("name")
if len(name) == 0 {
break
}
err := models.AddCategory(name)
if err != nil {
beego.Error(err)
}

this.Redirect("category", 301)

case "del":
id := this.Input().Get("id")
if len(id) == 0 {
break
}

err := models.DeleteCategory(id)
if err != nil {
beego.Error(err)
}
this.Redirect("/category", 301)
return

}

this.TplName = "category.html"
this.Data["IsCategory"] = true

var err error
this.Data["Categories"], err = models.GetAllCategories()

if err != nil {
beego.Error(err)
}
}
63 changes: 63 additions & 0 deletions controllers/default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package controllers

import (
"github.com/astaxie/beego"
//"strconv"
"ONE/models"
)

type MainController struct {
beego.Controller
}

func (c *MainController) Get() {
c.Data["IsHome"] = true
c.TplName = "home.html"
c.Data["IsLogin"] = checkAccount(c.Ctx)

topics, err := models.GetAllTopics(c.Input().Get("cate"), true, false)
if err != nil {
beego.Error(err)
} else {
c.Data["Topics"] = topics
}

categories, err := models.GetAllCategories()
if err != nil {
beego.Error(err)
}

c.Data["Categories"] = categories

// 模板使用
// c.Data["Website"] = "golang.org"
// c.Data["Email"] = "[email protected]"

// c.Data["Truecond"] = true
// c.Data["Falsecond"] = false

// type u struct {
// Name string
// Age int
// Sex string
// }

// user := &u{
// Name: "GoBlog",
// Age: 9,
// Sex: "nil",
// }

// c.Data["user"] = user

// nums := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}

// c.Data["Nums"] = nums

// c.Data["GO"] = "hello GO"

// c.Data["html"] = "<div> Hello Beego</div>"

// c.Data["Pipe"] = "<div>Hello Beego</div>"

}
24 changes: 24 additions & 0 deletions controllers/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package controllers

import (
"github.com/astaxie/beego"
)

type ErrorController struct {
beego.Controller
}

func (this *ErrorController) Error404() {
this.Data["content"] = "page not found"
this.TplName = "404.html"
}

func (this *ErrorController) Error501() {
this.Data["content"] = "server error"
this.TplName = "500.html"
}

// func (this *ErrorController) ErrorDb() {
// this.Data["content"] = "database is now down"
// this.TplName = "dberror.tpl"
// }
Loading

0 comments on commit 972643a

Please sign in to comment.