Skip to content

Commit 6a53a65

Browse files
authored
Merge pull request #206 from dedis/amine
Implementation of the Sciper checking
2 parents 9faabe7 + de824c2 commit 6a53a65

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

internal/testing/fake/election.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ func NewForm(formID string) types.Form {
2020
MainTitle: "dummyTitle",
2121
},
2222
FormID: formID,
23-
Status: types.Closed,
24-
Pubkey: pubKey,
23+
Status: types.Closed,
24+
Pubkey: pubKey,
2525
Suffragia: types.Suffragia{
2626
Ciphervotes: []types.Ciphervote{},
2727
},

web/backend/src/Server.ts

+28-4
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,34 @@ app.post('/api/add_role', (req, res) => {
258258
const { sciper } = req.body;
259259
const { role } = req.body;
260260

261-
usersDB.put(sciper, role).catch((error) => {
262-
res.status(500).send('Failed to add role');
263-
console.log(error);
264-
});
261+
// The sciper has to contain 6 numbers
262+
if (sciper > 999999 || sciper < 100000) {
263+
res.status(400).send('Sciper length is incorrect');
264+
return;
265+
}
266+
267+
// Call https://search-api.epfl.ch/api/ldap?q=228271, if the answer is
268+
// empty then sciper unknown, otherwise add it in userDB
269+
axios
270+
.get(`https://search-api.epfl.ch/api/ldap?q=${sciper}`)
271+
.then((response) => {
272+
if (response.data.length === 0) {
273+
res.status(400).send('Unknown Sciper');
274+
return;
275+
}
276+
277+
usersDB
278+
.put(sciper, role)
279+
.then(() => res.status(200).send('Role added'))
280+
.catch((error) => {
281+
res.status(500).send('Failed to add role');
282+
console.log(error);
283+
});
284+
})
285+
.catch((error) => {
286+
res.status(500).send('Failed to check Sciper');
287+
console.log(error);
288+
});
265289
});
266290

267291
// This call (only for admins) allow an admin to remove a role to a user.

0 commit comments

Comments
 (0)