function get_user($netid) { $q = new UserQuery(); $user = $q->findOneByNetid($netid); // The user exists in the database if ($user) { return $user; } else { // We need to build it. $netid_info = netid_info($netid); if ($netid_info) { if (array_key_exists("givenname", $netid_info)) { $name = $netid_info["givenname"]["0"] . " " . $netid_info["sn"]["0"]; } else { // User has no name in LDAP, set their name to their netid. $name = $netid; } $year = array_key_exists("ou", $netid_info) ? $netid_info["ou"]["0"] : false; $user = new User(); $user->setNetid($netid); if ($year) { $user->setYear($year); } if ($name) { $user->setName($name); } $user->save(); return $user; } else { // User doesn't exist in ldap either return false; } } }
} require_authenticated($who); // Pass $who as a parameter so it doesn't need to be requested again. if (array_key_exists("user", $who)) { if ($who['user']['IsAdmin']) { return true; } } // If any of those if statements above fail, and the function does not return, the user must not be an admin. $app = \Slim\Slim::getInstance(); $app->response->setStatus(401); render_json(array("error" => true, "message" => "Endpoint is for administrators only.")); return false; } $app->get('/netid-info/:netid', function ($netid) use($app) { render_json(netid_info($netid)); }); $app->get('/netid-db/:netid', function ($netid) use($app) { render_json_string(get_user($netid)->toJSON()); }); $app->get('/signin/:netid/:reason', function ($netid, $reason) use($app) { $result = signin_netid($netid, $reason); render_json($result); }); $app->group('/signins', function () use($app) { $app->get('/today', function () use($app) { render_json(signins_today()); }); $app->get('/all', function () use($app) { if (!require_admin()) { return;