コード例 #1
0
ファイル: AuthService.go プロジェクト: nosqldb/zhujian
func (this *AuthService) register(user info.User) (bool, string) {
	if userService.AddUser(user) {
		// 添加笔记本, 生活, 学习, 工作
		userId := user.UserId.Hex()
		notebook := info.Notebook{
			Seq:    -1,
			UserId: user.UserId}
		title2Id := map[string]bson.ObjectId{"life": bson.NewObjectId(), "study": bson.NewObjectId(), "work": bson.NewObjectId()}
		for title, objectId := range title2Id {
			notebook.Title = title
			notebook.NotebookId = objectId
			notebook.UserId = user.UserId
			notebookService.AddNotebook(notebook)
		}

		// 添加leanote -> 该用户的共享
		registerSharedUserId := configService.GetGlobalStringConfig("registerSharedUserId")
		if registerSharedUserId != "" {
			registerSharedNotebooks := configService.GetGlobalArrMapConfig("registerSharedNotebooks")
			registerSharedNotes := configService.GetGlobalArrMapConfig("registerSharedNotes")
			registerCopyNoteIds := configService.GetGlobalArrayConfig("registerCopyNoteIds")

			// 添加共享笔记本
			for _, notebook := range registerSharedNotebooks {
				perm, _ := strconv.Atoi(notebook["perm"])
				shareService.AddShareNotebookToUserId(notebook["notebookId"], perm, registerSharedUserId, userId)
			}

			// 添加共享笔记
			for _, note := range registerSharedNotes {
				perm, _ := strconv.Atoi(note["perm"])
				shareService.AddShareNoteToUserId(note["noteId"], perm, registerSharedUserId, userId)
			}

			// 复制笔记
			for _, noteId := range registerCopyNoteIds {
				note := noteService.CopySharedNote(noteId, title2Id["life"].Hex(), registerSharedUserId, user.UserId.Hex())
				//				Log(noteId)
				//				Log("Copy")
				//				LogJ(note)
				noteUpdate := bson.M{"IsBlog": false} // 不要是博客
				noteService.UpdateNote(user.UserId.Hex(), note.NoteId.Hex(), noteUpdate, -1)
			}
		}

		//---------------
		// 添加一条userBlog
		blogService.UpdateUserBlog(info.UserBlog{UserId: user.UserId,
			Title:      user.Username + " 's Blog",
			SubTitle:   "Love Leanote!",
			AboutMe:    "Hello, I am (^_^)",
			CanComment: true,
		})
		// 添加一个单页面
		blogService.AddOrUpdateSingle(user.UserId.Hex(), "", "About Me", "Hello, I am (^_^)")
	}

	return true, ""
}
コード例 #2
0
ファイル: NotebookService.go プロジェクト: nosqldb/zhujian
// 添加
// [ok]
func (this *NotebookService) AddNotebook(notebook info.Notebook) (bool, info.Notebook) {
	notebook.UrlTitle = GetUrTitle(notebook.UserId.Hex(), notebook.Title, "notebook")
	notebook.Usn = userService.IncrUsn(notebook.UserId.Hex())
	now := time.Now()
	notebook.CreatedTime = now
	notebook.UpdatedTime = now
	err := db.Notebooks.Insert(notebook)
	if err != nil {
		return false, notebook
	}
	return true, notebook
}
コード例 #3
0
// 添加notebook
// [OK]
func (c ApiNotebook) AddNotebook(title, parentNotebookId string, seq int) revel.Result {
	notebook := info.Notebook{NotebookId: bson.NewObjectId(),
		Title:  title,
		Seq:    seq,
		UserId: bson.ObjectIdHex(c.getUserId())}
	if parentNotebookId != "" && bson.IsObjectIdHex(parentNotebookId) {
		notebook.ParentNotebookId = bson.ObjectIdHex(parentNotebookId)
	}
	re := info.NewRe()
	re.Ok, notebook = notebookService.AddNotebook(notebook)
	if !re.Ok {
		return c.RenderJson(re)
	}
	return c.RenderJson(c.fixNotebook(&notebook))
}
コード例 #4
0
ファイル: NotebookController.go プロジェクト: nosqldb/zhujian
// 添加notebook
func (c Notebook) AddNotebook(notebookId, title, parentNotebookId string) revel.Result {
	notebook := info.Notebook{NotebookId: bson.ObjectIdHex(notebookId),
		Title:  title,
		Seq:    -1,
		UserId: c.GetObjectUserId()}
	if parentNotebookId != "" {
		notebook.ParentNotebookId = bson.ObjectIdHex(parentNotebookId)
	}

	re, notebook := notebookService.AddNotebook(notebook)

	if re {
		return c.RenderJson(notebook)
	} else {
		return c.RenderJson(false)
	}
}