MCPcopy Create free account
hub / github.com/TruthHun/DocHub / Prepare

Method Prepare

controllers/AdminControllers/BaseController.go:25–62  ·  view source on GitHub ↗

初始化函数

()

Source from the content-addressed store, hash-verified

23
24//初始化函数
25func (this *BaseController) Prepare() {
26 var ok bool
27 this.Sys, _ = models.NewSys().Get()
28 //检测是否已登录,未登录则跳转到登录页
29 AdminId := this.GetSession("AdminId")
30 this.AdminId, ok = AdminId.(int)
31 this.Data["Admin"], _ = models.NewAdmin().GetById(this.AdminId)
32 if !ok || this.AdminId == 0 {
33 this.Redirect("/admin/login", 302)
34 return
35 }
36
37 version := helper.VERSION
38 if helper.Debug {
39 version = fmt.Sprintf("%v.%v", version, time.Now().Unix())
40 }
41 this.Data["Version"] = version
42 //后台关闭XSRF功能
43 this.EnableXSRF = false
44 ctrl, _ := this.GetControllerAndAction()
45 ctrl = strings.TrimSuffix(ctrl, "Controller")
46 //设置默认模板
47 this.TplTheme = "default"
48 this.TplPrefix = "Admin/" + this.TplTheme + "/" + ctrl + "/"
49 this.Layout = "Admin/" + this.TplTheme + "/layout.html"
50 //当前模板静态文件
51 this.Data["TplStatic"] = "/static/Admin/" + this.TplTheme
52 //this.Data["PreviewDomain"] = beego.AppConfig.String("oss::PreviewUrl")
53 if cs, err := models.NewCloudStore(false); err == nil {
54 this.Data["PreviewDomain"] = cs.GetPublicDomain()
55 } else {
56 helper.Logger.Error(err.Error())
57 this.Data["PreviewDomain"] = ""
58 }
59 this.Data["Sys"] = this.Sys
60 this.Data["Title"] = "文库系统管理后台"
61 this.Data["Lang"] = "zh-CN"
62}
63
64//自定义的文档错误
65func (this *BaseController) ErrorDiy(status, redirect, msg interface{}, timewait int) {

Callers

nothing calls this directly

Calls 3

GetPublicDomainMethod · 0.95
GetMethod · 0.45
GetByIdMethod · 0.45

Tested by

no test coverage detected