siteurl, adminUsername config in configService

This commit is contained in:
life
2014-11-10 16:26:04 +08:00
parent 954c4e5e95
commit 6555384e5c
16 changed files with 118 additions and 98 deletions

View File

@ -183,7 +183,7 @@ func (c BaseController) SetLocale() string {
lang = "en"; lang = "en";
} }
c.RenderArgs["locale"] = lang; c.RenderArgs["locale"] = lang;
c.RenderArgs["siteUrl"] = siteUrl; c.RenderArgs["siteUrl"] = configService.GetSiteUrl();
c.RenderArgs["blogUrl"] = configService.GetBlogUrl() c.RenderArgs["blogUrl"] = configService.GetBlogUrl()
c.RenderArgs["leaUrl"] = configService.GetLeaUrl() c.RenderArgs["leaUrl"] = configService.GetLeaUrl()
@ -196,7 +196,7 @@ func (c BaseController) SetLocale() string {
func (c BaseController) SetUserInfo() { func (c BaseController) SetUserInfo() {
userInfo := c.GetUserInfo() userInfo := c.GetUserInfo()
c.RenderArgs["userInfo"] = userInfo c.RenderArgs["userInfo"] = userInfo
if(userInfo.Username == adminUsername) { if(userInfo.Username == configService.GetAdminUsername()) {
c.RenderArgs["isAdmin"] = true c.RenderArgs["isAdmin"] = true
} }
} }
@ -242,4 +242,4 @@ func (c BaseController) RenderRe(re info.Re) revel.Result {
} }
} }
return c.RenderJson(re) return c.RenderJson(re)
} }

View File

