@@ -49,8 +49,8 @@ function sendToDela(dataStr: string, req: express.Request, res: express.Response
49
49
let uri = process . env . DELA_NODE_URL + req . baseUrl . slice ( 4 ) ;
50
50
// boolean to check
51
51
let redirectToDefaultProxy = true ;
52
- // in case this is a DKG init request, we must also update the payload.
53
52
53
+ // in case this is a DKG init request, we must also update the payload.
54
54
const dkgInitRegex = / \/ e v o t i n g \/ s e r v i c e s \/ d k g \/ a c t o r s $ / ;
55
55
if ( uri . match ( dkgInitRegex ) ) {
56
56
const dataStr2 = JSON . stringify ( { FormID : req . body . FormID } ) ;
@@ -154,6 +154,7 @@ delaRouter.post('/services/dkg/actors', (req, res, next) => {
154
154
}
155
155
next ( ) ;
156
156
} ) ;
157
+
157
158
delaRouter . use ( '/services/dkg/actors/:formID' , ( req , res , next ) => {
158
159
const { formID } = req . params ;
159
160
if ( ! isAuthorized ( req . session . userId , formID , PERMISSIONS . ACTIONS . OWN ) ) {
@@ -162,6 +163,7 @@ delaRouter.use('/services/dkg/actors/:formID', (req, res, next) => {
162
163
}
163
164
next ( ) ;
164
165
} ) ;
166
+
165
167
delaRouter . use ( '/services/shuffle/:formID' , ( req , res , next ) => {
166
168
if ( ! req . session . userId ) {
167
169
res . status ( 401 ) . send ( 'Unauthenticated' ) ;
@@ -174,6 +176,32 @@ delaRouter.use('/services/shuffle/:formID', (req, res, next) => {
174
176
}
175
177
next ( ) ;
176
178
} ) ;
179
+
180
+ delaRouter . post ( '/forms/:formID/vote' , ( req , res ) => {
181
+ if ( ! req . session . userId ) {
182
+ res . status ( 401 ) . send ( 'Authentication required!' ) ;
183
+ return ;
184
+ }
185
+ if ( ! isAuthorized ( req . session . userId , req . params . formID , PERMISSIONS . ACTIONS . VOTE ) ) {
186
+ res . status ( 400 ) . send ( 'Unauthorized' ) ;
187
+ return ;
188
+ }
189
+
190
+ // We must set the UserID to know who this ballot is associated to. This is
191
+ // only needed to allow users to cast multiple ballots, where only the last
192
+ // ballot is taken into account. To preserve anonymity, the web-backend could
193
+ // translate UserIDs to another random ID.
194
+ // bodyData.UserID = req.session.userId.toString();
195
+
196
+ // DEBUG: this is only for debugging and needs to be replaced before production
197
+ const bodyData = req . body ;
198
+ console . warn ( 'DEV CODE - randomizing the SCIPER ID to allow for unlimited votes' ) ;
199
+ bodyData . UserID = makeid ( 10 ) ;
200
+
201
+ const dataStr = JSON . stringify ( bodyData ) ;
202
+ sendToDela ( dataStr , req , res ) ;
203
+ } ) ;
204
+
177
205
delaRouter . delete ( '/forms/:formID' , ( req , res ) => {
178
206
if ( ! req . session . userId ) {
179
207
res . status ( 401 ) . send ( 'Unauthenticated' ) ;
@@ -235,18 +263,6 @@ delaRouter.use('/*', (req, res) => {
235
263
}
236
264
237
265
const bodyData = req . body ;
238
-
239
- // special case for voting
240
- const regex = / \/ a p i \/ e v o t i n g \/ f o r m s \/ .* \/ v o t e / ;
241
- if ( req . baseUrl . match ( regex ) ) {
242
- // We must set the UserID to know who this ballot is associated to. This is
243
- // only needed to allow users to cast multiple ballots, where only the last
244
- // ballot is taken into account. To preserve anonymity the web-backend could
245
- // translate UserIDs to another random ID.
246
- // bodyData.UserID = req.session.userId.toString();
247
- bodyData . UserID = makeid ( 10 ) ;
248
- }
249
-
250
266
const dataStr = JSON . stringify ( bodyData ) ;
251
267
252
268
sendToDela ( dataStr , req , res ) ;
0 commit comments