share note to unregistered users

share note to unregistered users
This commit is contained in:
binnchx
2015-01-03 17:57:52 +08:00
parent e2e90f8618
commit 599e54de5b
5 changed files with 208 additions and 2 deletions

View File

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