function handle_auth() { $request = Flight::request(); //incoming= //outgoing= $stage = $request->query->stage; $ip = $request->query->ip; $mac = $request->query->mac; $token = $request->query->token; if (empty($stage) || empty($ip) || empty($mac) || empty($token)) { //Flight::Error('Required parameters empty!'); write_auth_response(AUTH_ERROR); } // Do some housekeeping clear_old_tokens(); // Even on STAGE_COUNTER, check token //if ($stage == STAGE_COUNTER) { // return; //} if (is_token_valid($token)) { write_auth_response(AUTH_ALLOWED); return; } write_auth_response(AUTH_DENIED); }
function make_token() { // Temporary: purge tokens more often // Tokens are cleared on GW communication, // but there is no gateway right now clear_old_tokens(); $db = Flight::db(); $token = generate_token(); $stmt = $db->prepare('INSERT INTO tokens (token) VALUES (:token)'); $stmt->bindParam(':token', $token); $stmt->execute(); return $token; }