MCPcopy Index your code
hub / github.com/TruthHun/DocHub / Prepare

Method Prepare

controllers/HomeControllers/BaseController.go:31–69  ·  view source on GitHub ↗

初始化函数

()

Source from the content-addressed store, hash-verified

29
30//初始化函数
31func (this *BaseController) Prepare() {
32 ctrl, _ := this.GetControllerAndAction()
33 ctrl = strings.TrimSuffix(ctrl, "Controller")
34
35 //设置默认模板
36 this.TplTheme = "default"
37 this.TplPrefix = "Home/" + this.TplTheme + "/" + ctrl + "/"
38 this.Layout = "Home/" + this.TplTheme + "/layout.html"
39
40 //防止跨站攻击
41 //检测用户是否已经在cookie存在登录
42 this.checkCookieLogin()
43
44 //初始化
45 this.Data["LoginUid"] = this.IsLogin
46 //当前模板静态文件
47 this.Data["TplStatic"] = "/static/Home/" + this.TplTheme
48
49 version := helper.VERSION
50 if helper.Debug { //debug模式下,每次更新js
51 version = fmt.Sprintf("%v.%v", version, time.Now().Unix())
52 }
53 this.Sys, _ = models.NewSys().Get()
54 this.Data["Version"] = version
55 this.Data["Sys"] = this.Sys
56 this.Data["Chanels"] = models.NewCategory().GetByPid(0, true)
57 this.Data["Pages"], _, _ = models.NewPages().List(beego.AppConfig.DefaultInt("pageslimit", 6), 1)
58 this.Data["AdminId"] = helper.Interface2Int(this.GetSession("AdminId"))
59 this.Data["CopyrightDate"] = time.Now().Format("2006")
60
61 this.Data["PreviewDomain"] = ""
62
63 if cs, err := models.NewCloudStore(false); err == nil {
64 this.Data["PreviewDomain"] = cs.GetPublicDomain()
65 } else {
66 helper.Logger.Error(err.Error())
67 }
68
69}
70
71//是否已经登录,如果已登录,则返回用户的id
72func (this *BaseController) CheckLogin() int {

Callers

nothing calls this directly

Calls 5

checkCookieLoginMethod · 0.95
GetPublicDomainMethod · 0.95
GetByPidMethod · 0.80
GetMethod · 0.45
ListMethod · 0.45

Tested by

no test coverage detected