1
- package main
1
+ package service
2
2
3
3
import (
4
4
"github.com/gorilla/mux"
5
5
"html/template"
6
6
"net/http"
7
7
"net/url"
8
8
"strings"
9
+ "keystation/model"
10
+ "keystation/util"
9
11
)
10
12
11
- func indexHandler (w http.ResponseWriter , r * http.Request ) {
13
+ var (
14
+ indexTemplate = template .Must (template .ParseFiles ("www/index.html" ))
15
+ importTemplate = template .Must (template .ParseFiles ("www/import.html" ))
16
+ signInTemplate = template .Must (template .ParseFiles ("www/signin.html" ))
17
+ sessionTemplate = template .Must (template .ParseFiles ("www/session.html" ))
18
+ txTemplate = template .Must (template .ParseFiles ("www/transaction.html" ))
19
+ )
20
+
21
+ func IndexHandler (w http.ResponseWriter , r * http.Request ) {
12
22
if r .URL .Path != "/" {
13
23
http .Redirect (w , r , "/" , http .StatusFound )
14
24
return
@@ -18,7 +28,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
18
28
return
19
29
}
20
30
21
- func importHandler (w http.ResponseWriter , r * http.Request ) {
31
+ func ImportHandler (w http.ResponseWriter , r * http.Request ) {
22
32
vars := mux .Vars (r )
23
33
24
34
client , err := url .QueryUnescape (vars ["client" ])
@@ -45,20 +55,20 @@ func importHandler(w http.ResponseWriter, r *http.Request) {
45
55
return
46
56
}
47
57
48
- params := importTemplateParams {}
58
+ params := model. ImportTemplateParams {}
49
59
params .QueryUrl = "signin?client=" + url .QueryEscape (client ) + "&lcd=" + url .QueryEscape (lcd ) + "&path=" + url .QueryEscape (path ) + "&payload=" + url .QueryEscape (payload )
50
60
params .Client = client
51
61
params .Lcd = lcd
52
62
params .Path = path
53
63
params .Payload = payload
54
- params .ShuffledNumCode = template .HTML (GetShuffledNum ()) // Keypad of shuffled number
55
- params .ShuffledAlphabetCode = template .HTML (GetShuffledAlphabet ()) // Keypad of shuffled alphabet
64
+ params .ShuffledNumCode = template .HTML (util . GetShuffledNum ()) // Keypad of shuffled number
65
+ params .ShuffledAlphabetCode = template .HTML (util . GetShuffledAlphabet ()) // Keypad of shuffled alphabet
56
66
57
67
importTemplate .Execute (w , params )
58
68
return
59
69
}
60
70
61
- func signInHandler (w http.ResponseWriter , r * http.Request ) {
71
+ func SignInHandler (w http.ResponseWriter , r * http.Request ) {
62
72
vars := mux .Vars (r )
63
73
64
74
client , err := url .QueryUnescape (vars ["client" ])
@@ -85,19 +95,19 @@ func signInHandler(w http.ResponseWriter, r *http.Request) {
85
95
return
86
96
}
87
97
88
- params := signInTemplateParams {}
98
+ params := model. SignInTemplateParams {}
89
99
params .QueryUrl = "import?client=" + url .QueryEscape (client ) + "&lcd=" + url .QueryEscape (lcd ) + "&path=" + url .QueryEscape (path ) + "&payload=" + url .QueryEscape (payload )
90
100
params .Lcd = lcd
91
- params .ShuffledNumCode = template .HTML (GetShuffledNum ()) // Keypad of shuffled number
92
- params .ShuffledAlphabetCode = template .HTML (GetShuffledAlphabet ()) // Keypad of shuffled alphabet
101
+ params .ShuffledNumCode = template .HTML (util . GetShuffledNum ()) // Keypad of shuffled number
102
+ params .ShuffledAlphabetCode = template .HTML (util . GetShuffledAlphabet ()) // Keypad of shuffled alphabet
93
103
94
104
signInTemplate .Execute (w , params )
95
105
return
96
106
}
97
107
98
- func sessionInHandler (w http.ResponseWriter , r * http.Request ) {
108
+ func SessionInHandler (w http.ResponseWriter , r * http.Request ) {
99
109
// HTML Form
100
- importForm := ImportForm {
110
+ importForm := model. ImportForm {
101
111
Account : r .FormValue ("account" ),
102
112
Client : r .FormValue ("client" ),
103
113
Path : r .FormValue ("path" ),
@@ -143,7 +153,7 @@ func sessionInHandler(w http.ResponseWriter, r *http.Request) {
143
153
}
144
154
}
145
155
146
- params := sessionTemplateParams {}
156
+ params := model. SessionTemplateParams {}
147
157
params .QueryUrl = "import?client=" + url .QueryEscape (client ) + "&lcd=" + url .QueryEscape (lcd ) + "&path=" + url .QueryEscape (path ) + "&payload=" + url .QueryEscape (payloadForQuery )
148
158
params .Payload = payload // address
149
159
params .Account = account // keychain account
@@ -152,7 +162,7 @@ func sessionInHandler(w http.ResponseWriter, r *http.Request) {
152
162
return
153
163
}
154
164
155
- func txHandler (w http.ResponseWriter , r * http.Request ) {
165
+ func TxHandler (w http.ResponseWriter , r * http.Request ) {
156
166
vars := mux .Vars (r )
157
167
158
168
account , err := url .QueryUnescape (vars ["account" ])
@@ -186,14 +196,14 @@ func txHandler(w http.ResponseWriter, r *http.Request) {
186
196
return
187
197
}
188
198
189
- params := txTemplateParams {}
199
+ params := model. TxTemplateParams {}
190
200
params .Account = account
191
201
params .Client = client
192
202
params .Lcd = lcd
193
203
params .Path = path
194
204
params .Payload = payload
195
- params .ShuffledNumCode = template .HTML (GetShuffledNum ()) // Keypad of shuffled number
196
- params .ShuffledAlphabetCode = template .HTML (GetShuffledAlphabet ()) // Keypad of shuffled alphabet
205
+ params .ShuffledNumCode = template .HTML (util . GetShuffledNum ()) // Keypad of shuffled number
206
+ params .ShuffledAlphabetCode = template .HTML (util . GetShuffledAlphabet ()) // Keypad of shuffled alphabet
197
207
198
208
txTemplate .Execute (w , params )
199
209
return
0 commit comments