/
c-admin-site.go
162 lines (140 loc) · 3.77 KB
/
c-admin-site.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package site
import (
"net/http"
"github.com/kapmahc/axe"
"github.com/kapmahc/axe/i18n"
)
type fmSiteInfo struct {
Title string `json:"title"`
SubTitle string `json:"subTitle"`
Keywords string `json:"keywords"`
Description string `json:"description"`
Copyright string `json:"copyright"`
}
func (p *Plugin) postAdminSiteInfo(c *axe.Context) {
var fm fmSiteInfo
if err := c.Bind(&fm); err != nil {
c.Abort(http.StatusInternalServerError, err)
return
}
lng := c.Payload[i18n.LOCALE].(string)
for k, v := range map[string]string{
"title": fm.Title,
"subTitle": fm.SubTitle,
"keywords": fm.Keywords,
"description": fm.Description,
"copyright": fm.Copyright,
} {
if err := p.I18n.Set(lng, "site."+k, v); err != nil {
c.Abort(http.StatusInternalServerError, err)
return
}
}
c.JSON(http.StatusOK, axe.H{})
}
type fmSiteAuthor struct {
Name string `json:"name"`
Email string `json:"email"`
}
func (p *Plugin) postAdminSiteAuthor(c *axe.Context) {
var fm fmSiteAuthor
if err := c.Bind(&fm); err != nil {
c.Abort(http.StatusInternalServerError, err)
return
}
lng := c.Payload[i18n.LOCALE].(string)
for k, v := range map[string]string{
"name": fm.Name,
"email": fm.Email,
} {
if err := p.I18n.Set(lng, "site.author."+k, v); err != nil {
c.Abort(http.StatusInternalServerError, err)
return
}
}
c.JSON(http.StatusOK, axe.H{})
}
func (p *Plugin) getAdminSiteSeo(c *axe.Context) {
var gc string
var bc string
p.Settings.Get("site.google.verify.code", &gc)
p.Settings.Get("site.baidu.verify.code", &bc)
links := []string{"robots.txt", "sitemap.xml.gz", "google" + gc + ".html", "baidu_verify_" + bc + ".html"}
langs, err := p.I18n.Store.Languages()
if err != nil {
c.Abort(http.StatusInternalServerError, err)
return
}
for _, l := range langs {
links = append(links, "rss-"+l+".atom")
}
c.JSON(http.StatusOK, axe.H{
"googleVerifyCode": gc,
"baiduVerifyCode": bc,
"links": links,
})
}
type fmSiteSeo struct {
GoogleVerifyCode string `json:"googleVerifyCode"`
BaiduVerifyCode string `json:"baiduVerifyCode"`
}
func (p *Plugin) postAdminSiteSeo(c *axe.Context) {
var fm fmSiteSeo
if err := c.Bind(&fm); err != nil {
c.Abort(http.StatusInternalServerError, err)
return
}
for k, v := range map[string]string{
"google.verify.code": fm.GoogleVerifyCode,
"baidu.verify.code": fm.BaiduVerifyCode,
} {
if err := p.Settings.Set("site."+k, v, true); err != nil {
c.Abort(http.StatusInternalServerError, err)
return
}
}
c.JSON(http.StatusOK, axe.H{})
}
type fmSiteSMTP struct {
Host string `json:"host"`
Port int `json:"port"`
Ssl bool `json:"ssl"`
Username string `json:"username"`
Password string `json:"password" validate:"min=6,max=32"`
PasswordConfirmation string `json:"passwordConfirmation" validate:"eqfield=Password"`
}
func (p *Plugin) getAdminSiteSMTP(c *axe.Context) {
smtp := make(map[string]interface{})
if err := p.Settings.Get("site.smtp", &smtp); err == nil {
smtp["password"] = ""
} else {
smtp["host"] = "localhost"
smtp["port"] = 25
smtp["ssl"] = false
smtp["username"] = "no-reply@change-me.com"
smtp["password"] = ""
}
c.JSON(http.StatusOK, axe.H{
"smtp": smtp,
"ports": []int{25, 465, 587},
})
}
func (p *Plugin) postAdminSiteSMTP(c *axe.Context) {
var fm fmSiteSMTP
if err := c.Bind(&fm); err != nil {
c.Abort(http.StatusInternalServerError, err)
return
}
val := map[string]interface{}{
"host": fm.Host,
"port": fm.Port,
"username": fm.Username,
"password": fm.Password,
"ssl": fm.Ssl,
}
if err := p.Settings.Set("site.smtp", val, true); err != nil {
c.Abort(http.StatusInternalServerError, err)
return
}
c.JSON(http.StatusOK, axe.H{})
}