ソースを参照

无语的return

layui
yirenyishi 6年前
コミット
25982729a8
  1. 1
      controllers/BlogController.go
  2. 20
      controllers/NoteController.go
  3. 11
      controllers/UserController.go
  4. 8
      models/Result.go
  5. 2
      views/iframe/note.html
  6. 7
      views/note.html

1
controllers/BlogController.go

@ -25,6 +25,7 @@ func (this *BlogController) Save() {
this.Data["json"] = models.ReurnError(500,"保存失败")
}
this.ServeJSON()
return
}
func (this *BlogController) Get() {

20
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)
}

11
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
}

8
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}
}

2
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 {

7
views/note.html

@ -51,7 +51,6 @@
<a href="javascript:void(0)" id="newNoteColl">管理文件夹</a>
<a href="javascript:void(0)" id="delNote">删除笔记</a>
<a href="javascript:void(0)">个人中心</a>
<a href="javascript:void(0)">Shortcodes</a>
</nav>
</nav>
</div> <!-- cd-main-content -->
@ -70,6 +69,11 @@
</ul>
</li>
{{end}}
{{/*{{if len .NoteColls 0}}*/}}
{{/*<ul class="cd-navigation cd-single-item-wrapper">*/}}
{{/*<li><a href="javascript:void(0)">新增文件夹</a></li>*/}}
{{/*</ul>*/}}
{{/*{{end}}*/}}
</ul>
</nav>
@ -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) {

読み込み中…
キャンセル
保存