diff --git a/app/controllers/ShareController.go b/app/controllers/ShareController.go index 0ae851e..9a39d5d 100644 --- a/app/controllers/ShareController.go +++ b/app/controllers/ShareController.go @@ -9,6 +9,7 @@ import ( // "github.com/leanote/leanote/app/types" // "io/ioutil" // "fmt" +// "time" ) type Share struct { @@ -204,16 +205,25 @@ func (c Share) QuerySharePass(noteId string) revel.Result { //展示分享笔记 func (c Share) ShowShareNote(noteId string) revel.Result { -// note := noteService.GetNote(noteId, c.GetUserId()) + note := noteService.GetNote(noteId, c.GetUserId()) // -// c.RenderArgs["title"] = note.UserId -// c.RenderArgs["title"] = note.UserId + c.RenderArgs["noteId"] = noteId + username := userService.GetUsernameById(note.UserId) + + c.RenderArgs["userName"] = username + c.RenderArgs["isMarkDown"] = note.IsMarkdown +// c.RenderArgs["timestamp"] = time.Now().Unix() + c.SetLocale() 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 +func (c Share) Verify4ShareNote(noteId string, sharePass int) revel.Result { + ok, note := shareService.Verify4ShareNote(noteId, sharePass); + attaches := []info.Attach{} + if (ok == true && note.AttachNum > 0) { + attaches = attachService.ListAttachs(noteId, c.GetUserId()) + } + re := info.Re{Ok : ok, Item: note, List: attaches} + return c.RenderJson(re) +} \ No newline at end of file diff --git a/app/service/ShareService.go b/app/service/ShareService.go index 28fbe84..e8ed5f1 100644 --- a/app/service/ShareService.go +++ b/app/service/ShareService.go @@ -783,11 +783,8 @@ func (this *ShareService) DeleteShareNotebookGroup(userId, notebookId, groupId s func (this *ShareService) GenSharePass(noteId string) (int, bool) { r := rand.New(rand.NewSource(time.Now().UnixNano())) - pass := 1000 + r.Intn(10000) + pass := 1000 + r.Intn(9000) - 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 } @@ -798,3 +795,14 @@ func (this *ShareService) QuerySharePass(noteId string) int { return note.SharePass } + +func (this *ShareService) Verify4ShareNote(noteId string, sharePass int) (bool, *info.Note) { + note := &info.Note{} + db.Get(db.Notes, noteId, note) + if note.SharePass == sharePass { + return true, note + } else { + note := &info.Note{} + return false, note + } +} diff --git a/app/service/UserService.go b/app/service/UserService.go index cea7c79..851d1b8 100644 --- a/app/service/UserService.go +++ b/app/service/UserService.go @@ -48,6 +48,13 @@ func (this *UserService) GetUsername(userId string) string { return user.Username } +// 得到用户名 +func (this *UserService) GetUsernameById(userId bson.ObjectId) string { + user := info.User{} + db.GetByQWithFields(db.Users, bson.M{"_id": userId}, []string{"Username"}, &user) + return user.Username +} + // 是否存在该用户 email func (this *UserService) IsExistsUser(email string) bool { if this.GetUserId(email) == "" { diff --git a/app/views/share/note_notebook_share_user_infos.html b/app/views/share/note_notebook_share_user_infos.html index ac13e52..add31c5 100644 --- a/app/views/share/note_notebook_share_user_infos.html +++ b/app/views/share/note_notebook_share_user_infos.html @@ -125,18 +125,33 @@ Share.dialogIsNote = {{.isNote}}; Share.dialogNoteOrNotebookId = '{{.noteOrNotebookId}}'; +var getHost = function(url) { + var host = "null"; + if(typeof url == "undefined" + || null == url) + url = window.location.href; + var regex = /.*\:\/\/([^\/]*).*/; + var match = url.match(regex); + if(typeof match != "undefined" + && null != match) + host = match[1]; + return host; +} + + $(function() { setTimeout(function() { $("#tr1 #friendsEmail").focus(); }, 500); +var host = getHost(); if (Share.dialogIsNote) { var url = "/share/querySharePass"; var data = {noteId: Share.dialogNoteOrNotebookId}; ajaxPost(url, data, function(re) { if(reIsOk(re)) { if (re.Item >= 1000 && re.Item < 10000) { - var shareLink = "https://leanote.com/share/" + '{{.noteOrNotebookId}}'; + var shareLink = host + '/share/note/{{.noteOrNotebookId}}'; $("#shareLink").val(shareLink); $("#sharePass").val(re.Item); } @@ -204,13 +219,13 @@ $("#groupInfo").on("click", ".btn-share-or-not", function() { //生成分享链接和密码 $("#genShareLink").on("click", function() { var sharePass = $("#sharePass").val(); - if (sharePass != '' && sharePass > 1000 ) { + if (sharePass != '' && sharePass > 1000 && sharePass < 10000) { $("#showMsg").html("不能重复生成分享链接和密码"); return; } var url = "/share/genShareLinkPass"; - var shareLink = "https://leanote.com/share/note/" + '{{.noteOrNotebookId}}'; + var shareLink = host + '/share/note/{{.noteOrNotebookId}}'; var data = {noteId: Share.dialogNoteOrNotebookId}; ajaxPost(url, data, function(re) { if(reIsOk(re)) { diff --git a/app/views/share/show_share_note.html b/app/views/share/show_share_note.html index a54b363..4db6479 100644 --- a/app/views/share/show_share_note.html +++ b/app/views/share/show_share_note.html @@ -1,83 +1,134 @@ - - - - - - - - - - -leanote, Not Just A Notebook +{{template "home/header.html" .}} - - - +
+
+{{$isMarkDown := .isMarkDown}} - - - +
+ {{ .userName }}分享了笔记

+ + 您需要输入分享密码才能查看:

+ +

+ +
+ +
+ + +{{template "home/footer.html"}} + + + + - - - -查看分享笔记{{.noteId}} - -您需要输入分享密码才能查看:
-
- - - - - - - - - - - - - - - - - - - +{{if $isMarkDown}} + + + + + + + + + + + +{{end}} \ No newline at end of file