示例#1
0
/*
{
  "NoteId": "550c0bee2ec82a2eb5000000",
  "NotebookId": "54a1676399c37b1c77000004",
  "UserId": "54a1676399c37b1c77000002",
  "Title": "asdfadsf--=",
  "Desc": "",
  "Tags": [
    ""
  ],
  "Abstract": "",
  "Content": "",
  "IsBlog": false,
  "IsTrash": false,
  "Usn": 8,
  "Files": [
    {
      "FileId": "551975d599c37b970f000002",
      "LocalFileId": "",
      "Type": "",
      "Title": "",
      "HasBody": false,
      "IsAttach": false
    },
    {
      "FileId": "551975de99c37b970f000003",
      "LocalFileId": "",
      "Type": "doc",
      "Title": "李铁-简历-ali-print-en.doc",
      "HasBody": false,
      "IsAttach": true
    },
    {
      "FileId": "551975de99c37b970f000004",
      "LocalFileId": "",
      "Type": "doc",
      "Title": "李铁-简历-ali-print.doc",
      "HasBody": false,
      "IsAttach": true
    }
  ],
  "CreatedTime": "2015-03-20T20:00:52.463+08:00",
  "UpdatedTime": "2015-03-31T00:12:44.967+08:00",
  "PublicTime": "2015-03-20T20:00:52.463+08:00"
}
*/
func (c ApiNote) GetNote(noteId string) revel.Result {
	if !bson.IsObjectIdHex(noteId) {
		re := info.NewApiRe()
		re.Msg = "noteIdInvalid"
		return c.RenderJson(re)
	}

	note := noteService.GetNote(noteId, c.getUserId())
	if note.NoteId == "" {
		re := info.NewApiRe()
		re.Msg = "notExists"
		return c.RenderJson(re)
	}
	apiNotes := noteService.ToApiNotes([]info.Note{note})
	return c.RenderJson(apiNotes[0])
}
示例#2
0
// 得到笔记本下的笔记
// [OK]
func (c ApiNote) GetNotes(notebookId string) revel.Result {
	if notebookId != "" && !bson.IsObjectIdHex(notebookId) {
		re := info.NewApiRe()
		re.Msg = "notebookIdInvalid"
		return c.RenderJson(re)
	}
	_, notes := noteService.ListUserNotes(c.getUserId(), notebookId, false, c.GetPage(), pageSize, defaultSortField, false, false)
	return c.RenderJson(noteService.ToApiNotes(notes))
}
示例#3
0
// 修改笔记
// [OK]
func (c ApiNotebook) UpdateNotebook(notebookId, title, parentNotebookId string, seq, usn int) revel.Result {
	re := info.NewApiRe()

	ok, msg, notebook := notebookService.UpdateNotebookApi(c.getUserId(), notebookId, title, parentNotebookId, seq, usn)
	if !ok {
		re.Ok = false
		re.Msg = msg
		return c.RenderJson(re)
	}
	LogJ(notebook)
	return c.RenderJson(c.fixNotebook(&notebook))
}
示例#4
0
// 头像设置
// 参数file=文件
// 成功返回{Logo: url} 头像新url
// [OK]
func (c ApiUser) UpdateLogo() revel.Result {
	ok, msg, url := c.uploadImage()

	if ok {
		ok = userService.UpdateAvatar(c.getUserId(), url)
		return c.RenderJson(map[string]string{"Logo": url})
	} else {
		re := info.NewApiRe()
		re.Msg = msg
		return c.RenderJson(re)
	}
}
示例#5
0
// 修改用户名
// [OK]
func (c ApiUser) UpdateUsername(username string) revel.Result {
	re := info.NewApiRe()
	if c.GetUsername() == "demo" {
		re.Msg = "cannotUpdateDemo"
		return c.RenderJson(re)
	}

	if re.Ok, re.Msg = Vd("username", username); !re.Ok {
		return c.RenderJson(re)
	}

	re.Ok, re.Msg = userService.UpdateUsername(c.getUserId(), username)
	return c.RenderJson(re)
}
示例#6
0
// 修改密码
// [OK]
func (c ApiUser) UpdatePwd(oldPwd, pwd string) revel.Result {
	re := info.NewApiRe()
	if c.GetUsername() == "demo" {
		re.Msg = "cannotUpdateDemo"
		return c.RenderJson(re)
	}
	if re.Ok, re.Msg = Vd("password", oldPwd); !re.Ok {
		return c.RenderJson(re)
	}
	if re.Ok, re.Msg = Vd("password", pwd); !re.Ok {
		return c.RenderJson(re)
	}
	re.Ok, re.Msg = userService.UpdatePwd(c.getUserId(), oldPwd, pwd)
	return c.RenderJson(re)
}
示例#7
0
// 获取用户信息
// [OK]
func (c ApiUser) Info() revel.Result {
	re := info.NewApiRe()

	userInfo := c.getUserInfo()
	if userInfo.UserId == "" {
		return c.RenderJson(re)
	}
	apiUser := info.ApiUser{
		UserId:   userInfo.UserId.Hex(),
		Username: userInfo.Username,
		Email:    userInfo.Email,
		Logo:     userInfo.Logo,
		Verified: userInfo.Verified,
	}
	return c.RenderJson(apiUser)
}
示例#8
0
文件: init.go 项目: nosqldb/zhujian
// 这里得到token, 若不是login, logout等公用操作, 必须验证是否已登录
func AuthInterceptor(c *revel.Controller) revel.Result {
	// 得到token /api/user/info?userId=xxx&token=xxxxx
	token := c.Params.Values.Get("token")
	noToken := false
	if token == "" {
		// 若无, 则取sessionId
		token = c.Session.Id()
		noToken = true
	}
	c.Session["_token"] = token

	// 全部变成首字大写
	var controller = strings.Title(c.Name)
	var method = strings.Title(c.MethodName)

	// 验证是否已登录
	// 通过sessionService判断该token下是否有userId, 并返回userId
	userId := sessionService.GetUserId(token)
	if noToken && userId == "" {
		// 从session中获取, api/file/getImage, api/file/getAttach, api/file/getAllAttach
		// 客户端
		userId, _ = c.Session["UserId"]
	}
	c.Session["_userId"] = userId

	// 是否需要验证?
	if !needValidate(controller, method) {
		return nil
	}

	if userId != "" {
		return nil // 已登录
	}

	// 没有登录, 返回错误的信息, 需要登录
	re := info.NewApiRe()
	re.Msg = "NOTLOGIN"
	return c.RenderJson(re)
}
示例#9
0
// 删除笔记本
// [OK]
func (c ApiNotebook) DeleteNotebook(notebookId string, usn int) revel.Result {
	re := info.NewApiRe()
	re.Ok, re.Msg = notebookService.DeleteNotebookForce(c.getUserId(), notebookId, usn)
	return c.RenderJson(re)
}