Upgrade revel from 0.13 to 0.14

https://github.com/revel/revel/releases/tag/v0.14.0
This commit is contained in:
lealife
2017-04-08 18:55:42 +08:00
parent 721e375d76
commit 6af19670da
39 changed files with 503 additions and 503 deletions

@ -28,12 +28,12 @@ func (c ApiAuth) Login(email, pwd string) revel.Result {
if err == nil {
token := bson.NewObjectId().Hex()
sessionService.SetUserId(token, userInfo.UserId.Hex())
return c.RenderJson(info.AuthOk{Ok: true, Token: token, UserId: userInfo.UserId, Email: userInfo.Email, Username: userInfo.Username})
return c.RenderJSON(info.AuthOk{Ok: true, Token: token, UserId: userInfo.UserId, Email: userInfo.Email, Username: userInfo.Username})
} else {
// 登录错误, 则错误次数++
msg = "wrongUsernameOrPassword"
}
return c.RenderJson(info.ApiRe{Ok: false, Msg: c.Message(msg)})
return c.RenderJSON(info.ApiRe{Ok: false, Msg: c.Message(msg)})
}
// 注销
@ -43,7 +43,7 @@ func (c ApiAuth) Logout() revel.Result {
sessionService.Clear(token)
re := info.NewApiRe()
re.Ok = true
return c.RenderJson(re)
return c.RenderJSON(re)
}
// 注册
@ -53,17 +53,17 @@ func (c ApiAuth) Register(email, pwd string) revel.Result {
re := info.NewApiRe()
if !configService.IsOpenRegister() {
re.Msg = "notOpenRegister" // 未开放注册
return c.RenderJson(re)
return c.RenderJSON(re)
}
if re.Ok, re.Msg = Vd("email", email); !re.Ok {
return c.RenderJson(re)
return c.RenderJSON(re)
}
if re.Ok, re.Msg = Vd("password", pwd); !re.Ok {
return c.RenderJson(re)
return c.RenderJSON(re)
}
// 注册
re.Ok, re.Msg = authService.Register(email, pwd, "")
return c.RenderJson(re)
return c.RenderJSON(re)
}

@ -30,7 +30,7 @@ func (c ApiFile) CopyImage(userId, fileId, toUserId string) revel.Result {
re.Ok, re.Id = fileService.CopyImage(userId, fileId, toUserId)
return c.RenderJson(re)
return c.RenderJSON(re)
}
// get all images by userId with page
@ -39,19 +39,19 @@ func (c ApiFile) GetImages(albumId, key string, page int) revel.Result {
re := info.NewRe()
re.Ok = true
re.Item = imagesPage
return c.RenderJson(re)
return c.RenderJSON(re)
}
func (c ApiFile) UpdateImageTitle(fileId, title string) revel.Result {
re := info.NewRe()
re.Ok = fileService.UpdateImageTitle(c.getUserId(), fileId, title)
return c.RenderJson(re)
return c.RenderJSON(re)
}
func (c ApiFile) DeleteImage(fileId string) revel.Result {
re := info.NewRe()
re.Ok, re.Msg = fileService.DeleteImage(c.getUserId(), fileId)
return c.RenderJson(re)
return c.RenderJSON(re)
}
*/

