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";
}
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)
}
}

View File

@ -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 != "" {

View File

@ -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)
}
}

View File

@ -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 == "" {

View File

@ -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;
}
}
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 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{})
}
}

View File

@ -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()
})
}
}

View File

@ -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")
})
}
}