@ -104,6 +104,7 @@ func (c Blog) setPreviewUrl() {
themeId := c.Session["themeId"] themeId := c.Session["themeId"]
theme := themeService.GetTheme(userId, themeId) theme := themeService.GetTheme(userId, themeId)
siteUrl := configService.GetSiteUrl()
blogUrl := siteUrl + "/preview" // blog.leanote.com blogUrl := siteUrl + "/preview" // blog.leanote.com
userIdOrEmail := userId userIdOrEmail := userId
@ -137,6 +138,7 @@ func (c Blog) setUrl(userBlog info.UserBlog, userInfo info.User) {
staticUrl = configService.GetUserUrl(strings.Split(host, ":")[0]) staticUrl = configService.GetUserUrl(strings.Split(host, ":")[0])
// staticUrl == host, 为保证同源!!! 只有host, http://leanote.com, http://blog/leanote.com // staticUrl == host, 为保证同源!!! 只有host, http://leanote.com, http://blog/leanote.com
// life.leanote.com, lealife.com // life.leanote.com, lealife.com
siteUrl := configService.GetSiteUrl()
if userBlog.Domain != "" && configService.AllowCustomDomain() { if userBlog.Domain != "" && configService.AllowCustomDomain() {
// ok // ok
indexUrl = configService.GetUserUrl(userBlog.Domain) indexUrl = configService.GetUserUrl(userBlog.Domain)
@ -496,7 +498,7 @@ func (c Blog) Archive(userIdOrEmail string, cateId string) (re revel.Result) {
// 用户id为空, 转至博客平台 // 用户id为空, 转至博客平台
if userIdOrEmail == "" { if userIdOrEmail == "" {
userIdOrEmail = leanoteUserId userIdOrEmail = configService.GetAdminUsername()
} }
var userInfo info.User var userInfo info.User
if userId != "" { if userId != "" {
@ -594,7 +596,7 @@ func (c Blog) Index(userIdOrEmail string) (re revel.Result) {
// 用户id为空, 转至博客平台 // 用户id为空, 转至博客平台
if userIdOrEmail == "" { if userIdOrEmail == "" {
userIdOrEmail = leanoteUserId userIdOrEmail = configService.GetAdminUsername()
} }
var userInfo info.User var userInfo info.User
if userId != "" { if userId != "" {

View File

@ -316,7 +316,7 @@ func (c File) UploadImage(renderHtml string) revel.Result {
re := c.uploadImage("", ""); re := c.uploadImage("", "");
c.RenderArgs["fileUrlPath"] = siteUrl + re.Id c.RenderArgs["fileUrlPath"] = configService.GetSiteUrl() + re.Id
c.RenderArgs["resultCode"] = re.Code c.RenderArgs["resultCode"] = re.Code
c.RenderArgs["resultMsg"] = re.Msg c.RenderArgs["resultMsg"] = re.Msg
@ -327,4 +327,4 @@ func (c File) UploadImage(renderHtml string) revel.Result {
func (c File) UploadImageJson(from, noteId string) revel.Result { func (c File) UploadImageJson(from, noteId string) revel.Result {
re := c.uploadImage(from, ""); re := c.uploadImage(from, "");
return c.RenderJson(re) return c.RenderJson(re)
} }

View File

@ -53,7 +53,8 @@ func (c Note) Index() revel.Result {
} }
// 当然, 还需要得到第一个notes的content // 当然, 还需要得到第一个notes的content
//... //...
c.RenderArgs["isAdmin"] = leanoteUserId == userInfo.Username Log(configService.GetAdminUsername())
c.RenderArgs["isAdmin"] = configService.GetAdminUsername() == userInfo.Username
c.RenderArgs["userInfo"] = userInfo c.RenderArgs["userInfo"] = userInfo
c.RenderArgs["userInfoJson"] = c.Json(userInfo) c.RenderArgs["userInfoJson"] = c.Json(userInfo)
@ -299,7 +300,7 @@ func (c Note) Html2Image(noteId string) revel.Result {
appKey, _ := revel.Config.String("app.secret") appKey, _ := revel.Config.String("app.secret")
cookieDomain, _ := revel.Config.String("cookie.domain") cookieDomain, _ := revel.Config.String("cookie.domain")
// 生成之 // 生成之
url := siteUrl + "/note/toImage?noteId=" + noteId + "&appKey=" + appKey; url := configService.GetSiteUrl() + "/note/toImage?noteId=" + noteId + "&appKey=" + appKey;
// /Users/life/Documents/bin/phantomjs/bin/phantomjs /Users/life/Desktop/test/b.js // /Users/life/Documents/bin/phantomjs/bin/phantomjs /Users/life/Desktop/test/b.js
binPath := configService.GetGlobalStringConfig("toImageBinPath") binPath := configService.GetGlobalStringConfig("toImageBinPath")
if binPath == "" { if binPath == "" {

View File

@ -3,7 +3,7 @@ package admin
import ( import (
"github.com/revel/revel" "github.com/revel/revel"
// "encoding/json" // "encoding/json"
// . "github.com/leanote/leanote/app/lea" "github.com/leanote/leanote/app/info"
// "io/ioutil" // "io/ioutil"
) )
@ -15,4 +15,10 @@ type AdminUpgrade struct {
func (c AdminUpgrade) UpgradeBlog() revel.Result { func (c AdminUpgrade) UpgradeBlog() revel.Result {
upgradeService.UpgradeBlog() upgradeService.UpgradeBlog()
return nil; return nil;
} }
func (c AdminUpgrade) UpgradeBetaToSelfBlog() revel.Result {
re := info.NewRe()
re.Ok, re.Msg = upgradeService.UpgradeBetaToSelfBlog(c.GetUserId())
return c.RenderJson(re)
}

View File

@ -28,7 +28,6 @@ var configService *service.ConfigService
var emailService *service.EmailService var emailService *service.EmailService
var upgradeService *service.UpgradeService var upgradeService *service.UpgradeService
var adminUsername = "admin"
// 拦截器 // 拦截器
// 不需要拦截的url // 不需要拦截的url
// Index 除了Note之外都不需要 // Index 除了Note之外都不需要
@ -83,7 +82,7 @@ func AuthInterceptor(c *revel.Controller) revel.Result {
// 验证是否已登录 // 验证是否已登录
// 必须是管理员 // 必须是管理员
if username, ok := c.Session["Username"]; ok && username == adminUsername { if username, ok := c.Session["Username"]; ok && username == configService.GetAdminUsername() {
return nil // 已登录 return nil // 已登录
} }
@ -129,4 +128,4 @@ func init() {
revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &AdminEmail{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &AdminEmail{})
revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &AdminUpgrade{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &AdminUpgrade{})
revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &AdminData{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &AdminData{})
} }

View File

@ -20,9 +20,9 @@ var blogService *service.BlogService
var tagService *service.TagService var tagService *service.TagService
var pwdService *service.PwdService var pwdService *service.PwdService
var tokenService *service.TokenService var tokenService *service.TokenService
var suggestionService *service.SuggestionService var suggestionService *service.SuggestionService
var albumService *service.AlbumService var albumService *service.AlbumService
var noteImageService *service.NoteImageService var noteImageService *service.NoteImageService
var fileService *service.FileService var fileService *service.FileService
var attachService *service.AttachService var attachService *service.AttachService
var configService *service.ConfigService var configService *service.ConfigService
@ -32,43 +32,45 @@ var themeService *service.ThemeService
var pageSize = 1000 var pageSize = 1000
var defaultSortField = "UpdatedTime" var defaultSortField = "UpdatedTime"
var leanoteUserId = "admin" // 不能更改
var adminUsername = "admin"
var siteUrl = "http://leanote.com"
// 拦截器 // 拦截器
// 不需要拦截的url // 不需要拦截的url
// Index 除了Note之外都不需要 // Index 除了Note之外都不需要
var commonUrl = map[string]map[string]bool{"Index": map[string]bool{"Index": true, var commonUrl = map[string]map[string]bool{"Index": map[string]bool{"Index": true,
"Login": true, "Login": true,
"DoLogin": true, "DoLogin": true,
"Logout": true, "Logout": true,
"Register": true, "Register": true,
"DoRegister": true, "DoRegister": true,
"FindPasswword": true, "FindPasswword": true,
"DoFindPassword": true, "DoFindPassword": true,
"FindPassword2": true, "FindPassword2": true,
"FindPasswordUpdate": true, "FindPasswordUpdate": true,
"Suggestion": true, "Suggestion": true,
}, },
"Note": map[string]bool{"ToImage": true}, "Note": map[string]bool{"ToImage": true},
"Blog": map[string]bool{"Index": true, "Blog": map[string]bool{"Index": true,
"View": true, "View": true,
"AboutMe": true, "AboutMe": true,
"Cate": true, "Cate": true,
"Search": true, "ListCateLatest": true,
"Search": true,
"GetLikeAndComments": true, "GetLikeAndComments": true,
"IncReadNum": true, "IncReadNum": true,
"ListComments": true, "ListComments": true,
}, "Single": true,
"Archive": true,
"Tags": true,
},
// 用户的激活与修改邮箱都不需要登录, 通过链接地址 // 用户的激活与修改邮箱都不需要登录, 通过链接地址
"User": map[string]bool{"UpdateEmail": true, "User": map[string]bool{"UpdateEmail": true,
"ActiveEmail":true, "ActiveEmail": true,
}, },
"Oauth": map[string]bool{"GithubCallback": true}, "Oauth": map[string]bool{"GithubCallback": true},
"File": map[string]bool{"OutputImage": true, "OutputFile": true}, "File": map[string]bool{"OutputImage": true, "OutputFile": true},
"Attach": map[string]bool{"Download": true, "DownloadAll": true}, "Attach": map[string]bool{"Download": true, "DownloadAll": true},
} }
func needValidate(controller, method string) bool { func needValidate(controller, method string) bool {
// 在里面 // 在里面
if v, ok := commonUrl[controller]; ok { if v, ok := commonUrl[controller]; ok {
@ -79,31 +81,31 @@ func needValidate(controller, method string) bool {
return true return true
} else { } else {
// controller不在这里的, 肯定要验证 // controller不在这里的, 肯定要验证
return true; return true
} }
} }
func AuthInterceptor(c *revel.Controller) revel.Result { func AuthInterceptor(c *revel.Controller) revel.Result {
// 全部变成首字大写 // 全部变成首字大写
var controller = strings.Title(c.Name) var controller = strings.Title(c.Name)
var method = strings.Title(c.MethodName) var method = strings.Title(c.MethodName)
// 是否需要验证? // 是否需要验证?
if !needValidate(controller, method) { if !needValidate(controller, method) {
return nil return nil
} }
// 验证是否已登录 // 验证是否已登录
if userId, ok := c.Session["UserId"]; ok && userId != "" { if userId, ok := c.Session["UserId"]; ok && userId != "" {
return nil // 已登录 return nil // 已登录
} }
// 没有登录, 判断是否是ajax操作 // 没有登录, 判断是否是ajax操作
if c.Request.Header.Get("X-Requested-With") == "XMLHttpRequest" { if c.Request.Header.Get("X-Requested-With") == "XMLHttpRequest" {
re := info.NewRe() re := info.NewRe()
re.Msg = "NOTLOGIN" re.Msg = "NOTLOGIN"
return c.RenderJson(re) return c.RenderJson(re)
} }
return c.Redirect("/login") return c.Redirect("/login")
} }
@ -121,7 +123,7 @@ func InitService() {
tokenService = service.TokenS tokenService = service.TokenS
noteImageService = service.NoteImageS noteImageService = service.NoteImageS
fileService = service.FileS fileService = service.FileS
albumService= service.AlbumS albumService = service.AlbumS
attachService = service.AttachS attachService = service.AttachS
pwdService = service.PwdS pwdService = service.PwdS
suggestionService = service.SuggestionS suggestionService = service.SuggestionS
@ -132,6 +134,11 @@ func InitService() {
themeService = service.ThemeS themeService = service.ThemeS
} }
// 初始化博客模板
// 博客模板不由revel的
func initBlogTemplate() {
}
func init() { func init() {
// interceptor // interceptor
// revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Index{}) // Index.Note自己校验 // revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Index{}) // Index.Note自己校验
@ -141,12 +148,11 @@ func init() {
revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &User{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &User{})
revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &File{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &File{})
revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Attach{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Attach{})
// revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Blog{})
revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &NoteContentHistory{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &NoteContentHistory{})
revel.OnAppStart(func() { revel.OnAppStart(func() {
siteUrl, _ = revel.Config.String("site.url")
// 博客初始化模板 // 博客初始化模板
blog.Init() blog.Init()
}) })
} }

View File

@ -29,7 +29,6 @@ var emailService *service.EmailService
var upgradeService *service.UpgradeService var upgradeService *service.UpgradeService
var themeService *service.ThemeService var themeService *service.ThemeService
var adminUsername = "admin"
// 拦截器 // 拦截器
// 不需要拦截的url // 不需要拦截的url
// Index 除了Note之外都不需要 // Index 除了Note之外都不需要
@ -128,6 +127,5 @@ func init() {
revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &MemberUser{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &MemberUser{})
revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &MemberBlog{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &MemberBlog{})
revel.OnAppStart(func() { revel.OnAppStart(func() {
adminUsername, _ = revel.Config.String("adminUsername")
}) })
} }

View File

@ -429,7 +429,7 @@ func (this *BlogService) fixUserBlog(userBlog *info.UserBlog) {
// Logo路径问题, 有些有http: 有些没有 // Logo路径问题, 有些有http: 有些没有
if userBlog.Logo != "" && !strings.HasPrefix(userBlog.Logo, "http") { if userBlog.Logo != "" && !strings.HasPrefix(userBlog.Logo, "http") {
userBlog.Logo = strings.Trim(userBlog.Logo, "/") userBlog.Logo = strings.Trim(userBlog.Logo, "/")
userBlog.Logo = siteUrl + "/" + userBlog.Logo userBlog.Logo = configService.GetSiteUrl() + "/" + userBlog.Logo
} }
if userBlog.SortField == "" { if userBlog.SortField == "" {
@ -691,7 +691,7 @@ func (this *BlogService) DeleteComment(noteId, commentId, userId string) bool {
return false return false
} }
if userId == adminUserId || note.UserId.Hex() == userId || comment.UserId.Hex() == userId { if userId == configService.GetAdminUserId() || note.UserId.Hex() == userId || comment.UserId.Hex() == userId {
if db.Delete(db.BlogComments, bson.M{"_id": bson.ObjectIdHex(commentId)}) { if db.Delete(db.BlogComments, bson.M{"_id": bson.ObjectIdHex(commentId)}) {
// 评论-1 // 评论-1
db.Update(db.Notes, bson.M{"_id": bson.ObjectIdHex(noteId)}, bson.M{"$inc": bson.M{"CommentNum": -1}}) db.Update(db.Notes, bson.M{"_id": bson.ObjectIdHex(noteId)}, bson.M{"$inc": bson.M{"CommentNum": -1}})

View File

@ -17,6 +17,9 @@ import (
// 配置服务 // 配置服务
// 只是全局的, 用户的配置没有 // 只是全局的, 用户的配置没有
type ConfigService struct { type ConfigService struct {
adminUserId string
siteUrl string
adminUsername string
// 全局的 // 全局的
GlobalAllConfigs map[string]interface{} GlobalAllConfigs map[string]interface{}
GlobalStringConfigs map[string]string GlobalStringConfigs map[string]string
@ -24,9 +27,6 @@ type ConfigService struct {
GlobalMapConfigs map[string]map[string]string GlobalMapConfigs map[string]map[string]string
GlobalArrMapConfigs map[string][]map[string]string GlobalArrMapConfigs map[string][]map[string]string
} }
var adminUserId = ""
// appStart时 将全局的配置从数据库中得到作为全局 // appStart时 将全局的配置从数据库中得到作为全局
func (this *ConfigService) InitGlobalConfigs() bool { func (this *ConfigService) InitGlobalConfigs() bool {
this.GlobalAllConfigs = map[string]interface{}{} this.GlobalAllConfigs = map[string]interface{}{}
@ -35,16 +35,17 @@ func (this *ConfigService) InitGlobalConfigs() bool {
this.GlobalMapConfigs = map[string]map[string]string{} this.GlobalMapConfigs = map[string]map[string]string{}
this.GlobalArrMapConfigs = map[string][]map[string]string{} this.GlobalArrMapConfigs = map[string][]map[string]string{}
adminUsername, _ := revel.Config.String("adminUsername") this.adminUsername, _ = revel.Config.String("adminUsername")
if adminUsername == "" { if this.adminUsername == "" {
adminUsername = "admin" this.adminUsername = "admin"
} }
this.siteUrl, _ = revel.Config.String("site.url")
userInfo := userService.GetUserInfoByAny(adminUsername) userInfo := userService.GetUserInfoByAny(this.adminUsername)
if userInfo.UserId == "" { if userInfo.UserId == "" {
return false return false
} }
adminUserId = userInfo.UserId.Hex() this.adminUserId = userInfo.UserId.Hex()
configs := []info.Config{} configs := []info.Config{}
db.ListByQ(db.Configs, bson.M{"UserId": userInfo.UserId}, &configs) db.ListByQ(db.Configs, bson.M{"UserId": userInfo.UserId}, &configs)
@ -68,6 +69,16 @@ func (this *ConfigService) InitGlobalConfigs() bool {
return true return true
} }
func (this *ConfigService) GetSiteUrl() string {
return this.siteUrl;
}
func (this *ConfigService) GetAdminUsername() string {
return this.adminUsername
}
func (this *ConfigService) GetAdminUserId() string {
return this.adminUserId
}
// 通用方法 // 通用方法
func (this *ConfigService) updateGlobalConfig(userId, key string, value interface{}, isArr, isMap, isArrMap bool) bool { func (this *ConfigService) updateGlobalConfig(userId, key string, value interface{}, isArr, isMap, isArrMap bool) bool {
// 判断是否存在 // 判断是否存在
@ -183,7 +194,7 @@ func (this *ConfigService) UpdateShareNoteConfig(registerSharedUserId string,
if registerSharedUserId == "" { if registerSharedUserId == "" {
ok = true ok = true
msg = "share userId is blank, So it share nothing to register" msg = "share userId is blank, So it share nothing to register"
this.UpdateGlobalStringConfig(adminUserId, "registerSharedUserId", "") this.UpdateGlobalStringConfig(this.adminUserId, "registerSharedUserId", "")
return return
} else { } else {
user := userService.GetUserInfo(registerSharedUserId) user := userService.GetUserInfo(registerSharedUserId)
@ -192,7 +203,7 @@ func (this *ConfigService) UpdateShareNoteConfig(registerSharedUserId string,
msg = "no such user: " + registerSharedUserId msg = "no such user: " + registerSharedUserId
return return
} else { } else {
this.UpdateGlobalStringConfig(adminUserId, "registerSharedUserId", registerSharedUserId) this.UpdateGlobalStringConfig(this.adminUserId, "registerSharedUserId", registerSharedUserId)
} }
} }
@ -219,7 +230,7 @@ func (this *ConfigService) UpdateShareNoteConfig(registerSharedUserId string,
} }
} }
} }
this.UpdateGlobalArrMapConfig(adminUserId, "registerSharedNotebooks", notebooks) this.UpdateGlobalArrMapConfig(this.adminUserId, "registerSharedNotebooks", notebooks)
notes := []map[string]string{} notes := []map[string]string{}
// 共享笔记 // 共享笔记
@ -244,7 +255,7 @@ func (this *ConfigService) UpdateShareNoteConfig(registerSharedUserId string,
} }
} }
} }
this.UpdateGlobalArrMapConfig(adminUserId, "registerSharedNotes", notes) this.UpdateGlobalArrMapConfig(this.adminUserId, "registerSharedNotes", notes)
// 复制 // 复制
noteIds := []string{} noteIds := []string{}
@ -265,7 +276,7 @@ func (this *ConfigService) UpdateShareNoteConfig(registerSharedUserId string,
} }
} }
} }
this.UpdateGlobalArrayConfig(adminUserId, "registerCopyNoteIds", noteIds) this.UpdateGlobalArrayConfig(this.adminUserId, "registerCopyNoteIds", noteIds)
ok = true ok = true
return return
@ -277,7 +288,7 @@ func (this *ConfigService) AddBackup(path, remark string) bool {
n := time.Now().Unix() n := time.Now().Unix()
nstr := fmt.Sprintf("%v", n) nstr := fmt.Sprintf("%v", n)
backups = append(backups, map[string]string{"createdTime": nstr, "path": path, "remark": remark}) backups = append(backups, map[string]string{"createdTime": nstr, "path": path, "remark": remark})
return this.UpdateGlobalArrMapConfig(adminUserId, "backups", backups) return this.UpdateGlobalArrMapConfig(this.adminUserId, "backups", backups)
} }
func (this *ConfigService) getBackupDirname() string { func (this *ConfigService) getBackupDirname() string {
@ -349,7 +360,7 @@ func (this *ConfigService) Restore(createdTime string) (ok bool, msg string) {
port, _ := revel.Config.String("db.port") port, _ := revel.Config.String("db.port")
username, _ := revel.Config.String("db.username") username, _ := revel.Config.String("db.username")
password, _ := revel.Config.String("db.password") password, _ := revel.Config.String("db.password")
// mongorestore -h localhost -d leanote -o /root/mongodb_backup/leanote-9-22/ -u leanote -p kk // mongorestore -h localhost -d leanote -o /root/mongodb_backup/leanote-9-22/ -u leanote -p nKFAkxKnWkEQy8Vv2LlM
binPath = binPath + " --drop -h " + host + " -d " + dbname + " -port " + port binPath = binPath + " --drop -h " + host + " -d " + dbname + " -port " + port
if username != "" { if username != "" {
binPath += " -u " + username + " -p " + password binPath += " -u " + username + " -p " + password
@ -398,7 +409,7 @@ func (this *ConfigService) DeleteBackup(createdTime string) (bool, string) {
// 删除之 // 删除之
backups = append(backups[0:i], backups[i+1:]...) backups = append(backups[0:i], backups[i+1:]...)
ok := this.UpdateGlobalArrMapConfig(adminUserId, "backups", backups) ok := this.UpdateGlobalArrMapConfig(this.adminUserId, "backups", backups)
return ok, "" return ok, ""
} }
@ -416,7 +427,7 @@ func (this *ConfigService) UpdateBackupRemark(createdTime, remark string) (bool,
} }
backup["remark"] = remark; backup["remark"] = remark;
ok := this.UpdateGlobalArrMapConfig(adminUserId, "backups", backups) ok := this.UpdateGlobalArrMapConfig(this.adminUserId, "backups", backups)
return ok, "" return ok, ""
} }
@ -451,7 +462,7 @@ func init() {
port = ""; port = "";
} }
siteUrl, _ = revel.Config.String("site.url") // 已包含:9000, http, 去掉成 leanote.com siteUrl, _ := revel.Config.String("site.url") // 已包含:9000, http, 去掉成 leanote.com
if strings.HasPrefix(siteUrl, "http://") { if strings.HasPrefix(siteUrl, "http://") {
defaultDomain = siteUrl[len("http://"):] defaultDomain = siteUrl[len("http://"):]
} else if strings.HasPrefix(siteUrl, "https://") { } else if strings.HasPrefix(siteUrl, "https://") {

View File

@ -82,9 +82,9 @@ func (this *EmailService) RegisterSendActiveEmail(userInfo info.User, email stri
return false return false
} }
tokenUrl := siteUrl + "/user/activeEmail?token=" + token tokenUrl := configService.GetSiteUrl() + "/user/activeEmail?token=" + token
// {siteUrl} {tokenUrl} {token} {tokenTimeout} {user.id} {user.email} {user.username} // {siteUrl} {tokenUrl} {token} {tokenTimeout} {user.id} {user.email} {user.username}
token2Value := map[string]interface{}{"siteUrl": siteUrl, "tokenUrl": tokenUrl, "token": token, "tokenTimeout": strconv.Itoa(int(tokenService.GetOverHours(info.TokenActiveEmail))), token2Value := map[string]interface{}{"siteUrl": configService.GetSiteUrl(), "tokenUrl": tokenUrl, "token": token, "tokenTimeout": strconv.Itoa(int(tokenService.GetOverHours(info.TokenActiveEmail))),
"user": map[string]interface{}{ "user": map[string]interface{}{
"userId": userInfo.UserId.Hex(), "userId": userInfo.UserId.Hex(),
"email": userInfo.Email, "email": userInfo.Email,
@ -122,9 +122,9 @@ func (this *EmailService) UpdateEmailSendActiveEmail(userInfo info.User, email s
tpl := configService.GetGlobalStringConfig("emailTemplateUpdateEmail"); tpl := configService.GetGlobalStringConfig("emailTemplateUpdateEmail");
// 发送邮件 // 发送邮件
tokenUrl := siteUrl + "/user/updateEmail?token=" + token tokenUrl := configService.GetSiteUrl() + "/user/updateEmail?token=" + token
// {siteUrl} {tokenUrl} {token} {tokenTimeout} {user.userId} {user.email} {user.username} // {siteUrl} {tokenUrl} {token} {tokenTimeout} {user.userId} {user.email} {user.username}
token2Value := map[string]interface{}{"siteUrl": siteUrl, "tokenUrl": tokenUrl, "token": token, "tokenTimeout": strconv.Itoa(int(tokenService.GetOverHours(info.TokenActiveEmail))), token2Value := map[string]interface{}{"siteUrl": configService.GetSiteUrl(), "tokenUrl": tokenUrl, "token": token, "tokenTimeout": strconv.Itoa(int(tokenService.GetOverHours(info.TokenActiveEmail))),
"newEmail": email, "newEmail": email,
"user": map[string]interface{}{ "user": map[string]interface{}{
"userId": userInfo.UserId.Hex(), "userId": userInfo.UserId.Hex(),
@ -148,9 +148,9 @@ func (this *EmailService) FindPwdSendEmail(token, email string) (ok bool, msg st
tpl := configService.GetGlobalStringConfig("emailTemplateFindPassword"); tpl := configService.GetGlobalStringConfig("emailTemplateFindPassword");
// 发送邮件 // 发送邮件
tokenUrl := siteUrl + "/findPassword/" + token tokenUrl := configService.GetSiteUrl() + "/findPassword/" + token
// {siteUrl} {tokenUrl} {token} {tokenTimeout} {user.id} {user.email} {user.username} // {siteUrl} {tokenUrl} {token} {tokenTimeout} {user.id} {user.email} {user.username}
token2Value := map[string]interface{}{"siteUrl": siteUrl, "tokenUrl": tokenUrl, token2Value := map[string]interface{}{"siteUrl": configService.GetSiteUrl(), "tokenUrl": tokenUrl,
"token": token, "tokenTimeout": strconv.Itoa(int(tokenService.GetOverHours(info.TokenActiveEmail)))} "token": token, "tokenTimeout": strconv.Itoa(int(tokenService.GetOverHours(info.TokenActiveEmail)))}
ok, msg, subject, tpl = this.renderEmail(subject, tpl, token2Value) ok, msg, subject, tpl = this.renderEmail(subject, tpl, token2Value)
@ -167,8 +167,8 @@ func (this *EmailService) SendInviteEmail(userInfo info.User, email, content str
subject := configService.GetGlobalStringConfig("emailTemplateInviteSubject"); subject := configService.GetGlobalStringConfig("emailTemplateInviteSubject");
tpl := configService.GetGlobalStringConfig("emailTemplateInvite"); tpl := configService.GetGlobalStringConfig("emailTemplateInvite");
token2Value := map[string]interface{}{"siteUrl": siteUrl, token2Value := map[string]interface{}{"siteUrl": configService.GetSiteUrl(),
"registerUrl": siteUrl + "/register?from=" + userInfo.Username, "registerUrl": configService.GetSiteUrl() + "/register?from=" + userInfo.Username,
"content": content, "content": content,
"user": map[string]interface{}{ "user": map[string]interface{}{
"username": userInfo.Username, "username": userInfo.Username,
@ -225,7 +225,7 @@ func (this *EmailService) SendCommentEmail(note info.Note, comment info.BlogComm
// {blog.id} {blog.title} {blog.url} // {blog.id} {blog.title} {blog.url}
// {commentUser.userId} {commentUser.username} {commentUser.email} // {commentUser.userId} {commentUser.username} {commentUser.email}
// {commentedUser.userId} {commentedUser.username} {commentedUser.email} // {commentedUser.userId} {commentedUser.username} {commentedUser.email}
token2Value := map[string]interface{}{"siteUrl": siteUrl, "blogUrl": configService.GetBlogUrl(), token2Value := map[string]interface{}{"siteUrl": configService.GetSiteUrl(), "blogUrl": configService.GetBlogUrl(),
"blog": map[string]string{ "blog": map[string]string{
"id": note.NoteId.Hex(), "id": note.NoteId.Hex(),
"title": note.Title, "title": note.Title,
@ -316,7 +316,7 @@ func (this *EmailService) renderEmail(subject, body string, values map[string]in
var tpl *template.Template var tpl *template.Template
values["siteUrl"] = siteUrl; values["siteUrl"] = configService.GetSiteUrl();
// subject // subject
if subject != "" { if subject != "" {

View File

@ -362,7 +362,7 @@ func (this *ThemeService) DeleteTheme(userId, themeId string) (ok bool) {
func (this *ThemeService) PublicTheme(userId, themeId string) (ok bool) { func (this *ThemeService) PublicTheme(userId, themeId string) (ok bool) {
// 是否是管理员? // 是否是管理员?
userInfo := userService.GetUserInfo(userId) userInfo := userService.GetUserInfo(userId)
if userInfo.Username == adminUsername { if userInfo.Username == configService.GetAdminUsername() {
theme := this.GetThemeById(themeId) theme := this.GetThemeById(themeId)
return db.UpdateByQField(db.Themes, bson.M{"UserId": bson.ObjectIdHex(userId), "_id": bson.ObjectIdHex(themeId)}, "IsDefault", !theme.IsDefault) return db.UpdateByQField(db.Themes, bson.M{"UserId": bson.ObjectIdHex(userId), "_id": bson.ObjectIdHex(themeId)}, "IsDefault", !theme.IsDefault)
} }

View File

@ -75,7 +75,7 @@ func (this *UserService) setUserLogo(user *info.User) {
} }
if user.Logo != "" && !strings.HasPrefix(user.Logo, "http") { if user.Logo != "" && !strings.HasPrefix(user.Logo, "http") {
user.Logo = strings.Trim(user.Logo, "/") user.Logo = strings.Trim(user.Logo, "/")
user.Logo = siteUrl + "/" + user.Logo user.Logo = configService.GetSiteUrl() + "/" + user.Logo
} }
} }
@ -256,8 +256,7 @@ func (this *UserService) UpdatePwd(userId, oldPwd, pwd string) (bool, string) {
// 管理员重置密码 // 管理员重置密码
func (this *UserService) ResetPwd(adminUserId, userId, pwd string) (ok bool, msg string) { func (this *UserService) ResetPwd(adminUserId, userId, pwd string) (ok bool, msg string) {
adminInfo := this.GetUserInfoByAny(adminUsername) if configService.GetAdminUserId() != adminUserId {
if adminInfo.UserId.Hex() != adminUserId {
return return
} }
ok = db.UpdateByQField(db.Users, bson.M{"_id": bson.ObjectIdHex(userId)}, "Pwd", Md5(pwd)) ok = db.UpdateByQField(db.Users, bson.M{"_id": bson.ObjectIdHex(userId)}, "Pwd", Md5(pwd))

View File

@ -1,7 +1,6 @@
package service package service
import ( import (
"github.com/revel/revel"
) )
// init service, for share service bettween services // init service, for share service bettween services
@ -30,9 +29,6 @@ var UpgradeS *UpgradeService
var SessionS, sessionService *SessionService var SessionS, sessionService *SessionService
var ThemeS, themeService *ThemeService var ThemeS, themeService *ThemeService
var siteUrl string
var adminUsername = "admin"
// onAppStart调用 // onAppStart调用
func InitService() { func InitService() {
NotebookS = &NotebookService{} NotebookS = &NotebookService{}
@ -74,6 +70,4 @@ func InitService() {
emailService = EmailS emailService = EmailS
sessionService = SessionS sessionService = SessionS
themeService = ThemeS themeService = ThemeS
}
siteUrl, _ = revel.Config.String("site.url")
}

View File

@ -242,6 +242,8 @@ latest=Latest
# 用户中心 # 用户中心
memberCenter=Member Center memberCenter=Member Center
userNotExists=该成员沿未注册
hasUsers=已存在该成员
# error # error
notFound=This page cann't found. notFound=This page cann't found.

View File

@ -268,6 +268,8 @@ latest=最新
# 用户中心 # 用户中心
memberCenter=用户中心 memberCenter=用户中心
userNotExists=该成员沿未注册
hasUsers=已存在该成员
# 必须要加这个, 奇怪 # 必须要加这个, 奇怪
[CN] [CN]