Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sciper checking #206

Merged
merged 13 commits into from
Dec 14, 2022
4 changes: 2 additions & 2 deletions internal/testing/fake/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func NewForm(formID string) types.Form {
MainTitle: "dummyTitle",
},
FormID: formID,
Status: types.Closed,
Pubkey: pubKey,
Status: types.Closed,
Pubkey: pubKey,
Suffragia: types.Suffragia{
Ciphervotes: []types.Ciphervote{},
},
Expand Down
32 changes: 28 additions & 4 deletions web/backend/src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,34 @@ app.post('/api/add_role', (req, res) => {
const { sciper } = req.body;
const { role } = req.body;

usersDB.put(sciper, role).catch((error) => {
res.status(500).send('Failed to add role');
console.log(error);
});
// The sciper has to contain 6 numbers
if (sciper > 999999 || sciper < 100000) {
res.status(400).send('Sciper length is incorrect');
return;
}

// Call https://search-api.epfl.ch/api/ldap?q=228271, if the answer is
// empty then sciper unknown, otherwise add it in userDB
axios
.get(`https://search-api.epfl.ch/api/ldap?q=${sciper}`)
.then((response) => {
if (response.data.length === 0) {
res.status(400).send('Unknown Sciper');
return;
}

usersDB
.put(sciper, role)
.then(() => res.status(200).send('Role added'))
.catch((error) => {
res.status(500).send('Failed to add role');
console.log(error);
});
})
.catch((error) => {
res.status(500).send('Failed to check Sciper');
console.log(error);
});
});

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