增加 web_base_url 配置, 用于配置 web 后台可置于代理子路径下

This commit is contained in:
涵曦
2019-05-10 16:29:55 +00:00
parent 4b7b2f4c27
commit 383dbd1b7b
21 changed files with 124 additions and 73 deletions

View File

@@ -21,6 +21,7 @@ type BaseController struct {
//初始化参数
func (s *BaseController) Prepare() {
s.Data["web_base_url"] = beego.AppConfig.String("web_base_url")
controllerName, actionName := s.GetControllerAndAction()
s.controllerName = strings.ToLower(controllerName[0 : len(controllerName)-10])
s.actionName = strings.ToLower(actionName)
@@ -33,7 +34,7 @@ func (s *BaseController) Prepare() {
timeNowUnix := time.Now().Unix()
if !((math.Abs(float64(timeNowUnix-int64(timestamp))) <= 20) && (crypt.Md5(configKey+strconv.Itoa(timestamp)) == md5Key)) {
if s.GetSession("auth") != true {
s.Redirect("/login/index", 302)
s.Redirect(beego.AppConfig.String("web_base_url")+"/login/index", 302)
}
}
if s.GetSession("isAdmin") != nil && !s.GetSession("isAdmin").(bool) {
@@ -59,6 +60,7 @@ func (s *BaseController) Prepare() {
//加载模板
func (s *BaseController) display(tpl ...string) {
s.Data["web_base_url"] = beego.AppConfig.String("web_base_url")
var tplname string
if s.Data["menu"] == nil {
s.Data["menu"] = s.actionName
@@ -82,6 +84,7 @@ func (s *BaseController) display(tpl ...string) {
//错误
func (s *BaseController) error() {
s.Data["web_base_url"] = beego.AppConfig.String("web_base_url")
s.Layout = "public/layout.html"
s.TplName = "public/error.html"
}

View File

@@ -4,6 +4,7 @@ import (
"github.com/cnlh/nps/lib/file"
"github.com/cnlh/nps/server"
"github.com/cnlh/nps/server/tool"
"github.com/cnlh/nps/vender/github.com/astaxie/beego"
)
type IndexController struct {
@@ -11,6 +12,7 @@ type IndexController struct {
}
func (s *IndexController) Index() {
s.Data["web_base_url"] = beego.AppConfig.String("web_base_url")
s.Data["data"] = server.GetDashboardData()
s.SetInfo("dashboard")
s.display("index/index")

View File

@@ -13,6 +13,7 @@ type LoginController struct {
}
func (self *LoginController) Index() {
self.Data["web_base_url"] = beego.AppConfig.String("web_base_url")
self.Data["register_allow"], _ = beego.AppConfig.Bool("allow_user_register")
self.TplName = "login/index.html"
}
@@ -59,6 +60,7 @@ func (self *LoginController) Verify() {
}
func (self *LoginController) Register() {
if self.Ctx.Request.Method == "GET" {
self.Data["web_base_url"] = beego.AppConfig.String("web_base_url")
self.TplName = "login/register.html"
} else {
if b, err := beego.AppConfig.Bool("allow_user_register"); err != nil || !b {
@@ -90,5 +92,5 @@ func (self *LoginController) Register() {
func (self *LoginController) Out() {
self.SetSession("auth", false)
self.Redirect("/login/index", 302)
self.Redirect(beego.AppConfig.String("web_base_url")+"/login/index", 302)
}