Exemplo n.º 1
0
// 显示分类的最近博客, jsonp
func (c Blog) ListCateLatest(notebookId, callback string) revel.Result {
	if notebookId == "" {
		return c.e404("")
	}
	// 自定义域名
	hasDomain, userBlog := c.domain()
	userId := ""
	if hasDomain {
		userId = userBlog.UserId.Hex()
	}

	var notebook info.Notebook
	notebook = notebookService.GetNotebookById(notebookId)
	if !notebook.IsBlog {
		return c.e404(userBlog.ThemePath)
	}
	if userId != "" && userId != notebook.UserId.Hex() {
		return c.e404(userBlog.ThemePath)
	}
	userId = notebook.UserId.Hex()

	var ok = false
	if ok, userBlog = c.blogCommon(userId, userBlog, info.User{}); !ok {
		return c.e404(userBlog.ThemePath)
	}

	// 分页的话, 需要分页信息, totalPage, curPage
	page := 1
	_, blogs := blogService.ListUserBlogs(userId, notebookId, page, 5, userBlog.SortField, userBlog.IsAsc)
	re := info.NewRe()
	re.Ok = true
	re.List = blogs
	return c.RenderJsonP(callback, re)
}
Exemplo n.º 2
0
// 复制外网的图片, 成公共图片 放在/upload下
// 都要好好的计算大小
func (c File) CopyHttpImage(src string) revel.Result {
	re := info.NewRe()
	fileUrlPath := "upload/" + c.GetUserId() + "/images"
	dir := revel.BasePath + "/public/" + fileUrlPath
	err := os.MkdirAll(dir, 0755)
	if err != nil {
		return c.RenderJson(re)
	}
	filesize, filename, _, ok := netutil.WriteUrl(src, dir)

	if !ok {
		re.Msg = "copy error"
		return c.RenderJson(re)
	}

	// File
	fileInfo := info.File{Name: filename,
		Title: filename,
		Path:  fileUrlPath + "/" + filename,
		Size:  filesize}

	id := bson.NewObjectId()
	fileInfo.FileId = id

	re.Id = id.Hex()
	re.Item = fileInfo.Path
	re.Ok, re.Msg = fileService.AddImage(fileInfo, "", c.GetUserId(), true)

	return c.RenderJson(re)
}
Exemplo n.º 3
0
// 得到文件内容
func (c MemberBlog) GetTplContent(themeId string, filename string) revel.Result {
	re := info.NewRe()
	re.Ok = true
	re.Item = themeService.GetTplContent(c.GetUserId(), themeId, filename)

	return c.RenderJson(re)
}
Exemplo n.º 4
0
// jsonp
func (c Blog) LikeComment(commentId string, callback string) revel.Result {
	re := info.NewRe()
	ok, isILikeIt, num := blogService.LikeComment(commentId, c.GetUserId())
	re.Ok = ok
	re.Item = bson.M{"IsILikeIt": isILikeIt, "Num": num}
	return c.RenderJsonP(callback, re)
}
Exemplo n.º 5
0
func AuthInterceptor(c *revel.Controller) revel.Result {
	// 全部变成首字大写
	/*
		var controller = strings.Title(c.Name)
		var method = strings.Title(c.MethodName)
		// 是否需要验证?
		if !needValidate(controller, method) {
			return nil
		}
	*/

	// 验证是否已登录
	// 必须是管理员
	if username, ok := c.Session["Username"]; ok && username == configService.GetAdminUsername() {
		return nil // 已登录
	}

	// 没有登录, 判断是否是ajax操作
	if c.Request.Header.Get("X-Requested-With") == "XMLHttpRequest" {
		re := info.NewRe()
		re.Msg = "NOTLOGIN"
		return c.RenderJson(re)
	}

	return c.Redirect("/login")
}
Exemplo n.º 6
0
func (c Blog) GetLikesAndComments(noteId, callback string) revel.Result {
	userId := c.GetUserId()
	result := map[string]interface{}{}

	// 我也点过?
	isILikeIt := false
	if userId != "" {
		isILikeIt = blogService.IsILikeIt(noteId, userId)
		result["visitUserInfo"] = userService.GetUserAndBlog(userId)
	}

	// 点赞用户列表
	likedUsers, hasMoreLikedUser := blogService.ListLikedUsers(noteId, false)
	// 评论
	page := c.GetPage()
	pageInfo, comments, commentUserInfo := blogService.ListComments(userId, noteId, page, 15)

	re := info.NewRe()
	re.Ok = true
	result["isILikeIt"] = isILikeIt
	result["likedUsers"] = likedUsers
	result["hasMoreLikedUser"] = hasMoreLikedUser
	result["pageInfo"] = pageInfo
	result["comments"] = comments
	result["commentUserInfo"] = commentUserInfo
	re.Item = result
	return c.RenderJsonP(callback, re)
}
Exemplo n.º 7
0
// 得到博客统计信息
func (c Blog) GetPostStat(noteId string) revel.Result {
	re := info.NewRe()
	re.Ok = true
	statInfo := blogService.GetBlogStat(noteId)
	re.Item = statInfo
	return c.RenderJson(re)
}
Exemplo n.º 8
0
func (c AdminUser) DoResetPwd(userId, pwd string) revel.Result {
	re := info.NewRe()
	if re.Ok, re.Msg = Vd("password", pwd); !re.Ok {
		return c.RenderRe(re)
	}
	re.Ok, re.Msg = userService.ResetPwd(c.GetUserId(), userId, pwd)
	return c.RenderRe(re)
}
Exemplo n.º 9
0
// 更新主题
func (c User) UpdateTheme(theme string) revel.Result {
	re := info.NewRe()
	re.Ok = userService.UpdateTheme(c.GetUserId(), theme)
	if re.Ok {
		c.UpdateSession("Theme", theme)
	}
	return c.RenderJson(re)
}
Exemplo n.º 10
0
// 发送邀请链接
func (c User) SendRegisterEmail(content, toEmail string) revel.Result {
	re := info.NewRe()
	if content == "" || !IsEmail(toEmail) {
		return c.RenderJson(re)
	}

	re.Ok = emailService.SendInviteEmail(c.GetUserInfo(), toEmail, content)
	return c.RenderJson(re)
}
Exemplo n.º 11
0
func (c MemberBlog) ListThemeImages(themeId string) revel.Result {
	re := info.NewRe()
	userId := c.GetUserId()
	path := themeService.GetThemeAbsolutePath(userId, themeId) + "/images"
	os.MkdirAll(path, 0755)
	images := ListDir(path)
	re.List = images
	re.Ok = true
	return c.RenderJson(re)
}
Exemplo n.º 12
0
// 找回密码修改密码
func (c Auth) FindPasswordUpdate(token, pwd string) revel.Result {
	re := info.NewRe()

	if re.Ok, re.Msg = Vd("password", pwd); !re.Ok {
		return c.RenderRe(re)
	}

	// 修改之
	re.Ok, re.Msg = pwdService.UpdatePwd(token, pwd)
	return c.RenderRe(re)
}
Exemplo n.º 13
0
// 添加用户
func (c MemberGroup) AddUser(groupId, email string) revel.Result {
	re := info.NewRe()
	userInfo := userService.GetUserInfoByAny(email)
	if userInfo.UserId == "" {
		re.Msg = "userNotExists"
	} else {
		re.Ok, re.Msg = groupService.AddUser(c.GetUserId(), groupId, userInfo.UserId.Hex())
		re.Item = userInfo
	}
	return c.RenderRe(re)
}
Exemplo n.º 14
0
// 建议
func (c Index) Suggestion(addr, suggestion string) revel.Result {
	re := info.NewRe()
	re.Ok = suggestionService.AddSuggestion(info.Suggestion{Addr: addr, UserId: c.GetObjectUserId(), Suggestion: suggestion})

	// 发给我
	go func() {
		emailService.SendEmail("*****@*****.**", "建议", "UserId: "+c.GetUserId()+" <br /> Suggestions: "+suggestion)
	}()

	return c.RenderJson(re)
}
Exemplo n.º 15
0
//-----------------
// 用户偏爱
func (c User) UpdateColumnWidth(notebookWidth, noteListWidth, mdEditorWidth int) revel.Result {
	re := info.NewRe()
	re.Ok = userService.UpdateColumnWidth(c.GetUserId(), notebookWidth, noteListWidth, mdEditorWidth)
	if re.Ok {
		c.UpdateSession("NotebookWidth", strconv.Itoa(notebookWidth))
		c.UpdateSession("NoteListWidth", strconv.Itoa(noteListWidth))
		c.UpdateSession("MdEditorWidth", strconv.Itoa(mdEditorWidth))

		LogJ(c.Session)
	}
	return c.RenderJson(re)
}
Exemplo n.º 16
0
func (c User) UpdateLeftIsMin(leftIsMin bool) revel.Result {
	re := info.NewRe()
	re.Ok = userService.UpdateLeftIsMin(c.GetUserId(), leftIsMin)
	if re.Ok {
		if leftIsMin {
			c.UpdateSession("LeftIsMin", "1")
		} else {
			c.UpdateSession("LeftIsMin", "0")
		}
	}
	return c.RenderJson(re)
}
Exemplo n.º 17
0
// 导出
func (c MemberBlog) ExportTheme(themeId string) revel.Result {
	re := info.NewRe()
	var path string
	re.Ok, path = themeService.ExportTheme(c.GetUserId(), themeId)
	if !re.Ok {
		return c.RenderText("error...")
	}
	fw, err := os.Open(path)
	if err != nil {
		return c.RenderText("error")
	}
	return c.RenderBinary(fw, GetFilename(path), revel.Attachment, time.Now()) // revel.Attachment
}
Exemplo n.º 18
0
// 修改Email发送激活邮箱
func (c User) UpdateEmailSendActiveEmail(email string) revel.Result {
	re := info.NewRe()
	if c.GetUsername() == "demo" {
		re.Msg = "cannotUpdateDemo"
		return c.RenderJson(re)
	}
	if re.Ok, re.Msg = Vd("email", email); !re.Ok {
		return c.RenderRe(re)
	}

	re.Ok, re.Msg = emailService.UpdateEmailSendActiveEmail(c.GetUserInfo(), email)
	return c.RenderRe(re)
}
Exemplo n.º 19
0
// 导入主题
func (c MemberBlog) ImportTheme() revel.Result {
	re := info.NewRe()

	file, handel, err := c.Request.FormFile("file")
	if err != nil {
		re.Msg = fmt.Sprintf("%v", err)
		return c.RenderJson(re)

	}
	defer file.Close()
	// 生成上传路径
	userId := c.GetUserId()
	dir := revel.BasePath + "/public/upload/" + userId + "/tmp"
	err = os.MkdirAll(dir, 0755)
	if err != nil {
		re.Msg = fmt.Sprintf("%v", err)
		return c.RenderJson(re)
	}
	// 生成新的文件名
	filename := handel.Filename

	var ext string
	_, ext = SplitFilename(filename)
	if ext != ".zip" {
		re.Msg = "Please upload zip file"
		return c.RenderJson(re)
	}

	filename = filename
	data, err := ioutil.ReadAll(file)
	if err != nil {
		return c.RenderJson(re)
	}

	// > 10M?
	if len(data) > 10*1024*1024 {
		re.Msg = "File is big than 10M"
		return c.RenderJson(re)
	}

	toPath := dir + "/" + filename
	err = ioutil.WriteFile(toPath, data, 0777)
	if err != nil {
		re.Msg = fmt.Sprintf("%v", err)
		return c.RenderJson(re)
	}

	// 上传好后, 增加之
	re.Ok, re.Msg = themeService.ImportTheme(c.GetUserId(), toPath)
	return c.RenderRe(re)
}
Exemplo n.º 20
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))
}
Exemplo n.º 21
0
// 添加
func (c AdminUser) Register(email, pwd string) revel.Result {
	re := info.NewRe()

	if re.Ok, re.Msg = Vd("email", email); !re.Ok {
		return c.RenderRe(re)
	}
	if re.Ok, re.Msg = Vd("password", pwd); !re.Ok {
		return c.RenderRe(re)
	}

	// 注册
	re.Ok, re.Msg = authService.Register(email, pwd, "")

	return c.RenderRe(re)
}
Exemplo n.º 22
0
// 修改密码
func (c User) UpdatePwd(oldPwd, pwd string) revel.Result {
	re := info.NewRe()
	if c.GetUsername() == "demo" {
		re.Msg = "cannotUpdateDemo"
		return c.RenderRe(re)
	}
	if re.Ok, re.Msg = Vd("password", oldPwd); !re.Ok {
		return c.RenderRe(re)
	}
	if re.Ok, re.Msg = Vd("password", pwd); !re.Ok {
		return c.RenderRe(re)
	}
	re.Ok, re.Msg = userService.UpdatePwd(c.GetUserId(), oldPwd, pwd)
	return c.RenderRe(re)
}
Exemplo n.º 23
0
// 修改用户名, 需要重置session
func (c User) UpdateUsername(username string) revel.Result {
	re := info.NewRe()
	if c.GetUsername() == "demo" {
		re.Msg = "cannotUpdateDemo"
		return c.RenderRe(re)
	}

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

	re.Ok, re.Msg = userService.UpdateUsername(c.GetUserId(), username)
	if re.Ok {
		c.UpdateSession("Username", username)
	}
	return c.RenderRe(re)
}
Exemplo n.º 24
0
//------------
// 第三方账号添加leanote账号
func (c User) AddAccount(email, pwd string) revel.Result {
	re := info.NewRe()

	if re.Ok, re.Msg = Vd("email", email); !re.Ok {
		return c.RenderRe(re)
	}
	if re.Ok, re.Msg = Vd("password", pwd); !re.Ok {
		return c.RenderRe(re)
	}

	re.Ok, re.Msg = userService.ThirdAddUser(c.GetUserId(), email, pwd)

	if re.Ok {
		c.UpdateSession("Email", email)
	}

	return c.RenderRe(re)
}
Exemplo n.º 25
0
func (c Blog) GetComments(noteId string, callback string) revel.Result {
	// 评论
	userId := c.GetUserId()
	page := c.GetPage()
	pageInfo, comments, commentUserInfo := blogService.ListComments(userId, noteId, page, 15)
	re := info.NewRe()
	re.Ok = true
	result := map[string]interface{}{}
	result["pageInfo"] = pageInfo
	result["comments"] = comments
	result["commentUserInfo"] = commentUserInfo
	re.Item = result

	if callback != "" {
		return c.RenderJsonP(callback, result)
	}

	return c.RenderJson(re)
}
Exemplo n.º 26
0
// jsonP
// 我是否点过赞? 得到我的信息
// 所有点赞的用户列表
// 各个评论中是否我也点过赞?
func (c Blog) GetLikes(noteId string, callback string) revel.Result {
	userId := c.GetUserId()
	result := map[string]interface{}{}
	isILikeIt := false
	if userId != "" {
		isILikeIt = blogService.IsILikeIt(noteId, userId)
		result["visitUserInfo"] = userService.GetUserAndBlog(userId)
	}
	// 点赞用户列表
	likedUsers, hasMoreLikedUser := blogService.ListLikedUsers(noteId, false)

	re := info.NewRe()
	re.Ok = true
	result["isILikeIt"] = isILikeIt
	result["likedUsers"] = likedUsers
	result["hasMoreLikedUser"] = hasMoreLikedUser

	re.Item = result
	return c.RenderJsonP(callback, re)
}
Exemplo n.º 27
0
func (c Auth) DoRegister(email, pwd, iu string) revel.Result {
	if !configService.IsOpenRegister() {
		return c.Redirect("/index")
	}

	re := info.NewRe()

	if re.Ok, re.Msg = Vd("email", email); !re.Ok {
		return c.RenderRe(re)
	}
	if re.Ok, re.Msg = Vd("password", pwd); !re.Ok {
		return c.RenderRe(re)
	}

	// 注册
	re.Ok, re.Msg = authService.Register(email, pwd, iu)

	// 注册成功, 则立即登录之
	if re.Ok {
		c.doLogin(email, pwd)
	}

	return c.RenderRe(re)
}
Exemplo n.º 28
0
func (c AdminUpgrade) UpgradeBeta3ToBeta4() revel.Result {
	re := info.NewRe()
	re.Ok, re.Msg = upgradeService.Api(c.GetUserId())
	return c.RenderJson(re)
}
Exemplo n.º 29
0
func (c AdminData) Backup() revel.Result {
	re := info.NewRe()
	re.Ok, re.Msg = configService.Backup("")
	return c.RenderJson(re)
}
Exemplo n.º 30
0
// 修改笔记的urlTitle
func (c MemberBlog) UpdateBlogUrlTitle(noteId, urlTitle string) revel.Result {
	re := info.NewRe()
	re.Ok, re.Item = blogService.UpateBlogUrlTitle(c.GetUserId(), noteId, urlTitle)
	return c.RenderJson(re)
}