From 868c10ef6a49b7e140a50ad26887b6a1ae6f2f69 Mon Sep 17 00:00:00 2001 From: "mail_yanpeng@163.com" Date: Fri, 23 Nov 2018 18:03:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=B8=AD=E5=BF=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/BlogController.go | 8 ++--- controllers/PageController.go | 2 +- controllers/UserController.go | 64 ++++++++++++++++++++++++---------- data/beeblog.db | Bin 86016 -> 86016 bytes service/BlogService.go | 36 ++++++++++++++++++- service/UserService.go | 7 ++++ static/css/me.css | 9 ++++- utils/PageUtil.go | 1 + views/T.nav.tpl | 3 +- views/ublogs.html | 41 ++++++++++++++++++---- 10 files changed, 137 insertions(+), 34 deletions(-) diff --git a/controllers/BlogController.go b/controllers/BlogController.go index 6dd5a97..ab4b113 100644 --- a/controllers/BlogController.go +++ b/controllers/BlogController.go @@ -41,7 +41,7 @@ func (this *BlogController) Get() { id, _ := strconv.ParseInt(idStr, 10, 64) blog, err := service.GetBlog(id) if err != nil { - this.Redirect("/500.html",302) + this.Redirect("/500",302) return } this.Data["Blog"] = blog @@ -56,7 +56,7 @@ func (this *BlogController) Get() { func (this *BlogController) New() { uid := this.GetSession("userid") if uid == nil { - this.Redirect("/login.html", 302) + this.Redirect("login.html", 302) return } this.TplName = "newblog.html" @@ -68,7 +68,7 @@ func (this *BlogController) Blog1() { func (this *BlogController) BlogsPage() { cats, errcat := service.GetCats() if errcat != nil { - this.Redirect("500.html", 302) + this.Redirect("/500", 302) return } num, _ := this.GetInt("num") @@ -87,7 +87,7 @@ func (this *BlogController) BlogsPage() { fmt.Println("nelson page", num, size, cat) pages, err := service.FindBlogs(num, size, cat, flag) if err != nil { - this.Redirect("500.html", 302) + this.Redirect("/500", 302) return } diff --git a/controllers/PageController.go b/controllers/PageController.go index ffbde7c..0e444fc 100644 --- a/controllers/PageController.go +++ b/controllers/PageController.go @@ -13,7 +13,7 @@ type PageController struct { func (this *PageController) Blog() { cats, err := service.GetCats() if err != nil { - this.Redirect("500.html", 302) + this.Redirect("/500", 302) return } this.Data["Cats"] = cats diff --git a/controllers/UserController.go b/controllers/UserController.go index 1b70433..d2d46c2 100644 --- a/controllers/UserController.go +++ b/controllers/UserController.go @@ -9,7 +9,6 @@ import ( "time" "strconv" "encoding/hex" - "fmt" ) type UserController struct { @@ -23,30 +22,58 @@ func (u *UserController) RegistPage() { u.TplName = "regist.html" } -func (u *UserController) PersonBlog() { - u.TplName = "ublogs.html" +func (this *UserController) PersonBlog() { + uid := this.GetSession("userid") + if uid == nil { + this.Redirect("/login", 302) + return + } + size := 15 + num, _ := this.GetInt("num") + if num <= 0 { + num = 1 + } + flag, _ := this.GetInt("flag") + page, err := service.MeBlogs(num, size, flag, uid.(int64)) + if err != nil { + if uid == nil { + this.Redirect("/500", 302) + return + } + } + user, uerr := service.GetUser(uid.(int64)) + if uerr != nil { + if uid == nil { + this.Redirect("/500", 302) + return + } + } + this.Data["Page"] = page + this.Data["Flag"] = 0 + this.Data["User"] = user + this.TplName = "ublogs.html" } func (this *UserController) Login() { username := this.GetString("username") userpwd := this.GetString("userpwd") if username == "" { - this.Data["json"] = models.ReurnError(1,"用户名为空") + this.Data["json"] = models.ReurnError(1, "用户名为空") this.ServeJSON() return } if len(username) < 4 { - this.Data["json"] = models.ReurnError(1,"用户名最低4位") + this.Data["json"] = models.ReurnError(1, "用户名最低4位") this.ServeJSON() return } if userpwd == "" { - this.Data["json"] = models.ReurnError(1,"密码为空") + this.Data["json"] = models.ReurnError(1, "密码为空") this.ServeJSON() return } if len(userpwd) < 6 { - this.Data["json"] = models.ReurnError(1,"密码最低6位") + this.Data["json"] = models.ReurnError(1, "密码最低6位") this.ServeJSON() return } @@ -59,12 +86,11 @@ func (this *UserController) Login() { this.Data["json"] = models.ReurnSuccess("") this.SetSession("userid", user.Id) this.SetSession("nickname", user.NickName) - fmt.Println(this.CruSession) } else { - this.Data["json"] = models.ReurnError(1,"用户名或密码错误") + this.Data["json"] = models.ReurnError(1, "用户名或密码错误") } } else { - this.Data["json"] = models.ReurnError(1,"用户名不存在") + this.Data["json"] = models.ReurnError(1, "用户名不存在") } this.ServeJSON() return @@ -76,28 +102,28 @@ func (this *UserController) Regist() { username = strings.Replace(username, " ", "", -1) userpwd = strings.Replace(userpwd, " ", "", -1) if username == "" { - this.Data["json"] = models.ReurnError(1,"用户名为空") + this.Data["json"] = models.ReurnError(1, "用户名为空") this.ServeJSON() return } if len(username) < 4 { - this.Data["json"] = models.ReurnError(1,"用户名最低4位") + this.Data["json"] = models.ReurnError(1, "用户名最低4位") this.ServeJSON() return } if userpwd == "" { - this.Data["json"] = models.ReurnError(1,"密码为空") + this.Data["json"] = models.ReurnError(1, "密码为空") this.ServeJSON() return } if len(userpwd) < 6 { - this.Data["json"] = models.ReurnError(1,"密码最低6位") + this.Data["json"] = models.ReurnError(1, "密码最低6位") this.ServeJSON() return } user, _ := service.FindByUserName(username) if user != nil { - this.Data["json"] = models.ReurnError(1,"用户已经存在") + this.Data["json"] = models.ReurnError(1, "用户已经存在") this.ServeJSON() return } @@ -107,12 +133,12 @@ func (this *UserController) Regist() { h = md5.New() h.Write([]byte(userpwd + salt)) userpwd = hex.EncodeToString(h.Sum(nil)) - user = &models.User{UserName: username,NickName:username, UserPwd: userpwd, Salt: salt} + user = &models.User{UserName: username, NickName: username, UserPwd: userpwd, Salt: salt} err := service.SaveUser(user) if err == nil { this.Data["json"] = models.ReurnSuccess("") } else { - this.Data["json"] = models.ReurnError(1,"注册失败") + this.Data["json"] = models.ReurnError(1, "注册失败") } this.ServeJSON() return @@ -121,6 +147,6 @@ func (this *UserController) Regist() { func (this *UserController) Logout() { this.DelSession("userid") this.DelSession("nickname") - this.Redirect("/",302) + this.Redirect("/", 302) return -} \ No newline at end of file +} diff --git a/data/beeblog.db b/data/beeblog.db index b7c8412b0b24cbfddadc73b9b4d004f15513b620..18c5617b5936bb5b2b45d374972d6c039530865c 100644 GIT binary patch delta 30 ocmV+(0O9|Dpap=S1&|v7){z`T0oJi#pHBg@vQYn@0i>evV7*/}}