From 6555384e5ca5d18cfa0fa1b25c9a94aa20c97aa3 Mon Sep 17 00:00:00 2001 From: life Date: Mon, 10 Nov 2014 16:26:04 +0800 Subject: [PATCH] siteurl, adminUsername config in configService --- app/controllers/BaseController.go | 6 +- app/controllers/BlogController.go | 6 +- app/controllers/FileController.go | 4 +- app/controllers/NoteController.go | 5 +- .../admin/AdminUpgradeController.go | 10 ++- app/controllers/admin/init.go | 5 +- app/controllers/init.go | 84 ++++++++++--------- app/controllers/member/init.go | 4 +- app/service/BlogService.go | 4 +- app/service/ConfigService.go | 47 +++++++---- app/service/EmailService.go | 20 ++--- app/service/ThemeService.go | 2 +- app/service/UserService.go | 5 +- app/service/init.go | 8 +- messages/msg.en | 2 + messages/msg.zh | 4 +- 16 files changed, 118 insertions(+), 98 deletions(-) diff --git a/app/controllers/BaseController.go b/app/controllers/BaseController.go index 8ed0de9..fcef661 100644 --- a/app/controllers/BaseController.go +++ b/app/controllers/BaseController.go @@ -183,7 +183,7 @@ func (c BaseController) SetLocale() string { lang = "en"; } c.RenderArgs["locale"] = lang; - c.RenderArgs["siteUrl"] = siteUrl; + c.RenderArgs["siteUrl"] = configService.GetSiteUrl(); c.RenderArgs["blogUrl"] = configService.GetBlogUrl() c.RenderArgs["leaUrl"] = configService.GetLeaUrl() @@ -196,7 +196,7 @@ func (c BaseController) SetLocale() string { func (c BaseController) SetUserInfo() { userInfo := c.GetUserInfo() c.RenderArgs["userInfo"] = userInfo - if(userInfo.Username == adminUsername) { + if(userInfo.Username == configService.GetAdminUsername()) { c.RenderArgs["isAdmin"] = true } } @@ -242,4 +242,4 @@ func (c BaseController) RenderRe(re info.Re) revel.Result { } } return c.RenderJson(re) -} \ No newline at end of file +} diff --git a/app/controllers/BlogController.go b/app/controllers/BlogController.go index c1cf46c..d01d043 100644 --- a/app/controllers/BlogController.go +++ b/app/controllers/BlogController.go @@ -104,6 +104,7 @@ func (c Blog) setPreviewUrl() { themeId := c.Session["themeId"] theme := themeService.GetTheme(userId, themeId) + siteUrl := configService.GetSiteUrl() blogUrl := siteUrl + "/preview" // blog.leanote.com userIdOrEmail := userId @@ -137,6 +138,7 @@ func (c Blog) setUrl(userBlog info.UserBlog, userInfo info.User) { staticUrl = configService.GetUserUrl(strings.Split(host, ":")[0]) // staticUrl == host, 为保证同源!!! 只有host, http://leanote.com, http://blog/leanote.com // life.leanote.com, lealife.com + siteUrl := configService.GetSiteUrl() if userBlog.Domain != "" && configService.AllowCustomDomain() { // ok indexUrl = configService.GetUserUrl(userBlog.Domain) @@ -496,7 +498,7 @@ func (c Blog) Archive(userIdOrEmail string, cateId string) (re revel.Result) { // 用户id为空, 转至博客平台 if userIdOrEmail == "" { - userIdOrEmail = leanoteUserId + userIdOrEmail = configService.GetAdminUsername() } var userInfo info.User if userId != "" { @@ -594,7 +596,7 @@ func (c Blog) Index(userIdOrEmail string) (re revel.Result) { // 用户id为空, 转至博客平台 if userIdOrEmail == "" { - userIdOrEmail = leanoteUserId + userIdOrEmail = configService.GetAdminUsername() } var userInfo info.User if userId != "" { diff --git a/app/controllers/FileController.go b/app/controllers/FileController.go index b95e0d3..7e4a4b7 100644 --- a/app/controllers/FileController.go +++ b/app/controllers/FileController.go @@ -316,7 +316,7 @@ func (c File) UploadImage(renderHtml string) revel.Result { re := c.uploadImage("", ""); - c.RenderArgs["fileUrlPath"] = siteUrl + re.Id + c.RenderArgs["fileUrlPath"] = configService.GetSiteUrl() + re.Id c.RenderArgs["resultCode"] = re.Code 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 { re := c.uploadImage(from, ""); return c.RenderJson(re) -} \ No newline at end of file +} diff --git a/app/controllers/NoteController.go b/app/controllers/NoteController.go index df21997..80e8b17 100644 --- a/app/controllers/NoteController.go +++ b/app/controllers/NoteController.go @@ -53,7 +53,8 @@ func (c Note) Index() revel.Result { } // 当然, 还需要得到第一个notes的content //... - c.RenderArgs["isAdmin"] = leanoteUserId == userInfo.Username + Log(configService.GetAdminUsername()) + c.RenderArgs["isAdmin"] = configService.GetAdminUsername() == userInfo.Username c.RenderArgs["userInfo"] = 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") 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 binPath := configService.GetGlobalStringConfig("toImageBinPath") if binPath == "" { diff --git a/app/controllers/admin/AdminUpgradeController.go b/app/controllers/admin/AdminUpgradeController.go index c8dc206..8580acf 100644 --- a/app/controllers/admin/AdminUpgradeController.go +++ b/app/controllers/admin/AdminUpgradeController.go @@ -3,7 +3,7 @@ package admin import ( "github.com/revel/revel" // "encoding/json" -// . "github.com/leanote/leanote/app/lea" + "github.com/leanote/leanote/app/info" // "io/ioutil" ) @@ -15,4 +15,10 @@ type AdminUpgrade struct { func (c AdminUpgrade) UpgradeBlog() revel.Result { upgradeService.UpgradeBlog() return nil; -} \ No newline at end of file +} + +func (c AdminUpgrade) UpgradeBetaToSelfBlog() revel.Result { + re := info.NewRe() + re.Ok, re.Msg = upgradeService.UpgradeBetaToSelfBlog(c.GetUserId()) + return c.RenderJson(re) +} diff --git a/app/controllers/admin/init.go b/app/controllers/admin/init.go index c151864..bcd964c 100644 --- a/app/controllers/admin/init.go +++ b/app/controllers/admin/init.go @@ -28,7 +28,6 @@ var configService *service.ConfigService var emailService *service.EmailService var upgradeService *service.UpgradeService -var adminUsername = "admin" // 拦截器 // 不需要拦截的url // 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 // 已登录 } @@ -129,4 +128,4 @@ func init() { revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &AdminEmail{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &AdminUpgrade{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &AdminData{}) -} \ No newline at end of file +} diff --git a/app/controllers/init.go b/app/controllers/init.go index 2af847f..11c1761 100644 --- a/app/controllers/init.go +++ b/app/controllers/init.go @@ -20,9 +20,9 @@ var blogService *service.BlogService var tagService *service.TagService var pwdService *service.PwdService var tokenService *service.TokenService -var suggestionService *service.SuggestionService -var albumService *service.AlbumService -var noteImageService *service.NoteImageService +var suggestionService *service.SuggestionService +var albumService *service.AlbumService +var noteImageService *service.NoteImageService var fileService *service.FileService var attachService *service.AttachService var configService *service.ConfigService @@ -32,43 +32,45 @@ var themeService *service.ThemeService var pageSize = 1000 var defaultSortField = "UpdatedTime" -var leanoteUserId = "admin" // 不能更改 -var adminUsername = "admin" -var siteUrl = "http://leanote.com" // 拦截器 // 不需要拦截的url // Index 除了Note之外都不需要 -var commonUrl = map[string]map[string]bool{"Index": map[string]bool{"Index": true, - "Login": true, - "DoLogin": true, - "Logout": true, - "Register": true, - "DoRegister": true, - "FindPasswword": true, - "DoFindPassword": true, - "FindPassword2": true, - "FindPasswordUpdate": true, - "Suggestion": true, - }, +var commonUrl = map[string]map[string]bool{"Index": map[string]bool{"Index": true, + "Login": true, + "DoLogin": true, + "Logout": true, + "Register": true, + "DoRegister": true, + "FindPasswword": true, + "DoFindPassword": true, + "FindPassword2": true, + "FindPasswordUpdate": true, + "Suggestion": true, +}, "Note": map[string]bool{"ToImage": true}, "Blog": map[string]bool{"Index": true, - "View": true, - "AboutMe": true, - "Cate": true, - "Search": true, + "View": true, + "AboutMe": true, + "Cate": true, + "ListCateLatest": true, + "Search": true, "GetLikeAndComments": true, - "IncReadNum": true, - "ListComments": true, - }, + "IncReadNum": true, + "ListComments": true, + "Single": true, + "Archive": true, + "Tags": true, + }, // 用户的激活与修改邮箱都不需要登录, 通过链接地址 "User": map[string]bool{"UpdateEmail": true, - "ActiveEmail":true, - }, - "Oauth": map[string]bool{"GithubCallback": true}, - "File": map[string]bool{"OutputImage": true, "OutputFile": true}, + "ActiveEmail": true, + }, + "Oauth": map[string]bool{"GithubCallback": true}, + "File": map[string]bool{"OutputImage": true, "OutputFile": true}, "Attach": map[string]bool{"Download": true, "DownloadAll": true}, } + func needValidate(controller, method string) bool { // 在里面 if v, ok := commonUrl[controller]; ok { @@ -79,31 +81,31 @@ func needValidate(controller, method string) bool { return true } else { // controller不在这里的, 肯定要验证 - return true; + return true } } 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 userId, ok := c.Session["UserId"]; ok && userId != "" { 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") } @@ -121,7 +123,7 @@ func InitService() { tokenService = service.TokenS noteImageService = service.NoteImageS fileService = service.FileS - albumService= service.AlbumS + albumService = service.AlbumS attachService = service.AttachS pwdService = service.PwdS suggestionService = service.SuggestionS @@ -132,6 +134,11 @@ func InitService() { themeService = service.ThemeS } +// 初始化博客模板 +// 博客模板不由revel的 +func initBlogTemplate() { +} + func init() { // interceptor // 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, &File{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Attach{}) +// revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Blog{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &NoteContentHistory{}) - + revel.OnAppStart(func() { - siteUrl, _ = revel.Config.String("site.url") - // 博客初始化模板 blog.Init() }) -} \ No newline at end of file +} diff --git a/app/controllers/member/init.go b/app/controllers/member/init.go index a86b6f1..2737265 100644 --- a/app/controllers/member/init.go +++ b/app/controllers/member/init.go @@ -29,7 +29,6 @@ var emailService *service.EmailService var upgradeService *service.UpgradeService var themeService *service.ThemeService -var adminUsername = "admin" // 拦截器 // 不需要拦截的url // Index 除了Note之外都不需要 @@ -128,6 +127,5 @@ func init() { revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &MemberUser{}) revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &MemberBlog{}) revel.OnAppStart(func() { - adminUsername, _ = revel.Config.String("adminUsername") }) -} \ No newline at end of file +} diff --git a/app/service/BlogService.go b/app/service/BlogService.go index a396d0b..4d8677c 100644 --- a/app/service/BlogService.go +++ b/app/service/BlogService.go @@ -429,7 +429,7 @@ func (this *BlogService) fixUserBlog(userBlog *info.UserBlog) { // Logo路径问题, 有些有http: 有些没有 if userBlog.Logo != "" && !strings.HasPrefix(userBlog.Logo, "http") { userBlog.Logo = strings.Trim(userBlog.Logo, "/") - userBlog.Logo = siteUrl + "/" + userBlog.Logo + userBlog.Logo = configService.GetSiteUrl() + "/" + userBlog.Logo } if userBlog.SortField == "" { @@ -691,7 +691,7 @@ func (this *BlogService) DeleteComment(noteId, commentId, userId string) bool { 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)}) { // 评论-1 db.Update(db.Notes, bson.M{"_id": bson.ObjectIdHex(noteId)}, bson.M{"$inc": bson.M{"CommentNum": -1}}) diff --git a/app/service/ConfigService.go b/app/service/ConfigService.go index fd79093..a24cc7e 100644 --- a/app/service/ConfigService.go +++ b/app/service/ConfigService.go @@ -17,6 +17,9 @@ import ( // 配置服务 // 只是全局的, 用户的配置没有 type ConfigService struct { + adminUserId string + siteUrl string + adminUsername string // 全局的 GlobalAllConfigs map[string]interface{} GlobalStringConfigs map[string]string @@ -24,9 +27,6 @@ type ConfigService struct { GlobalMapConfigs map[string]map[string]string GlobalArrMapConfigs map[string][]map[string]string } - -var adminUserId = "" - // appStart时 将全局的配置从数据库中得到作为全局 func (this *ConfigService) InitGlobalConfigs() bool { this.GlobalAllConfigs = map[string]interface{}{} @@ -35,16 +35,17 @@ func (this *ConfigService) InitGlobalConfigs() bool { this.GlobalMapConfigs = map[string]map[string]string{} this.GlobalArrMapConfigs = map[string][]map[string]string{} - adminUsername, _ := revel.Config.String("adminUsername") - if adminUsername == "" { - adminUsername = "admin" + this.adminUsername, _ = revel.Config.String("adminUsername") + if this.adminUsername == "" { + this.adminUsername = "admin" } + this.siteUrl, _ = revel.Config.String("site.url") - userInfo := userService.GetUserInfoByAny(adminUsername) + userInfo := userService.GetUserInfoByAny(this.adminUsername) if userInfo.UserId == "" { return false } - adminUserId = userInfo.UserId.Hex() + this.adminUserId = userInfo.UserId.Hex() configs := []info.Config{} db.ListByQ(db.Configs, bson.M{"UserId": userInfo.UserId}, &configs) @@ -68,6 +69,16 @@ func (this *ConfigService) InitGlobalConfigs() bool { 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 { // 判断是否存在 @@ -183,7 +194,7 @@ func (this *ConfigService) UpdateShareNoteConfig(registerSharedUserId string, if registerSharedUserId == "" { ok = true msg = "share userId is blank, So it share nothing to register" - this.UpdateGlobalStringConfig(adminUserId, "registerSharedUserId", "") + this.UpdateGlobalStringConfig(this.adminUserId, "registerSharedUserId", "") return } else { user := userService.GetUserInfo(registerSharedUserId) @@ -192,7 +203,7 @@ func (this *ConfigService) UpdateShareNoteConfig(registerSharedUserId string, msg = "no such user: " + registerSharedUserId return } 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{} // 共享笔记 @@ -244,7 +255,7 @@ func (this *ConfigService) UpdateShareNoteConfig(registerSharedUserId string, } } } - this.UpdateGlobalArrMapConfig(adminUserId, "registerSharedNotes", notes) + this.UpdateGlobalArrMapConfig(this.adminUserId, "registerSharedNotes", notes) // 复制 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 return @@ -277,7 +288,7 @@ func (this *ConfigService) AddBackup(path, remark string) bool { n := time.Now().Unix() nstr := fmt.Sprintf("%v", n) 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 { @@ -349,7 +360,7 @@ func (this *ConfigService) Restore(createdTime string) (ok bool, msg string) { port, _ := revel.Config.String("db.port") username, _ := revel.Config.String("db.username") 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 if username != "" { 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:]...) - ok := this.UpdateGlobalArrMapConfig(adminUserId, "backups", backups) + ok := this.UpdateGlobalArrMapConfig(this.adminUserId, "backups", backups) return ok, "" } @@ -416,7 +427,7 @@ func (this *ConfigService) UpdateBackupRemark(createdTime, remark string) (bool, } backup["remark"] = remark; - ok := this.UpdateGlobalArrMapConfig(adminUserId, "backups", backups) + ok := this.UpdateGlobalArrMapConfig(this.adminUserId, "backups", backups) return ok, "" } @@ -451,7 +462,7 @@ func init() { 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://") { defaultDomain = siteUrl[len("http://"):] } else if strings.HasPrefix(siteUrl, "https://") { diff --git a/app/service/EmailService.go b/app/service/EmailService.go index 09c7045..ad71306 100644 --- a/app/service/EmailService.go +++ b/app/service/EmailService.go @@ -82,9 +82,9 @@ func (this *EmailService) RegisterSendActiveEmail(userInfo info.User, email stri 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} - 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{}{ "userId": userInfo.UserId.Hex(), "email": userInfo.Email, @@ -122,9 +122,9 @@ func (this *EmailService) UpdateEmailSendActiveEmail(userInfo info.User, email s 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} - 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, "user": map[string]interface{}{ "userId": userInfo.UserId.Hex(), @@ -148,9 +148,9 @@ func (this *EmailService) FindPwdSendEmail(token, email string) (ok bool, msg st tpl := configService.GetGlobalStringConfig("emailTemplateFindPassword"); // 发送邮件 - tokenUrl := siteUrl + "/findPassword/" + token + tokenUrl := configService.GetSiteUrl() + "/findPassword/" + token // {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)))} 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"); tpl := configService.GetGlobalStringConfig("emailTemplateInvite"); - token2Value := map[string]interface{}{"siteUrl": siteUrl, - "registerUrl": siteUrl + "/register?from=" + userInfo.Username, + token2Value := map[string]interface{}{"siteUrl": configService.GetSiteUrl(), + "registerUrl": configService.GetSiteUrl() + "/register?from=" + userInfo.Username, "content": content, "user": map[string]interface{}{ "username": userInfo.Username, @@ -225,7 +225,7 @@ func (this *EmailService) SendCommentEmail(note info.Note, comment info.BlogComm // {blog.id} {blog.title} {blog.url} // {commentUser.userId} {commentUser.username} {commentUser.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{ "id": note.NoteId.Hex(), "title": note.Title, @@ -316,7 +316,7 @@ func (this *EmailService) renderEmail(subject, body string, values map[string]in var tpl *template.Template - values["siteUrl"] = siteUrl; + values["siteUrl"] = configService.GetSiteUrl(); // subject if subject != "" { diff --git a/app/service/ThemeService.go b/app/service/ThemeService.go index 1f717e9..e5b18fb 100644 --- a/app/service/ThemeService.go +++ b/app/service/ThemeService.go @@ -362,7 +362,7 @@ func (this *ThemeService) DeleteTheme(userId, themeId string) (ok bool) { func (this *ThemeService) PublicTheme(userId, themeId string) (ok bool) { // 是否是管理员? userInfo := userService.GetUserInfo(userId) - if userInfo.Username == adminUsername { + if userInfo.Username == configService.GetAdminUsername() { theme := this.GetThemeById(themeId) return db.UpdateByQField(db.Themes, bson.M{"UserId": bson.ObjectIdHex(userId), "_id": bson.ObjectIdHex(themeId)}, "IsDefault", !theme.IsDefault) } diff --git a/app/service/UserService.go b/app/service/UserService.go index 8b0ac4d..5a3461c 100644 --- a/app/service/UserService.go +++ b/app/service/UserService.go @@ -75,7 +75,7 @@ func (this *UserService) setUserLogo(user *info.User) { } if user.Logo != "" && !strings.HasPrefix(user.Logo, "http") { 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) { - adminInfo := this.GetUserInfoByAny(adminUsername) - if adminInfo.UserId.Hex() != adminUserId { + if configService.GetAdminUserId() != adminUserId { return } ok = db.UpdateByQField(db.Users, bson.M{"_id": bson.ObjectIdHex(userId)}, "Pwd", Md5(pwd)) diff --git a/app/service/init.go b/app/service/init.go index e386a7c..2c7cb7e 100644 --- a/app/service/init.go +++ b/app/service/init.go @@ -1,7 +1,6 @@ package service import ( - "github.com/revel/revel" ) // init service, for share service bettween services @@ -30,9 +29,6 @@ var UpgradeS *UpgradeService var SessionS, sessionService *SessionService var ThemeS, themeService *ThemeService -var siteUrl string -var adminUsername = "admin" - // onAppStart调用 func InitService() { NotebookS = &NotebookService{} @@ -74,6 +70,4 @@ func InitService() { emailService = EmailS sessionService = SessionS themeService = ThemeS - - siteUrl, _ = revel.Config.String("site.url") -} \ No newline at end of file +} diff --git a/messages/msg.en b/messages/msg.en index 6b3f71c..f81e974 100644 --- a/messages/msg.en +++ b/messages/msg.en @@ -242,6 +242,8 @@ latest=Latest # 用户中心 memberCenter=Member Center +userNotExists=该成员沿未注册 +hasUsers=已存在该成员 # error notFound=This page cann't found. diff --git a/messages/msg.zh b/messages/msg.zh index 0971dab..e22b669 100644 --- a/messages/msg.zh +++ b/messages/msg.zh @@ -268,6 +268,8 @@ latest=最新 # 用户中心 memberCenter=用户中心 +userNotExists=该成员沿未注册 +hasUsers=已存在该成员 # 必须要加这个, 奇怪 -[CN] \ No newline at end of file +[CN]