siteurl, adminUsername config in configService
This commit is contained in:
@ -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}})
|
||||
|
@ -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://") {
|
||||
|
@ -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 != "" {
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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))
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user