@ -52,7 +52,7 @@ func (c ApiNote) GetSyncNotes(afterUsn, maxEntry int) revel.Result {
maxEntry = 100
}
notes := noteService.GetSyncNotes(c.getUserId(), afterUsn, maxEntry)
return c.RenderJson(notes)
return c.RenderJSON(notes)
}
// 得到笔记本下的笔记
@ -61,17 +61,17 @@ func (c ApiNote) GetNotes(notebookId string) revel.Result {
if notebookId != "" && !bson.IsObjectIdHex(notebookId) {
re := info.NewApiRe()
re.Msg = "notebookIdInvalid"
return c.RenderJson(re)
return c.RenderJSON(re)
}
_, notes := noteService.ListNotes(c.getUserId(), notebookId, false, c.GetPage(), pageSize, defaultSortField, false, false)
return c.RenderJson(noteService.ToApiNotes(notes))
return c.RenderJSON(noteService.ToApiNotes(notes))
}
// 得到trash
// [OK]
func (c ApiNote) GetTrashNotes() revel.Result {
_, notes := noteService.ListNotes(c.getUserId(), "", true, c.GetPage(), pageSize, defaultSortField, false, false)
return c.RenderJson(noteService.ToApiNotes(notes))
return c.RenderJSON(noteService.ToApiNotes(notes))
}
@ -127,17 +127,17 @@ func (c ApiNote) GetNote(noteId string) revel.Result {
if !bson.IsObjectIdHex(noteId) {
re := info.NewApiRe()
re.Msg = "noteIdInvalid"
return c.RenderJson(re)
return c.RenderJSON(re)
}
note := noteService.GetNote(noteId, c.getUserId())
if note.NoteId == "" {
re := info.NewApiRe()
re.Msg = "notExists"
return c.RenderJson(re)
return c.RenderJSON(re)
}
apiNotes := noteService.ToApiNotes([]info.Note{note})
return c.RenderJson(apiNotes[0])
return c.RenderJSON(apiNotes[0])
}
// 得到note和内容
@ -148,7 +148,7 @@ func (c ApiNote) GetNoteAndContent(noteId string) revel.Result {
apiNotes := noteService.ToApiNotes([]info.Note{noteAndContent.Note})
apiNote := apiNotes[0]
apiNote.Content = noteService.FixContent(noteAndContent.Content, noteAndContent.IsMarkdown)
return c.RenderJson(apiNote)
return c.RenderJSON(apiNote)
}
// content里的image, attach链接是
@ -207,7 +207,7 @@ func (c ApiNote) GetNoteContent(noteId string) revel.Result {
Content: noteContent.Content,
}
return c.RenderJson(apiNoteContent)
return c.RenderJSON(apiNoteContent)
}
// 添加笔记
@ -233,10 +233,10 @@ func (c ApiNote) AddNote(noteOrContent info.ApiNote) revel.Result {
LogJ(file)
}
*/
// return c.RenderJson(re)
// return c.RenderJSON(re)
if noteOrContent.NotebookId == "" || !bson.IsObjectIdHex(noteOrContent.NotebookId) {
re.Msg = "notebookIdNotExists"
return c.RenderJson(re)
return c.RenderJSON(re)
}
noteId := bson.NewObjectId()
@ -259,7 +259,7 @@ func (c ApiNote) AddNote(noteOrContent info.ApiNote) revel.Result {
}
// 报不是图片的错误没关系, 证明客户端传来非图片的数据
if msg != "notImage" {
return c.RenderJson(re)
return c.RenderJSON(re)
}
} else {
// 建立映射
@ -271,7 +271,7 @@ func (c ApiNote) AddNote(noteOrContent info.ApiNote) revel.Result {
}
}
} else {
return c.RenderJson(re)
return c.RenderJSON(re)
}
}
}
@ -282,7 +282,7 @@ func (c ApiNote) AddNote(noteOrContent info.ApiNote) revel.Result {
// Log("Add")
// LogJ(noteOrContent)
// return c.RenderJson(re)
// return c.RenderJSON(re)
note := info.Note{UserId: userId,
NoteId: noteId,
@ -318,7 +318,7 @@ func (c ApiNote) AddNote(noteOrContent info.ApiNote) revel.Result {
if note.NoteId == "" {
re.Ok = false
return c.RenderJson(re)
return c.RenderJSON(re)
}
// 添加需要返回的
@ -332,7 +332,7 @@ func (c ApiNote) AddNote(noteOrContent info.ApiNote) revel.Result {
noteOrContent.Content = ""
noteOrContent.Abstract = ""
// apiNote := info.NoteToApiNote(note, noteOrContent.Files)
return c.RenderJson(noteOrContent)
return c.RenderJSON(noteOrContent)
}
// 更新笔记
@ -347,12 +347,12 @@ func (c ApiNote) UpdateNote(noteOrContent info.ApiNote) revel.Result {
if noteOrContent.NoteId == "" {
re.Msg = "noteIdNotExists"
return c.RenderJson(re)
return c.RenderJSON(re)
}
if noteOrContent.Usn <= 0 {
re.Msg = "usnNotExists"
return c.RenderJson(re)
return c.RenderJSON(re)
}
// Log("_____________")
@ -368,12 +368,12 @@ func (c ApiNote) UpdateNote(noteOrContent info.ApiNote) revel.Result {
note := noteService.GetNote(noteId, userId)
if note.NoteId == "" {
re.Msg = "notExists"
return c.RenderJson(re)
return c.RenderJSON(re)
}
if note.Usn != noteOrContent.Usn {
re.Msg = "conflict"
Log("conflict")
return c.RenderJson(re)
return c.RenderJSON(re)
}
Log("没有冲突")
@ -402,14 +402,14 @@ func (c ApiNote) UpdateNote(noteOrContent info.ApiNote) revel.Result {
} else {
re.Msg = msg
}
return c.RenderJson(re)
return c.RenderJSON(re)
} else {
// 建立映射
file.FileId = fileId
noteOrContent.Files[i] = file
}
} else {
return c.RenderJson(re)
return c.RenderJSON(re)
}
}
}
@ -490,7 +490,7 @@ func (c ApiNote) UpdateNote(noteOrContent info.ApiNote) revel.Result {
if !noteOk {
re.Ok = false
re.Msg = noteMsg
return c.RenderJson(re)
return c.RenderJSON(re)
}
}
@ -528,7 +528,7 @@ func (c ApiNote) UpdateNote(noteOrContent info.ApiNote) revel.Result {
}
if !re.Ok {
return c.RenderJson(re)
return c.RenderJSON(re)
}
noteOrContent.Content = ""
@ -539,14 +539,14 @@ func (c ApiNote) UpdateNote(noteOrContent info.ApiNote) revel.Result {
// LogJ(noteOrContent.Files)
noteOrContent.UserId = c.getUserId()
return c.RenderJson(noteOrContent)
return c.RenderJSON(noteOrContent)
}
// 删除trash
func (c ApiNote) DeleteTrash(noteId string, usn int) revel.Result {
re := info.NewReUpdate()
re.Ok, re.Msg, re.Usn = trashService.DeleteTrashApi(noteId, c.getUserId(), usn)
return c.RenderJson(re)
return c.RenderJSON(re)
}
// 得到历史列表
@ -558,7 +558,7 @@ func (c ApiNote) GetHistories(noteId string) revel.Result {
re.Ok = true
re.Item = histories
}
return c.RenderJson(re)
return c.RenderJSON(re)
}
*/
@ -569,13 +569,13 @@ func (c ApiNote) ExportPdf(noteId string) revel.Result {
userId := c.getUserId()
if noteId == "" {
re.Msg = "noteNotExists"
return c.RenderJson(re)
return c.RenderJSON(re)
}
note := noteService.GetNoteById(noteId)
if note.NoteId == "" {
re.Msg = "noteNotExists"
return c.RenderJson(re)
return c.RenderJSON(re)
}
noteUserId := note.UserId.Hex()
@ -584,7 +584,7 @@ func (c ApiNote) ExportPdf(noteId string) revel.Result {
// 是否是有权限协作的
if !note.IsBlog && !shareService.HasReadPerm(noteUserId, userId, noteId) {
re.Msg = "noteNotExists"
return c.RenderJson(re)
return c.RenderJSON(re)
}
}
@ -594,7 +594,7 @@ func (c ApiNote) ExportPdf(noteId string) revel.Result {
dir := revel.BasePath + "/" + fileUrlPath
if !MkdirAll(dir) {
re.Msg = "noDir"
return c.RenderJson(re)
return c.RenderJSON(re)
}
filename := guid + ".pdf"
path := dir + "/" + filename
@ -623,12 +623,12 @@ func (c ApiNote) ExportPdf(noteId string) revel.Result {
_, err := cmd.Output()
if err != nil {
re.Msg = "sysError"
return c.RenderJson(re)
return c.RenderJSON(re)
}
file, err := os.Open(path)
if err != nil {
re.Msg = "sysError"
return c.RenderJson(re)
return c.RenderJSON(re)
}
filenameReturn := note.Title

@ -53,7 +53,7 @@ func (c ApiNotebook) GetSyncNotebooks(afterUsn, maxEntry int) revel.Result {
maxEntry = 100
}
notebooks := notebookService.GeSyncNotebooks(c.getUserId(), afterUsn, maxEntry)
return c.RenderJson(c.fixNotebooks(notebooks))
return c.RenderJSON(c.fixNotebooks(notebooks))
}
// 得到用户的所有笔记本
@ -61,7 +61,7 @@ func (c ApiNotebook) GetSyncNotebooks(afterUsn, maxEntry int) revel.Result {
// info.SubNotebooks
func (c ApiNotebook) GetNotebooks() revel.Result {
notebooks := notebookService.GeSyncNotebooks(c.getUserId(), 0, 99999)
return c.RenderJson(c.fixNotebooks(notebooks))
return c.RenderJSON(c.fixNotebooks(notebooks))
}
// 添加notebook
@ -77,9 +77,9 @@ func (c ApiNotebook) AddNotebook(title, parentNotebookId string, seq int) revel.
re := info.NewRe()
re.Ok, notebook = notebookService.AddNotebook(notebook)
if !re.Ok {
return c.RenderJson(re)
return c.RenderJSON(re)
}
return c.RenderJson(c.fixNotebook(&notebook))
return c.RenderJSON(c.fixNotebook(&notebook))
}
// 修改笔记
@ -91,10 +91,10 @@ func (c ApiNotebook) UpdateNotebook(notebookId, title, parentNotebookId string,
if !ok {
re.Ok = false
re.Msg = msg
return c.RenderJson(re)
return c.RenderJSON(re)
}
LogJ(notebook)
return c.RenderJson(c.fixNotebook(&notebook))
return c.RenderJSON(c.fixNotebook(&notebook))
}
// 删除笔记本
@ -102,5 +102,5 @@ func (c ApiNotebook) UpdateNotebook(notebookId, title, parentNotebookId string,
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)
return c.RenderJSON(re)
}

@ -23,7 +23,7 @@ func (c ApiTag) GetSyncTags(afterUsn, maxEntry int) revel.Result {
maxEntry = 100
}
tags := tagService.GeSyncTags(c.getUserId(), afterUsn, maxEntry)
return c.RenderJson(tags)
return c.RenderJSON(tags)
}
// 添加Tag
@ -44,7 +44,7 @@ func (c ApiTag) GetSyncTags(afterUsn, maxEntry int) revel.Result {
*/
func (c ApiTag) AddTag(tag string) revel.Result {
ret := tagService.AddOrUpdateTag(c.getUserId(), tag)
return c.RenderJson(ret)
return c.RenderJSON(ret)
}
// 删除标签
@ -52,5 +52,5 @@ func (c ApiTag) AddTag(tag string) revel.Result {
func (c ApiTag) DeleteTag(tag string, usn int) revel.Result {
re := info.NewReUpdate()
re.Ok, re.Msg, re.Usn = tagService.DeleteTagApi(c.getUserId(), tag, usn)
return c.RenderJson(re)
return c.RenderJSON(re)
}

@ -28,7 +28,7 @@ func (c ApiUser) Info() revel.Result {
userInfo := c.getUserInfo()
if userInfo.UserId == "" {
return c.RenderJson(re)
return c.RenderJSON(re)
}
apiUser := info.ApiUser{
UserId: userInfo.UserId.Hex(),
@ -37,7 +37,7 @@ func (c ApiUser) Info() revel.Result {
Logo: userInfo.Logo,
Verified: userInfo.Verified,
}
return c.RenderJson(apiUser)
return c.RenderJSON(apiUser)
}
// 修改用户名
@ -46,15 +46,15 @@ func (c ApiUser) UpdateUsername(username string) revel.Result {
re := info.NewApiRe()
if c.GetUsername() == "demo" {
re.Msg = "cannotUpdateDemo"
return c.RenderJson(re)
return c.RenderJSON(re)
}
if re.Ok, re.Msg = Vd("username", username); !re.Ok {
return c.RenderJson(re)
return c.RenderJSON(re)
}
re.Ok, re.Msg = userService.UpdateUsername(c.getUserId(), username)
return c.RenderJson(re)
return c.RenderJSON(re)
}
// 修改密码
@ -63,23 +63,23 @@ func (c ApiUser) UpdatePwd(oldPwd, pwd string) revel.Result {
re := info.NewApiRe()
if c.GetUsername() == "demo" {
re.Msg = "cannotUpdateDemo"
return c.RenderJson(re)
return c.RenderJSON(re)
}
if re.Ok, re.Msg = Vd("password", oldPwd); !re.Ok {
return c.RenderJson(re)
return c.RenderJSON(re)
}
if re.Ok, re.Msg = Vd("password", pwd); !re.Ok {
return c.RenderJson(re)
return c.RenderJSON(re)
}
re.Ok, re.Msg = userService.UpdatePwd(c.getUserId(), oldPwd, pwd)
return c.RenderJson(re)
return c.RenderJSON(re)
}
// 获得同步状态
// [OK]
func (c ApiUser) GetSyncState() revel.Result {
ret := bson.M{"LastSyncUsn": userService.GetUsn(c.getUserId()), "LastSyncTime": time.Now().Unix()}
return c.RenderJson(ret)
return c.RenderJSON(ret)
}
// 头像设置
@ -91,11 +91,11 @@ func (c ApiUser) UpdateLogo() revel.Result {
if ok {
ok = userService.UpdateAvatar(c.getUserId(), url)
return c.RenderJson(map[string]string{"Logo": url})
return c.RenderJSON(map[string]string{"Logo": url})
} else {
re := info.NewApiRe()
re.Msg = msg
return c.RenderJson(re)
return c.RenderJSON(re)
}
}

@ -75,7 +75,7 @@ func AuthInterceptor(c *revel.Controller) revel.Result {
noToken := false
if token == "" {
// 若无, 则取sessionId
token = c.Session.Id()
token = c.Session.ID()
noToken = true
}
c.Session["_token"] = token
@ -106,7 +106,7 @@ func AuthInterceptor(c *revel.Controller) revel.Result {
// 没有登录, 返回错误的信息, 需要登录
re := info.NewApiRe()
re.Msg = "NOTLOGIN"
return c.RenderJson(re)
return c.RenderJSON(re)
}
func init() {