2017-04-30 22:13:12 +08:00
|
|
|
package routers
|
|
|
|
|
|
|
|
import (
|
2018-01-26 17:17:38 +08:00
|
|
|
"encoding/json"
|
2017-04-30 22:13:12 +08:00
|
|
|
"github.com/astaxie/beego"
|
|
|
|
"github.com/astaxie/beego/context"
|
2017-06-14 09:23:29 +08:00
|
|
|
"github.com/lifei6671/mindoc/conf"
|
|
|
|
"github.com/lifei6671/mindoc/models"
|
2018-01-26 17:17:38 +08:00
|
|
|
"net/url"
|
2017-04-30 22:13:12 +08:00
|
|
|
)
|
|
|
|
|
2018-01-26 17:17:38 +08:00
|
|
|
func init() {
|
2017-04-30 22:13:12 +08:00
|
|
|
var FilterUser = func(ctx *context.Context) {
|
|
|
|
_, ok := ctx.Input.Session(conf.LoginSessionName).(models.Member)
|
|
|
|
|
|
|
|
if !ok {
|
2017-07-07 16:20:55 +08:00
|
|
|
if ctx.Input.IsAjax() {
|
2018-01-26 17:17:38 +08:00
|
|
|
jsonData := make(map[string]interface{}, 3)
|
2017-07-07 16:20:55 +08:00
|
|
|
|
|
|
|
jsonData["errcode"] = 403
|
|
|
|
jsonData["message"] = "请登录后再操作"
|
2018-01-26 17:17:38 +08:00
|
|
|
|
2017-07-07 16:20:55 +08:00
|
|
|
returnJSON, _ := json.Marshal(jsonData)
|
|
|
|
|
|
|
|
ctx.ResponseWriter.Write(returnJSON)
|
2018-01-26 17:17:38 +08:00
|
|
|
} else {
|
|
|
|
ctx.Redirect(302, beego.URLFor("AccountController.Login") + "?url=" + url.PathEscape(ctx.Request.URL.RequestURI()))
|
2017-07-07 16:20:55 +08:00
|
|
|
}
|
2017-04-30 22:13:12 +08:00
|
|
|
}
|
|
|
|
}
|
2018-01-26 17:17:38 +08:00
|
|
|
beego.InsertFilter("/manager", beego.BeforeRouter, FilterUser)
|
|
|
|
beego.InsertFilter("/manager/*", beego.BeforeRouter, FilterUser)
|
|
|
|
beego.InsertFilter("/setting", beego.BeforeRouter, FilterUser)
|
|
|
|
beego.InsertFilter("/setting/*", beego.BeforeRouter, FilterUser)
|
|
|
|
beego.InsertFilter("/book", beego.BeforeRouter, FilterUser)
|
|
|
|
beego.InsertFilter("/book/*", beego.BeforeRouter, FilterUser)
|
|
|
|
beego.InsertFilter("/api/*", beego.BeforeRouter, FilterUser)
|
2017-05-03 14:22:05 +08:00
|
|
|
|
|
|
|
var FinishRouter = func(ctx *context.Context) {
|
2018-01-26 17:17:38 +08:00
|
|
|
ctx.ResponseWriter.Header().Add("MinDoc-Version", conf.VERSION)
|
|
|
|
ctx.ResponseWriter.Header().Add("MinDoc-Site", "https://www.iminho.me")
|
2017-05-03 14:22:05 +08:00
|
|
|
}
|
|
|
|
|
2018-01-26 17:17:38 +08:00
|
|
|
beego.InsertFilter("/*", beego.BeforeRouter, FinishRouter, false)
|
2017-04-30 22:13:12 +08:00
|
|
|
}
|