forked from adamwalach/openvpn-web-ui
/
base.go
81 lines (63 loc) · 1.52 KB
/
base.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package controllers
import (
"github.com/adamwalach/openvpn-web-ui/models"
"github.com/astaxie/beego"
)
type BaseController struct {
beego.Controller
Userinfo *models.User
IsLogin bool
}
type NestPreparer interface {
NestPrepare()
}
type NestFinisher interface {
NestFinish()
}
func (c *BaseController) Prepare() {
c.SetParams()
c.IsLogin = c.GetSession("userinfo") != nil
if c.IsLogin {
c.Userinfo = c.GetLogin()
}
c.Data["IsLogin"] = c.IsLogin
c.Data["Userinfo"] = c.Userinfo
//c.Data["HeadStyles"] = []string{}
//c.Data["HeadScripts"] = []string{}
//c.Layout = "base.tpl"
//c.LayoutSections = make(map[string]string)
//c.LayoutSections["BaseHeader"] = "header.tpl"
//c.LayoutSections["BaseFooter"] = "footer.tpl"
if app, ok := c.AppController.(NestPreparer); ok {
app.NestPrepare()
}
}
func (c *BaseController) Finish() {
if app, ok := c.AppController.(NestFinisher); ok {
app.NestFinish()
}
}
func (c *BaseController) GetLogin() *models.User {
u := &models.User{Id: c.GetSession("userinfo").(int64)}
u.Read()
return u
}
func (c *BaseController) DelLogin() {
c.DelSession("userinfo")
}
func (c *BaseController) SetLogin(user *models.User) {
c.SetSession("userinfo", user.Id)
}
func (c *BaseController) LoginPath() string {
return c.URLFor("LoginController.Login")
}
func (c *BaseController) SetParams() {
c.Data["Params"] = make(map[string]string)
for k, v := range c.Input() {
c.Data["Params"].(map[string]string)[k] = v[0]
}
}
type BreadCrumbs struct {
Title string
Subtitle string
}