/
adminStorePluginHandler.go
274 lines (257 loc) · 8.82 KB
/
adminStorePluginHandler.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
package handlers
import (
"net/http"
"strconv"
"time"
sdbi "github.com/Ulbora/six910-database-interface"
"github.com/gorilla/mux"
)
/*
Six910 is a shopping cart and E-commerce system.
Copyright (C) 2020 Ulbora Labs LLC. (www.ulboralabs.com)
All rights reserved.
Copyright (C) 2020 Ken Williamson
All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//SpiPage SpiPage
type SpiPage struct {
Error string
StorePlugins *sdbi.StorePlugins
}
//StoreAdminAddStorePluginPage StoreAdminAddStorePluginPage
func (h *Six910Handler) StoreAdminAddStorePluginPage(w http.ResponseWriter, r *http.Request) {
aspis, suc := h.getSession(r)
h.Log.Debug("session suc in store plugins add view", suc)
if suc {
if h.isStoreAdminLoggedIn(aspis) {
aspiErr := r.URL.Query().Get("error")
var aspipg SpiPage
aspipg.Error = aspiErr
h.AdminTemplates.ExecuteTemplate(w, adminAddStorePluginPage, &aspipg)
} else {
http.Redirect(w, r, adminLogin, http.StatusFound)
}
}
}
//StoreAdminAddStorePluginFromListPage StoreAdminAddStorePluginFromListPage
func (h *Six910Handler) StoreAdminAddStorePluginFromListPage(w http.ResponseWriter, r *http.Request) {
fgpils, suc := h.getSession(r)
h.Log.Debug("session suc in store plugin from list view", suc)
if suc {
if h.isStoreAdminLoggedIn(fgpils) {
hd := h.getHeader(fgpils)
var fpiPage PluginPage
vpivars := mux.Vars(r)
fststr := vpivars["start"]
fendstr := vpivars["end"]
fvpistart, _ := strconv.ParseInt(fststr, 10, 64)
fvpiend, _ := strconv.ParseInt(fendstr, 10, 64)
pisl := h.API.GetPluginList(fvpistart, fvpiend, hd)
fpiPage.Pagination = h.doPagination(fvpistart, len(*pisl), 100, "/admin/addStorePluginFromList")
fpiPage.PluginList = pisl
h.Log.Debug("Plugin in list", pisl)
h.AdminTemplates.ExecuteTemplate(w, adminAddStorePluginFromListPage, &fpiPage)
} else {
http.Redirect(w, r, adminLogin, http.StatusFound)
}
}
}
//StoreAdminGetStorePluginToAddPage StoreAdminGetStorePluginToAddPage
func (h *Six910Handler) StoreAdminGetStorePluginToAddPage(w http.ResponseWriter, r *http.Request) {
taepis, suc := h.getSession(r)
h.Log.Debug("session suc in store plugin to add view", suc)
if suc {
if h.isStoreAdminLoggedIn(taepis) {
hd := h.getHeader(taepis)
taeipErr := r.URL.Query().Get("error")
epivars := mux.Vars(r)
tapidstr := epivars["id"]
iID, _ := strconv.ParseInt(tapidstr, 10, 64)
h.Log.Debug("plugin id in to add", iID)
var taepip PluginPage
taepip.Error = taeipErr
taepip.Plugin = h.API.GetPlugin(iID, hd)
h.AdminTemplates.ExecuteTemplate(w, adminStorePlugintoAddPage, &taepip)
} else {
http.Redirect(w, r, adminLogin, http.StatusFound)
}
}
}
//StoreAdminAddStorePlugin StoreAdminAddStorePlugin
func (h *Six910Handler) StoreAdminAddStorePlugin(w http.ResponseWriter, r *http.Request) {
addspis, suc := h.getSession(r)
h.Log.Debug("session suc in Store Plugin add", suc)
if suc {
if h.isStoreAdminLoggedIn(addspis) {
hd := h.getHeader(addspis)
apivars := mux.Vars(r)
atapidstr := apivars["id"]
aiID, _ := strconv.ParseInt(atapidstr, 10, 64)
h.Log.Debug("plugin id in to add", aiID)
exspil := h.API.GetStorePluginList(hd)
h.Log.Debug("plugin found in add: ", *exspil)
var explFound bool
for _, pi := range *exspil {
if pi.PluginID == aiID {
explFound = true
break
}
}
var addSuc bool
h.Log.Debug("explFound: ", explFound)
if !explFound {
pita := h.API.GetPlugin(aiID, hd)
var aspi sdbi.StorePlugins
aspi.PluginName = pita.PluginName
aspi.Category = pita.Category
aspi.Active = true
aspi.IsPGW = pita.IsPGW
aspi.PluginID = pita.ID
aspi.ActivateURL = pita.ActivateURL
aspi.OauthRedirectURL = pita.OauthRedirectURL
//aspi := h.processStorePlugin(r)
h.Log.Debug("Store Plugin add", aspi)
spirres := h.API.AddStorePlugin(&aspi, hd)
addSuc = spirres.Success
h.Log.Debug("Store Plugin add resp", *spirres)
} else {
addSuc = true
}
if addSuc {
http.Redirect(w, r, adminStorePluginListView, http.StatusFound)
} else {
http.Redirect(w, r, adminStorePluginListViewFail, http.StatusFound)
}
} else {
http.Redirect(w, r, adminLogin, http.StatusFound)
}
}
}
//StoreAdminEditStorePluginPage StoreAdminEditStorePluginPage
func (h *Six910Handler) StoreAdminEditStorePluginPage(w http.ResponseWriter, r *http.Request) {
espis, suc := h.getSession(r)
h.Log.Debug("session suc in Store Plugin edit view", suc)
if suc {
if h.isStoreAdminLoggedIn(espis) {
hd := h.getHeader(espis)
espipErr := r.URL.Query().Get("error")
espivars := mux.Vars(r)
espiidstr := espivars["id"]
iID, _ := strconv.ParseInt(espiidstr, 10, 64)
h.Log.Debug("Store Plugin id in edit", iID)
var espigp SpiPage
espigp.Error = espipErr
espigp.StorePlugins = h.API.GetStorePlugin(iID, hd)
h.AdminTemplates.ExecuteTemplate(w, adminEditStorePluginPage, &espigp)
} else {
http.Redirect(w, r, adminLogin, http.StatusFound)
}
}
}
//StoreAdminEditStorePlugin StoreAdminEditStorePlugin
func (h *Six910Handler) StoreAdminEditStorePlugin(w http.ResponseWriter, r *http.Request) {
espiis, suc := h.getSession(r)
h.Log.Debug("session suc in store plugin edit", suc)
if suc {
if h.isStoreAdminLoggedIn(espiis) {
espii := h.processStorePlugin(r)
h.Log.Debug("store plugin update", *espii)
hd := h.getHeader(espiis)
res := h.API.UpdateStorePlugin(espii, hd)
h.Log.Debug("store plugin update resp", *res)
if res.Success {
http.Redirect(w, r, adminStorePluginListView, http.StatusFound)
} else {
http.Redirect(w, r, adminStorePluginListViewFail, http.StatusFound)
}
} else {
http.Redirect(w, r, adminLogin, http.StatusFound)
}
}
}
//StoreAdminViewStorePluginList StoreAdminViewStorePluginList
func (h *Six910Handler) StoreAdminViewStorePluginList(w http.ResponseWriter, r *http.Request) {
gspils, suc := h.getSession(r)
h.Log.Debug("session suc in store plugin view", suc)
if suc {
if h.isStoreAdminLoggedIn(gspils) {
hd := h.getHeader(gspils)
spisl := h.API.GetStorePluginList(hd)
h.Log.Debug("store plugin in list", spisl)
h.AdminTemplates.ExecuteTemplate(w, adminStorePluginListPage, &spisl)
} else {
http.Redirect(w, r, adminLogin, http.StatusFound)
}
}
}
//StoreAdminDeleteStorePlugin StoreAdminDeleteStorePlugin
func (h *Six910Handler) StoreAdminDeleteStorePlugin(w http.ResponseWriter, r *http.Request) {
dspis, suc := h.getSession(r)
h.Log.Debug("session suc in store plugin list delete", suc)
if suc {
if h.isStoreAdminLoggedIn(dspis) {
hd := h.getHeader(dspis)
dspivars := mux.Vars(r)
idstrd := dspivars["id"]
idddspi, _ := strconv.ParseInt(idstrd, 10, 64)
res := h.API.DeleteStorePlugin(idddspi, hd)
h.Log.Debug("store plugin delete resp", *res)
if res.Success {
http.Redirect(w, r, adminStorePluginListView, http.StatusFound)
} else {
http.Redirect(w, r, adminStorePluginListViewFail, http.StatusFound)
}
} else {
http.Redirect(w, r, adminLogin, http.StatusFound)
}
}
}
func (h *Six910Handler) processStorePlugin(r *http.Request) *sdbi.StorePlugins {
var i sdbi.StorePlugins
id := r.FormValue("id")
i.ID, _ = strconv.ParseInt(id, 10, 64)
i.PluginName = r.FormValue("pluginName")
i.Category = r.FormValue("category")
active := r.FormValue("active")
if active == "on" {
i.Active = true
} else {
i.Active = false
}
//i.Active, _ = strconv.ParseBool(active)
oauthClientID := r.FormValue("oauthClientId")
i.OauthClientID, _ = strconv.ParseInt(oauthClientID, 10, 64)
i.OauthSecret = r.FormValue("oauthSecret")
i.OauthRedirectURL = r.FormValue("oauthRedirectUrl")
i.ActivateURL = r.FormValue("activateUrl")
i.APIKey = r.FormValue("apiKey")
rekeyTryCount := r.FormValue("rekeyTryCount")
i.RekeyTryCount, _ = strconv.ParseInt(rekeyTryCount, 10, 64)
rekeyDate := r.FormValue("rekeyDate")
i.RekeyDate, _ = time.Parse(timeFormat, rekeyDate)
i.IframeURL = r.FormValue("iframeUrl")
i.MenuTitle = r.FormValue("menuTitle")
i.MenuIconURL = r.FormValue("menuIconUrl")
isPgw := r.FormValue("isPgw")
i.IsPGW, _ = strconv.ParseBool(isPgw)
// if isPgw == "on" {
// i.IsPGW = true
// } else {
// i.IsPGW = false
// }
pluginID := r.FormValue("pluginId")
i.PluginID, _ = strconv.ParseInt(pluginID, 10, 64)
storeID := r.FormValue("storeId")
i.StoreID, _ = strconv.ParseInt(storeID, 10, 64)
return &i
}