Exemplo n.º 1
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.º 2
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)
	}

	email = strings.ToLower(email)

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

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

	return c.RenderRe(re)
}
Exemplo n.º 3
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.ListBlogs(userId, notebookId, page, 5, userBlog.SortField, userBlog.IsAsc)
	re := info.NewRe()
	re.Ok = true
	re.List = blogs
	return c.RenderJsonP(callback, re)
}
Exemplo n.º 4
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.º 5
0
//------------
// 第三方账号添加leanote账号
func (c User) AddAccount(email, pwd string) revel.Result {
	re := info.NewRe()

	if email == "" {
		re.Msg = "请输入邮箱"
		return c.RenderJson(re)
	} else if !IsEmail(email) {
		re.Msg = "请输入正确的邮箱"
		return c.RenderJson(re)
	}

	// 密码
	if pwd == "" {
		re.Msg = "请输入密码"
		return c.RenderJson(re)
	} else if len(pwd) < 6 {
		re.Msg = "密码长度至少6位"
		return c.RenderJson(re)
	}

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

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

	return c.RenderJson(re)
}
Exemplo n.º 6
0
//-----------------
// html2image
func (c Note) Html2Image(noteId string) revel.Result {
	re := info.NewRe()
	userId := c.GetUserId()
	note := noteService.GetNote(noteId, userId)
	if note.NoteId == "" {
		return c.RenderJson(re)
	}
	content := noteService.GetNoteContent(noteId, userId)

	// path 判断是否需要重新生成之
	fileUrlPath := "/upload/" + userId + "/images/weibo"
	dir := revel.BasePath + "/public/" + fileUrlPath
	if !ClearDir(dir) {
		return c.RenderJson(re)
	}

	filename := note.NoteId.Hex() + ".png"
	path := dir + "/" + filename

	// 生成之
	html2image.ToImage(userId, c.GetUsername(), noteId, note.Title, content.Content, path)

	re.Ok = true
	re.Id = fileUrlPath + "/" + filename
	return c.RenderJson(re)
}
Exemplo n.º 7
0
func (c Auth) DoRegister(email, pwd string) revel.Result {
	if !openRegister {
		return c.Redirect("/index")
	}

	re := info.NewRe()

	if email == "" {
		re.Msg = c.Message("inputEmail")
		return c.RenderJson(re)
	} else if !IsEmail(email) {
		re.Msg = c.Message("wrongEmail")
		return c.RenderJson(re)
	}

	// 密码
	if pwd == "" {
		re.Msg = c.Message("inputPassword")
		return c.RenderJson(re)
	} else if len(pwd) < 6 {
		re.Msg = c.Message("wrongPassword")
		return c.RenderJson(re)
	}

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

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

	return c.RenderJson(re)
}
Exemplo n.º 8
0
func (c AdminSetting) Mongodb(mongodumpPath, mongorestorePath string) revel.Result {
	re := info.NewRe()
	re.Ok = configService.UpdateGlobalStringConfig(c.GetUserId(), "mongodumpPath", mongodumpPath)
	re.Ok = configService.UpdateGlobalStringConfig(c.GetUserId(), "mongorestorePath", mongorestorePath)

	return c.RenderJson(re)
}
Exemplo n.º 9
0
func (c AdminEmail) SendToUsers(userFilterEmail, userFilterWhiteList, userFilterBlackList, latestEmailSubject, latestEmailBody string, verified, saveAsOldEmail bool) revel.Result {
	re := info.NewRe()

	c.updateConfig([]string{"userFilterEmail", "userFilterWhiteList", "userFilterBlackList", "latestEmailSubject", "latestEmailBody"})

	if latestEmailSubject == "" || latestEmailBody == "" {
		re.Msg = "subject or body is blank"
		return c.RenderJson(re)
	}

	if saveAsOldEmail {
		oldEmails := configService.GetGlobalMapConfig("oldEmails")
		oldEmails[latestEmailSubject] = latestEmailBody
		configService.UpdateGlobalMapConfig(c.GetUserId(), "oldEmails", oldEmails)
	}

	users := userService.GetAllUserByFilter(userFilterEmail, userFilterWhiteList, userFilterBlackList, verified)

	if users == nil || len(users) == 0 {
		re.Ok = false
		re.Msg = "no users"
		return c.RenderJson(re)
	}

	re.Ok, re.Msg = emailService.SendEmailToUsers(users, latestEmailSubject, latestEmailBody)
	if !re.Ok {
		return c.RenderJson(re)
	}

	re.Ok = true
	re.Msg = "users:" + strconv.Itoa(len(users))

	return c.RenderJson(re)
}
Exemplo n.º 10
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.º 11
0
func (c AdminEmail) Template() revel.Result {
	re := info.NewRe()

	keys := []string{"emailTemplateHeader", "emailTemplateFooter",
		"emailTemplateRegisterSubject",
		"emailTemplateRegister",
		"emailTemplateFindPasswordSubject",
		"emailTemplateFindPassword",
		"emailTemplateUpdateEmailSubject",
		"emailTemplateUpdateEmail",
		"emailTemplateInviteSubject",
		"emailTemplateInvite",
		"emailTemplateCommentSubject",
		"emailTemplateComment",
	}

	userId := c.GetUserId()
	for _, key := range keys {
		v := c.Params.Values.Get(key)
		if v != "" {
			ok, msg := emailService.ValidTpl(v)
			if !ok {
				re.Ok = false
				re.Msg = "Error key: " + key + "<br />" + msg
				return c.RenderJson(re)
			} else {
				configService.UpdateGlobalStringConfig(userId, key, v)
			}
		}
	}

	re.Ok = true
	return c.RenderJson(re)
}
Exemplo n.º 12
0
// 发送Email
func (c AdminEmail) SendToUsers2(emails, latestEmailSubject, latestEmailBody string, verified, saveAsOldEmail bool) revel.Result {
	re := info.NewRe()

	c.updateConfig([]string{"sendEmails", "latestEmailSubject", "latestEmailBody"})

	if latestEmailSubject == "" || latestEmailBody == "" {
		re.Msg = "subject or body is blank"
		return c.RenderJson(re)
	}

	if saveAsOldEmail {
		oldEmails := configService.GetGlobalMapConfig("oldEmails")
		oldEmails[latestEmailSubject] = latestEmailBody
		configService.UpdateGlobalMapConfig(c.GetUserId(), "oldEmails", oldEmails)
	}

	emails = strings.Replace(emails, "\r", "", -1)
	emailsArr := strings.Split(emails, "\n")

	users := userService.ListUserInfosByEmails(emailsArr)
	LogJ(emailsArr)

	re.Ok, re.Msg = emailService.SendEmailToUsers(users, latestEmailSubject, latestEmailBody)

	return c.RenderJson(re)
}
Exemplo n.º 13
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.º 14
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.º 15
0
// 复制外网的图片
// 都要好好的计算大小
func (c File) CopyHttpImage(src string) revel.Result {
	re := info.NewRe()

	// 生成上传路径
	newGuid := NewGuid()
	userId := c.GetUserId()
	// fileUrlPath := "files/" + Digest3(userId) + "/" + userId + "/" + Digest2(newGuid) + "/images"
	fileUrlPath := "files/" + GetRandomFilePath(userId, newGuid) + "/images"
	dir := revel.BasePath + "/" + 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.º 16
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.º 17
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.º 18
0
// 共享设置
func (c AdminSetting) ShareNote(registerSharedUserId string,
	registerSharedNotebookPerms, registerSharedNotePerms []int,
	registerSharedNotebookIds, registerSharedNoteIds, registerCopyNoteIds []string) revel.Result {

	re := info.NewRe()
	re.Ok, re.Msg = configService.UpdateShareNoteConfig(registerSharedUserId, registerSharedNotebookPerms, registerSharedNotePerms, registerSharedNotebookIds, registerSharedNoteIds, registerCopyNoteIds)
	return c.RenderJson(re)
}
Exemplo n.º 19
0
func (c AdminSetting) UploadSize(uploadImageSize, uploadAvatarSize, uploadBlogLogoSize, uploadAttachSize float64) revel.Result {
	re := info.NewRe()
	re.Ok = configService.UpdateGlobalStringConfig(c.GetUserId(), "uploadImageSize", fmt.Sprintf("%v", uploadImageSize))
	re.Ok = configService.UpdateGlobalStringConfig(c.GetUserId(), "uploadAvatarSize", fmt.Sprintf("%v", uploadAvatarSize))
	re.Ok = configService.UpdateGlobalStringConfig(c.GetUserId(), "uploadBlogLogoSize", fmt.Sprintf("%v", uploadBlogLogoSize))
	re.Ok = configService.UpdateGlobalStringConfig(c.GetUserId(), "uploadAttachSize", fmt.Sprintf("%v", uploadAttachSize))
	return c.RenderJson(re)
}
Exemplo n.º 20
0
func (c AdminEmail) DoBlogTag(recommendTags, newTags string) revel.Result {
	re := info.NewRe()

	re.Ok = configService.UpdateGlobalArrayConfig(c.GetUserId(), "recommendTags", strings.Split(recommendTags, ","))
	re.Ok = configService.UpdateGlobalArrayConfig(c.GetUserId(), "newTags", strings.Split(newTags, ","))

	return c.RenderJson(re)
}
Exemplo n.º 21
0
func (c AdminSetting) HomePage(homePage string) revel.Result {
	re := info.NewRe()
	if homePage == "0" {
		homePage = ""
	}
	re.Ok = configService.UpdateGlobalStringConfig(c.GetUserId(), "homePage", homePage)
	return c.RenderJson(re)
}
Exemplo n.º 22
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.º 23
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.º 24
0
//-----------------
// 用户偏爱
func (c User) UpdateColumnWidth(notebookWidth, noteListWidth int) revel.Result {
	re := info.NewRe()
	re.Ok = userService.UpdateColumnWidth(c.GetUserId(), notebookWidth, noteListWidth)
	if re.Ok {
		c.UpdateSession("NotebookWidth", strconv.Itoa(notebookWidth))
		c.UpdateSession("NoteListWidth", strconv.Itoa(noteListWidth))
	}
	return c.RenderJson(re)
}
Exemplo n.º 25
0
func (c AdminEmail) Set(emailHost, emailPort, emailUsername, emailPassword string) revel.Result {
	re := info.NewRe()
	re.Ok = configService.UpdateGlobalStringConfig(c.GetUserId(), "emailHost", emailHost)
	re.Ok = configService.UpdateGlobalStringConfig(c.GetUserId(), "emailPort", emailPort)
	re.Ok = configService.UpdateGlobalStringConfig(c.GetUserId(), "emailUsername", emailUsername)
	re.Ok = configService.UpdateGlobalStringConfig(c.GetUserId(), "emailPassword", emailPassword)

	return c.RenderJson(re)
}
Exemplo n.º 26
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)
}
// 添加用户
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.º 28
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() {
		SendToLeanote("建议", "建议", "UserId: "+c.GetUserId()+" <br /> Suggestions: "+suggestion)
	}()

	return c.RenderJson(re)
}
Exemplo n.º 29
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.º 30
0
// 复制别人共享的笔记给我
func (c Note) CopySharedNote(noteIds []string, notebookId, fromUserId string) revel.Result {
	copyNotes := make([]info.Note, len(noteIds))
	userId := c.GetUserId()
	for i, noteId := range noteIds {
		copyNotes[i] = noteService.CopySharedNote(noteId, notebookId, fromUserId, userId)
	}
	re := info.NewRe()
	re.Ok = true
	re.Item = copyNotes
	return c.RenderJson(re)
}