From 599e54de5bd2024750e62f065932f03b23d9fbcb Mon Sep 17 00:00:00 2001 From: binnchx Date: Sat, 3 Jan 2015 17:57:52 +0800 Subject: [PATCH] share note to unregistered users share note to unregistered users --- app/controllers/ShareController.go | 33 +++++++- app/info/NoteInfo.go | 2 + app/service/ShareService.go | 22 +++++ .../share/note_notebook_share_user_infos.html | 70 +++++++++++++++- app/views/share/show_share_note.html | 83 +++++++++++++++++++ 5 files changed, 208 insertions(+), 2 deletions(-) create mode 100644 app/views/share/show_share_note.html diff --git a/app/controllers/ShareController.go b/app/controllers/ShareController.go index 9630b0b..0ae851e 100644 --- a/app/controllers/ShareController.go +++ b/app/controllers/ShareController.go @@ -36,6 +36,8 @@ func (c Share) AddShareNote(noteId string, emails []string, perm int) revel.Resu return c.RenderJson(status) } + + // 添加共享notebook func (c Share) AddShareNotebook(notebookId string, emails []string, perm int) revel.Result { status := make(map[string]info.Re, len(emails)) @@ -185,4 +187,33 @@ func (c Share) DeleteShareNotebookGroup(notebookId, groupId string) revel.Result // 更新, 也是一样, 先删后加 func (c Share) UpdateShareNotebookGroupPerm(notebookId, groupId string, perm int) revel.Result { return c.AddShareNotebookGroup(notebookId, groupId, perm) -} \ No newline at end of file +} + +//生成笔记分享密码及更新到db +func (c Share) GenShareLinkPass(noteId string) revel.Result { + pass, ok := shareService.GenSharePass(noteId) + re := info.Re{Ok : true, Item : pass, List: ok} + return c.RenderJson(re); +} + +func (c Share) QuerySharePass(noteId string) revel.Result { + pass := shareService.QuerySharePass(noteId) + re := info.Re{Ok : true, Item : pass} + return c.RenderJson(re); +} + +//展示分享笔记 +func (c Share) ShowShareNote(noteId string) revel.Result { +// note := noteService.GetNote(noteId, c.GetUserId()) +// +// c.RenderArgs["title"] = note.UserId +// c.RenderArgs["title"] = note.UserId + return c.RenderTemplate("share/show_share_note.html") +} + +//验证分享密码 +//func (c Share) Verify4ShareNote(noteId string, sharePass int) revel.Result { +// ok = shareService.Verify4ShareNote(noteId, sharePass); +// re := info.Re{Ok : true, Item : pass} +// +//} \ No newline at end of file diff --git a/app/info/NoteInfo.go b/app/info/NoteInfo.go index a1bce49..96e77ef 100644 --- a/app/info/NoteInfo.go +++ b/app/info/NoteInfo.go @@ -40,6 +40,8 @@ type Note struct { RecommendTime time.Time `RecommendTime,omitempty` // 推荐时间 PublicTime time.Time `PublicTime,omitempty` // 发表时间, 公开为博客则设置 UpdatedUserId bson.ObjectId `bson:"UpdatedUserId"` // 如果共享了, 并可写, 那么可能是其它他修改了 + + SharePass int `SharePass` //分享笔记的密码 } // 内容 diff --git a/app/service/ShareService.go b/app/service/ShareService.go index 40219b3..28fbe84 100644 --- a/app/service/ShareService.go +++ b/app/service/ShareService.go @@ -7,6 +7,7 @@ import ( "gopkg.in/mgo.v2/bson" "time" "sort" + "math/rand" ) // 共享Notebook, Note服务 @@ -336,12 +337,14 @@ func (this *ShareService) AddShareNote(noteId string, perm int, userId, email st "ToUserId": bson.ObjectIdHex(toUserId), }); + shareNote := info.ShareNote{NoteId: bson.ObjectIdHex(noteId), UserId: bson.ObjectIdHex(userId), ToUserId: bson.ObjectIdHex(toUserId), Perm: perm, CreatedTime: time.Now(), } + return db.Insert(db.ShareNotes, shareNote), "", toUserId } @@ -776,3 +779,22 @@ func (this *ShareService) DeleteShareNotebookGroup(userId, notebookId, groupId s "ToGroupId": bson.ObjectIdHex(groupId), }); } + + +func (this *ShareService) GenSharePass(noteId string) (int, bool) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + pass := 1000 + r.Intn(10000) + + if pass >= 10000 { + pass -= 1000 + } + ok := db.Update(db.Notes, bson.M{"_id": bson.ObjectIdHex(noteId)}, bson.M{"$set": bson.M{"SharePass": pass}}) + return pass, ok +} + +func (this *ShareService) QuerySharePass(noteId string) int { + note := &info.Note{} + db.Get(db.Notes, noteId, note) + + return note.SharePass +} diff --git a/app/views/share/note_notebook_share_user_infos.html b/app/views/share/note_notebook_share_user_infos.html index 785e3ef..ac13e52 100644 --- a/app/views/share/note_notebook_share_user_infos.html +++ b/app/views/share/note_notebook_share_user_infos.html @@ -5,11 +5,14 @@ {{$noteOrNotebookId := .noteOrNotebookId}} - + {{$isNote := .isNote}} @@ -108,11 +124,40 @@ \ No newline at end of file diff --git a/app/views/share/show_share_note.html b/app/views/share/show_share_note.html new file mode 100644 index 0000000..a54b363 --- /dev/null +++ b/app/views/share/show_share_note.html @@ -0,0 +1,83 @@ + + + + + + + + + + +leanote, Not Just A Notebook + + + + + + + + + + + + + +查看分享笔记{{.noteId}} + +您需要输入分享密码才能查看:
+
+ + + + + + + + + + + + + + + + + + + +