From 25982729a8d690cec7e2c690713e10f9403f1e68 Mon Sep 17 00:00:00 2001 From: yirenyishi Date: Tue, 20 Nov 2018 22:46:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0=E8=AF=AD=E7=9A=84return?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/BlogController.go | 1 + controllers/NoteController.go | 20 ++++++++++++++++++-- controllers/UserController.go | 11 +++++++++++ models/Result.go | 8 ++++---- views/iframe/note.html | 2 +- views/note.html | 7 +++++-- 6 files changed, 40 insertions(+), 9 deletions(-) diff --git a/controllers/BlogController.go b/controllers/BlogController.go index a66151f..f4e6c79 100644 --- a/controllers/BlogController.go +++ b/controllers/BlogController.go @@ -25,6 +25,7 @@ func (this *BlogController) Save() { this.Data["json"] = models.ReurnError(500,"保存失败") } this.ServeJSON() + return } func (this *BlogController) Get() { diff --git a/controllers/NoteController.go b/controllers/NoteController.go index 36208ae..3853f82 100644 --- a/controllers/NoteController.go +++ b/controllers/NoteController.go @@ -17,9 +17,12 @@ func (this *NoteController) Save() { title := this.GetString("title") uid := this.GetSession("userid") if uid == nil { + fmt.Println("ueseid nil",uid) this.Data["json"] = models.ReurnError(401,"保存失败") this.ServeJSON() + return } + fmt.Println("ueseid:",uid) note := &models.Note{Title: title, Pid: pid, UserId: uid.(int64)} err := service.SaveNote(note) if err == nil { @@ -28,6 +31,7 @@ func (this *NoteController) Save() { this.Data["json"] = models.ReurnError(500,"保存失败") } this.ServeJSON() + return } func (this *NoteController) Edit() { idStr := this.Ctx.Input.Param(":id") @@ -37,17 +41,19 @@ func (this *NoteController) Edit() { if uid == nil{ this.Data["json"] = models.ReurnError(401, "") this.ServeJSON() + return } note := &models.Note{Id:id} err1 := service.GetNote(note) if err1 != nil { - fmt.Print(err1) this.Data["json"] = models.ReurnError(500,"保存失败") this.ServeJSON() + return } if uid != note.UserId { this.Data["json"] = models.ReurnError(403,"") this.ServeJSON() + return } note.NoteHtml = noteHtml err := service.EditNote(note) @@ -57,6 +63,7 @@ func (this *NoteController) Edit() { this.Data["json"] = models.ReurnError(500,"保存失败") } this.ServeJSON() + return } func (this *NoteController) SaveNoteColl() { @@ -65,6 +72,7 @@ func (this *NoteController) SaveNoteColl() { if uid == nil{ this.Data["json"] = models.ReurnError(401, "") this.ServeJSON() + return } note := &models.NoteColl{Title: title, UserId: uid.(int64)} err := service.SaveNoteColl(note) @@ -74,6 +82,7 @@ func (this *NoteController) SaveNoteColl() { this.Data["json"] = models.ReurnError(500,"保存失败") } this.ServeJSON() + return } func (this *NoteController) Get() { @@ -81,6 +90,7 @@ func (this *NoteController) Get() { if uid == nil{ this.Data["json"] = models.ReurnError(401, "") this.ServeJSON() + return } idStr := this.Ctx.Input.Param(":id") id, _ := strconv.ParseInt(idStr, 10, 64) @@ -92,14 +102,17 @@ func (this *NoteController) Get() { if note.UserId != uid.(int64) { this.Data["json"] = models.ReurnError(403, "") this.ServeJSON() + return } this.ServeJSON() + return } func (this *NoteController) Delete() { uid := this.GetSession("userid") if uid == nil{ this.Data["json"] = models.ReurnError(401, "") this.ServeJSON() + return } idStr := this.Ctx.Input.Param(":id") id, _ := strconv.ParseInt(idStr, 10, 64) @@ -108,23 +121,26 @@ func (this *NoteController) Delete() { if err != nil { this.Data["json"] = models.ReurnError(500,"") this.ServeJSON() + return } if note.UserId != uid.(int64) { this.Data["json"] = models.ReurnError(403, "") this.ServeJSON() + return } err = service.DelNote(note) if err != nil { this.Data["json"] = models.ReurnError(500,"") this.ServeJSON() + return } this.Data["json"] = models.ReurnSuccess("") this.ServeJSON() + return } func (this *NoteController) Note() { uid := this.GetSession("userid") - fmt.Println("userid", uid) if uid == nil { this.Redirect("/login", 302) } diff --git a/controllers/UserController.go b/controllers/UserController.go index 775599d..157eb7c 100644 --- a/controllers/UserController.go +++ b/controllers/UserController.go @@ -39,18 +39,22 @@ func (this *UserController) Login() { if username == "" { this.Data["json"] = models.ReurnError(1,"用户名为空") this.ServeJSON() + return } if len(username) < 4 { this.Data["json"] = models.ReurnError(1,"用户名最低4位") this.ServeJSON() + return } if userpwd == "" { this.Data["json"] = models.ReurnError(1,"密码为空") this.ServeJSON() + return } if len(userpwd) < 6 { this.Data["json"] = models.ReurnError(1,"密码最低6位") this.ServeJSON() + return } user, error := service.FindByUserName(username) if error == nil && user != nil { @@ -68,6 +72,7 @@ func (this *UserController) Login() { this.Data["json"] = models.ReurnError(1,"用户名不存在") } this.ServeJSON() + return } func (this *UserController) Regist() { @@ -78,23 +83,28 @@ func (this *UserController) Regist() { if username == "" { this.Data["json"] = models.ReurnError(1,"用户名为空") this.ServeJSON() + return } if len(username) < 4 { this.Data["json"] = models.ReurnError(1,"用户名最低4位") this.ServeJSON() + return } if userpwd == "" { this.Data["json"] = models.ReurnError(1,"密码为空") this.ServeJSON() + return } if len(userpwd) < 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.ServeJSON() + return } h := md5.New() h.Write([]byte(strconv.FormatInt(time.Now().Unix(), 10) + beego.AppConfig.String("host"))) @@ -110,4 +120,5 @@ func (this *UserController) Regist() { this.Data["json"] = models.ReurnError(1,"注册失败") } this.ServeJSON() + return } diff --git a/models/Result.go b/models/Result.go index 7215e13..60e0e3f 100644 --- a/models/Result.go +++ b/models/Result.go @@ -1,7 +1,7 @@ package models type Error struct { - Status byte + Status int Msg string } @@ -9,11 +9,11 @@ func ReurnError(status int,msg string) *Error { if msg == "" { msg = "error" } - return &Error{Status: byte(status), Msg: msg} + return &Error{Status: status, Msg: msg} } type Success struct { - Status byte + Status int Msg string } @@ -21,5 +21,5 @@ func ReurnSuccess(msg string) *Error { if msg == "" { msg = "success" } - return &Error{Status: byte(0), Msg: msg} + return &Error{Status: 0, Msg: msg} } diff --git a/views/iframe/note.html b/views/iframe/note.html index 631ec18..5ab4127 100644 --- a/views/iframe/note.html +++ b/views/iframe/note.html @@ -59,7 +59,7 @@ parent.layer.msg("保存成功", {icon: 6}); var index = parent.layer.getFrameIndex(window.name); parent.layer.close(index); - } else if (data.Status = 401) { + } else if (data.Status == 401) { parent.location.href = "/login" parent.layer.close(index); } else { diff --git a/views/note.html b/views/note.html index 6eef0fe..0b370c3 100644 --- a/views/note.html +++ b/views/note.html @@ -51,7 +51,6 @@ 管理文件夹 删除笔记 个人中心 - Shortcodes @@ -70,6 +69,11 @@ {{end}} + {{/*{{if len .NoteColls 0}}*/}} + {{/**/}} + {{/*{{end}}*/}} @@ -190,7 +194,6 @@ }, function () { $.post('/note/del/' + note.Id, function (data) { - debugger if (data.Status == 0) { var subMenu = $(".sub-menu li a") $.each(subMenu, function (index, el) {