forked from adamwalach/openvpn-web-ui
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsettings.go
55 lines (47 loc) · 1.14 KB
/
settings.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
package controllers
import (
"html/template"
"github.com/adamwalach/openvpn-web-ui/models"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
)
type SettingsController struct {
BaseController
}
func (c *SettingsController) NestPrepare() {
if !c.IsLogin {
c.Ctx.Redirect(302, c.LoginPath())
return
}
c.Data["breadcrumbs"] = &BreadCrumbs{
Title: "Settings",
}
}
func (c *SettingsController) Get() {
c.TplName = "settings.html"
c.Data["xsrfdata"] = template.HTML(c.XSRFFormHTML())
settings := models.Settings{Profile: "default"}
settings.Read("Profile")
c.Data["Settings"] = &settings
}
func (c *SettingsController) Post() {
c.TplName = "settings.html"
flash := beego.NewFlash()
settings := models.Settings{Profile: "default"}
settings.Read("Profile")
if err := c.ParseForm(&settings); err != nil {
beego.Warning(err)
flash.Error(err.Error())
flash.Store(&c.Controller)
return
}
c.Data["Settings"] = &settings
o := orm.NewOrm()
if _, err := o.Update(&settings); err != nil {
flash.Error(err.Error())
} else {
flash.Success("Settings has been updated")
models.GlobalCfg = settings
}
flash.Store(&c.Controller)
}