Add register_event endpoint
This commit is contained in:
parent
21233a7c6c
commit
deb378e5d5
22
README.md
22
README.md
|
@ -5,6 +5,7 @@ Daemon for retrieving Argon2 hashes for user pseudonymisation in vote result lis
|
|||
|
||||
# API definition
|
||||
## Get vote ID
|
||||
Retrieve hashes / vote IDs for a list of user names and a known event.
|
||||
### REQUEST
|
||||
Request Headers - endpoint requires SSL client certificate
|
||||
```http
|
||||
|
@ -34,3 +35,24 @@ Request Body
|
|||
[...] // repeats for all users listed in request
|
||||
]
|
||||
```
|
||||
## Register event
|
||||
### REQUEST
|
||||
Request Headers - endpoint requires SSL client certificate
|
||||
```http
|
||||
GET /register_event HTTP/1.1
|
||||
Host: abstimmidd.netzbegruenung.de
|
||||
Content-Type: application/json
|
||||
```
|
||||
Request Body
|
||||
```javascript
|
||||
{
|
||||
"event_token": String // Secret event token to identify event
|
||||
}
|
||||
```
|
||||
### RESPONSE
|
||||
```javascript
|
||||
[
|
||||
"success": Bool // Registration of event was successful
|
||||
]
|
||||
```
|
||||
|
||||
|
|
|
@ -32,6 +32,18 @@ function get_event_id($cfg, $token) {
|
|||
return $event_id;
|
||||
}
|
||||
|
||||
function register_event($cfg) {
|
||||
$body = json_decode(file_get_contents('php://input'));
|
||||
$event_id = get_event_id($cfg, $body->event_token);
|
||||
$event_token = $body->event_token;
|
||||
$query = "INSERT INTO events (token) VALUES (?)";
|
||||
$stmt = $cfg['mysqli']->prepare($query);
|
||||
$stmt->bind_param("s", $event_token);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
function save_hash($cfg, $event_id, $vote_round, $name, $hash) {
|
||||
$query = "INSERT INTO hashes (event, vote_round, name, hash) VALUES (?, ?, ?, ?)";
|
||||
$stmt = $cfg['mysqli']->prepare($query);
|
||||
|
|
|
@ -7,6 +7,9 @@ header('Content-Type: application/json');
|
|||
if($_SERVER["REQUEST_URI"] == '/get_ids') {
|
||||
$data = get_voting_ids($cfg);
|
||||
echo json_encode($data);
|
||||
} else if($_SERVER["REQUEST_URI"] == '/register_event') {
|
||||
$data = register_event($cfg);
|
||||
echo json_encode($data);
|
||||
}
|
||||
else {
|
||||
echo json_encode(array("error" => "no route"));
|
||||
|
|
Loading…
Reference in a new issue