2014-10-22 16:20:45 +08:00
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/leanote/leanote/app/info"
|
2015-11-13 17:58:41 +08:00
|
|
|
. "github.com/leanote/leanote/app/lea"
|
|
|
|
"github.com/revel/revel"
|
2014-10-22 16:20:45 +08:00
|
|
|
"strconv"
|
2015-11-13 17:58:41 +08:00
|
|
|
"strings"
|
2014-10-22 16:20:45 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// admin 首页
|
|
|
|
|
|
|
|
type AdminEmail struct {
|
|
|
|
AdminBaseController
|
|
|
|
}
|
|
|
|
|
|
|
|
// email配置
|
|
|
|
func (c AdminEmail) Email() revel.Result {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// blog标签设置
|
|
|
|
func (c AdminEmail) Blog() revel.Result {
|
|
|
|
recommendTags := configService.GetGlobalArrayConfig("recommendTags")
|
|
|
|
newTags := configService.GetGlobalArrayConfig("newTags")
|
|
|
|
c.RenderArgs["recommendTags"] = strings.Join(recommendTags, ",")
|
|
|
|
c.RenderArgs["newTags"] = strings.Join(newTags, ",")
|
2015-11-13 17:58:41 +08:00
|
|
|
return c.RenderTemplate("admin/setting/blog.html")
|
2014-10-22 16:20:45 +08:00
|
|
|
}
|
|
|
|
func (c AdminEmail) DoBlogTag(recommendTags, newTags string) revel.Result {
|
|
|
|
re := info.NewRe()
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
re.Ok = configService.UpdateGlobalArrayConfig(c.GetUserId(), "recommendTags", strings.Split(recommendTags, ","))
|
|
|
|
re.Ok = configService.UpdateGlobalArrayConfig(c.GetUserId(), "newTags", strings.Split(newTags, ","))
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
return c.RenderJson(re)
|
|
|
|
}
|
|
|
|
|
|
|
|
// demo
|
|
|
|
// blog标签设置
|
|
|
|
func (c AdminEmail) Demo() revel.Result {
|
|
|
|
c.RenderArgs["demoUsername"] = configService.GetGlobalStringConfig("demoUsername")
|
|
|
|
c.RenderArgs["demoPassword"] = configService.GetGlobalStringConfig("demoPassword")
|
2015-11-13 17:58:41 +08:00
|
|
|
return c.RenderTemplate("admin/setting/demo.html")
|
2014-10-22 16:20:45 +08:00
|
|
|
}
|
|
|
|
func (c AdminEmail) DoDemo(demoUsername, demoPassword string) revel.Result {
|
|
|
|
re := info.NewRe()
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2015-09-06 23:16:56 +08:00
|
|
|
userInfo, err := authService.Login(demoUsername, demoPassword)
|
|
|
|
if err != nil {
|
|
|
|
return c.RenderJson(info.Re{Ok: false})
|
|
|
|
}
|
2014-10-22 16:20:45 +08:00
|
|
|
if userInfo.UserId == "" {
|
2015-11-13 17:58:41 +08:00
|
|
|
re.Msg = "The User is Not Exists"
|
2014-10-22 16:20:45 +08:00
|
|
|
return c.RenderJson(re)
|
|
|
|
}
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
re.Ok = configService.UpdateGlobalStringConfig(c.GetUserId(), "demoUserId", userInfo.UserId.Hex())
|
|
|
|
re.Ok = configService.UpdateGlobalStringConfig(c.GetUserId(), "demoUsername", demoUsername)
|
|
|
|
re.Ok = configService.UpdateGlobalStringConfig(c.GetUserId(), "demoPassword", demoPassword)
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
return c.RenderJson(re)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToImage
|
|
|
|
// 长微博的bin路径phantomJs
|
|
|
|
func (c AdminEmail) ToImage() revel.Result {
|
|
|
|
c.RenderArgs["toImageBinPath"] = configService.GetGlobalStringConfig("toImageBinPath")
|
2015-11-13 17:58:41 +08:00
|
|
|
return c.RenderTemplate("admin/setting/toImage.html")
|
2014-10-22 16:20:45 +08:00
|
|
|
}
|
|
|
|
func (c AdminEmail) DoToImage(toImageBinPath string) revel.Result {
|
|
|
|
re := info.NewRe()
|
|
|
|
re.Ok = configService.UpdateGlobalStringConfig(c.GetUserId(), "toImageBinPath", toImageBinPath)
|
|
|
|
return c.RenderJson(re)
|
|
|
|
}
|
|
|
|
|
2016-10-29 16:38:13 +08:00
|
|
|
func (c AdminEmail) Set(emailHost, emailPort, emailUsername, emailPassword, emailSSL string) revel.Result {
|
2014-10-22 16:20:45 +08:00
|
|
|
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)
|
2016-10-29 16:38:13 +08:00
|
|
|
re.Ok = configService.UpdateGlobalStringConfig(c.GetUserId(), "emailSSL", emailSSL)
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
return c.RenderJson(re)
|
|
|
|
}
|
|
|
|
func (c AdminEmail) Template() revel.Result {
|
|
|
|
re := info.NewRe()
|
2015-11-13 17:58:41 +08:00
|
|
|
|
|
|
|
keys := []string{"emailTemplateHeader", "emailTemplateFooter",
|
2014-10-22 16:20:45 +08:00
|
|
|
"emailTemplateRegisterSubject",
|
|
|
|
"emailTemplateRegister",
|
|
|
|
"emailTemplateFindPasswordSubject",
|
|
|
|
"emailTemplateFindPassword",
|
|
|
|
"emailTemplateUpdateEmailSubject",
|
|
|
|
"emailTemplateUpdateEmail",
|
|
|
|
"emailTemplateInviteSubject",
|
|
|
|
"emailTemplateInvite",
|
|
|
|
"emailTemplateCommentSubject",
|
|
|
|
"emailTemplateComment",
|
|
|
|
}
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
re.Ok = true
|
|
|
|
return c.RenderJson(re)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 发送Email
|
|
|
|
func (c AdminEmail) SendEmailToEmails(sendEmails, latestEmailSubject, latestEmailBody string, verified, saveAsOldEmail bool) revel.Result {
|
|
|
|
re := info.NewRe()
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
c.updateConfig([]string{"sendEmails", "latestEmailSubject", "latestEmailBody"})
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
if latestEmailSubject == "" || latestEmailBody == "" {
|
|
|
|
re.Msg = "subject or body is blank"
|
|
|
|
return c.RenderJson(re)
|
|
|
|
}
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
if saveAsOldEmail {
|
|
|
|
oldEmails := configService.GetGlobalMapConfig("oldEmails")
|
|
|
|
oldEmails[latestEmailSubject] = latestEmailBody
|
2015-11-13 17:58:41 +08:00
|
|
|
configService.UpdateGlobalMapConfig(c.GetUserId(), "oldEmails", oldEmails)
|
2014-10-22 16:20:45 +08:00
|
|
|
}
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
sendEmails = strings.Replace(sendEmails, "\r", "", -1)
|
|
|
|
emails := strings.Split(sendEmails, "\n")
|
2015-11-13 17:58:41 +08:00
|
|
|
|
|
|
|
re.Ok, re.Msg = emailService.SendEmailToEmails(emails, latestEmailSubject, latestEmailBody)
|
2014-10-22 16:20:45 +08:00
|
|
|
return c.RenderJson(re)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 发送Email
|
|
|
|
func (c AdminEmail) SendToUsers2(emails, latestEmailSubject, latestEmailBody string, verified, saveAsOldEmail bool) revel.Result {
|
|
|
|
re := info.NewRe()
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
c.updateConfig([]string{"sendEmails", "latestEmailSubject", "latestEmailBody"})
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
if latestEmailSubject == "" || latestEmailBody == "" {
|
|
|
|
re.Msg = "subject or body is blank"
|
|
|
|
return c.RenderJson(re)
|
|
|
|
}
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
if saveAsOldEmail {
|
|
|
|
oldEmails := configService.GetGlobalMapConfig("oldEmails")
|
|
|
|
oldEmails[latestEmailSubject] = latestEmailBody
|
2015-11-13 17:58:41 +08:00
|
|
|
configService.UpdateGlobalMapConfig(c.GetUserId(), "oldEmails", oldEmails)
|
2014-10-22 16:20:45 +08:00
|
|
|
}
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
emails = strings.Replace(emails, "\r", "", -1)
|
|
|
|
emailsArr := strings.Split(emails, "\n")
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
users := userService.ListUserInfosByEmails(emailsArr)
|
|
|
|
LogJ(emailsArr)
|
2015-11-13 17:58:41 +08:00
|
|
|
|
|
|
|
re.Ok, re.Msg = emailService.SendEmailToUsers(users, latestEmailSubject, latestEmailBody)
|
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
return c.RenderJson(re)
|
|
|
|
}
|
|
|
|
|
|
|
|
// send Email dialog
|
2015-11-13 17:58:41 +08:00
|
|
|
func (c AdminEmail) SendEmailDialog(emails string) revel.Result {
|
2014-10-22 16:20:45 +08:00
|
|
|
emailsArr := strings.Split(emails, ",")
|
|
|
|
emailsNl := strings.Join(emailsArr, "\n")
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
c.RenderArgs["emailsNl"] = emailsNl
|
|
|
|
c.RenderArgs["str"] = configService.GlobalStringConfigs
|
|
|
|
c.RenderArgs["map"] = configService.GlobalMapConfigs
|
2015-11-13 17:58:41 +08:00
|
|
|
|
|
|
|
return c.RenderTemplate("admin/email/emailDialog.html")
|
2014-10-22 16:20:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c AdminEmail) SendToUsers(userFilterEmail, userFilterWhiteList, userFilterBlackList, latestEmailSubject, latestEmailBody string, verified, saveAsOldEmail bool) revel.Result {
|
|
|
|
re := info.NewRe()
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
c.updateConfig([]string{"userFilterEmail", "userFilterWhiteList", "userFilterBlackList", "latestEmailSubject", "latestEmailBody"})
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
if latestEmailSubject == "" || latestEmailBody == "" {
|
|
|
|
re.Msg = "subject or body is blank"
|
|
|
|
return c.RenderJson(re)
|
|
|
|
}
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
if saveAsOldEmail {
|
|
|
|
oldEmails := configService.GetGlobalMapConfig("oldEmails")
|
|
|
|
oldEmails[latestEmailSubject] = latestEmailBody
|
2015-11-13 17:58:41 +08:00
|
|
|
configService.UpdateGlobalMapConfig(c.GetUserId(), "oldEmails", oldEmails)
|
2014-10-22 16:20:45 +08:00
|
|
|
}
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
users := userService.GetAllUserByFilter(userFilterEmail, userFilterWhiteList, userFilterBlackList, verified)
|
2015-11-13 17:58:41 +08:00
|
|
|
|
|
|
|
if users == nil || len(users) == 0 {
|
2014-10-22 16:20:45 +08:00
|
|
|
re.Ok = false
|
|
|
|
re.Msg = "no users"
|
|
|
|
return c.RenderJson(re)
|
|
|
|
}
|
2015-11-13 17:58:41 +08:00
|
|
|
|
|
|
|
re.Ok, re.Msg = emailService.SendEmailToUsers(users, latestEmailSubject, latestEmailBody)
|
|
|
|
if !re.Ok {
|
2014-10-22 16:20:45 +08:00
|
|
|
return c.RenderJson(re)
|
|
|
|
}
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
re.Ok = true
|
|
|
|
re.Msg = "users:" + strconv.Itoa(len(users))
|
2015-11-13 17:58:41 +08:00
|
|
|
|
2014-10-22 16:20:45 +08:00
|
|
|
return c.RenderJson(re)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 删除emails
|
|
|
|
func (c AdminEmail) DeleteEmails(ids string) revel.Result {
|
|
|
|
re := info.NewRe()
|
|
|
|
re.Ok = emailService.DeleteEmails(strings.Split(ids, ","))
|
|
|
|
return c.RenderJson(re)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c AdminEmail) List(sorter, keywords string) revel.Result {
|
|
|
|
pageNumber := c.GetPage()
|
2015-11-13 17:58:41 +08:00
|
|
|
sorterField, isAsc := c.getSorter("CreatedTime", false, []string{"email", "ok", "subject", "createdTime"})
|
|
|
|
pageInfo, emails := emailService.ListEmailLogs(pageNumber, userPageSize, sorterField, isAsc, keywords)
|
2014-10-22 16:20:45 +08:00
|
|
|
c.RenderArgs["pageInfo"] = pageInfo
|
|
|
|
c.RenderArgs["emails"] = emails
|
|
|
|
c.RenderArgs["keywords"] = keywords
|
2015-11-13 17:58:41 +08:00
|
|
|
return c.RenderTemplate("admin/email/list.html")
|
|
|
|
}
|