@@ -44,7 +44,7 @@ func NewForm(srv ordering.Service, mngr txn.Manager, p pool.Pool,
44
44
logger : logger ,
45
45
orderingSvc : srv ,
46
46
context : ctx ,
47
- formFac : fac ,
47
+ formFac : fac ,
48
48
mngr : mngr ,
49
49
pool : p ,
50
50
pk : pk ,
@@ -60,7 +60,7 @@ type form struct {
60
60
orderingSvc ordering.Service
61
61
logger zerolog.Logger
62
62
context serde.Context
63
- formFac serde.Factory
63
+ formFac serde.Factory
64
64
mngr txn.Manager
65
65
pool pool.Pool
66
66
pk kyber.Point
@@ -126,16 +126,6 @@ func (h *form) NewForm(w http.ResponseWriter, r *http.Request) {
126
126
127
127
// NewFormVote implements proxy.Proxy
128
128
func (h * form ) NewFormVote (w http.ResponseWriter , r * http.Request ) {
129
- vars := mux .Vars (r )
130
-
131
- // check if the formID is valid
132
- if vars == nil || vars ["formID" ] == "" {
133
- http .Error (w , fmt .Sprintf ("formID not found: %v" , vars ), http .StatusInternalServerError )
134
- return
135
- }
136
-
137
- formID := vars ["formID" ]
138
-
139
129
var req ptypes.CastVoteRequest
140
130
141
131
// get the signed request
@@ -152,6 +142,16 @@ func (h *form) NewFormVote(w http.ResponseWriter, r *http.Request) {
152
142
return
153
143
}
154
144
145
+ vars := mux .Vars (r )
146
+
147
+ // check if the formID is valid
148
+ if vars == nil || vars ["formID" ] == "" {
149
+ http .Error (w , fmt .Sprintf ("formID not found: %v" , vars ), http .StatusInternalServerError )
150
+ return
151
+ }
152
+
153
+ formID := vars ["formID" ]
154
+
155
155
elecMD , err := h .getFormsMetadata ()
156
156
if err != nil {
157
157
http .Error (w , "failed to get form metadata" , http .StatusNotFound )
@@ -166,7 +166,7 @@ func (h *form) NewFormVote(w http.ResponseWriter, r *http.Request) {
166
166
167
167
ciphervote := make (types.Ciphervote , len (req .Ballot ))
168
168
169
- // encrypt the vote
169
+ // encrypt the vote
170
170
for i , egpair := range req .Ballot {
171
171
k := suite .Point ()
172
172
@@ -192,8 +192,8 @@ func (h *form) NewFormVote(w http.ResponseWriter, r *http.Request) {
192
192
193
193
castVote := types.CastVote {
194
194
FormID : formID ,
195
- UserID : req .UserID ,
196
- Ballot : ciphervote ,
195
+ UserID : req .UserID ,
196
+ Ballot : ciphervote ,
197
197
}
198
198
199
199
// serialize the vote
@@ -214,6 +214,22 @@ func (h *form) NewFormVote(w http.ResponseWriter, r *http.Request) {
214
214
215
215
// EditForm implements proxy.Proxy
216
216
func (h * form ) EditForm (w http.ResponseWriter , r * http.Request ) {
217
+ var req ptypes.UpdateFormRequest
218
+
219
+ // get the signed request
220
+ signed , err := ptypes .NewSignedRequest (r .Body )
221
+ if err != nil {
222
+ InternalError (w , r , newSignedErr (err ), nil )
223
+ return
224
+ }
225
+
226
+ // get the request and verify the signature
227
+ err = signed .GetAndVerify (h .pk , & req )
228
+ if err != nil {
229
+ InternalError (w , r , getSignedErr (err ), nil )
230
+ return
231
+ }
232
+
217
233
vars := mux .Vars (r )
218
234
219
235
//check if the formID is valid
@@ -236,21 +252,6 @@ func (h *form) EditForm(w http.ResponseWriter, r *http.Request) {
236
252
return
237
253
}
238
254
239
- var req ptypes.UpdateFormRequest
240
-
241
- // get the signed request
242
- signed , err := ptypes .NewSignedRequest (r .Body )
243
- if err != nil {
244
- InternalError (w , r , newSignedErr (err ), nil )
245
- return
246
- }
247
-
248
- // get the request and verify the signature
249
- err = signed .GetAndVerify (h .pk , & req )
250
- if err != nil {
251
- InternalError (w , r , getSignedErr (err ), nil )
252
- return
253
- }
254
255
switch req .Action {
255
256
case "open" :
256
257
h .openForm (formID , w , r )
@@ -413,7 +414,7 @@ func (h *form) Form(w http.ResponseWriter, r *http.Request) {
413
414
}
414
415
415
416
response := ptypes.GetFormResponse {
416
- FormID : string (form .FormID ),
417
+ FormID : string (form .FormID ),
417
418
Configuration : form .Configuration ,
418
419
Status : uint16 (form .Status ),
419
420
Pubkey : hex .EncodeToString (pubkeyBuf ),
@@ -468,9 +469,9 @@ func (h *form) Forms(w http.ResponseWriter, r *http.Request) {
468
469
469
470
info := ptypes.LightForm {
470
471
FormID : string (form .FormID ),
471
- Title : form .Configuration .MainTitle ,
472
- Status : uint16 (form .Status ),
473
- Pubkey : hex .EncodeToString (pubkeyBuf ),
472
+ Title : form .Configuration .MainTitle ,
473
+ Status : uint16 (form .Status ),
474
+ Pubkey : hex .EncodeToString (pubkeyBuf ),
474
475
}
475
476
476
477
allFormsInfo [i ] = info
0 commit comments