// Register autoloader and instantiate Slim \Slim\Slim::registerAutoloader(); $app = new \Slim\Slim(); // Database Configuration $dbhost = 'localhost'; $dbuser = '******'; $dbpass = '******'; // $dbname = 'naiemoji'; $dbname = 'testorm'; $dbmethod = 'mysql:dbname='; $dsn = $dbmethod . $dbname; $pdo = new PDO($dsn, $dbuser, $dbpass); $db = new NotORM($pdo); // Home Route $app->get('/', function () use($app) { $app->response->setStatus(200); $app->render('../templates/homepage.html'); }); // Register a user $app->post('/register', function () use($app, $db) { $app->response()->header('Content-Type', 'application/json'); $name = $app->request()->post('name'); $email = $app->request()->post('email'); $password = $app->request()->post('password'); $passwordEncryption = md5($password); if ($email === $db->users()->where('email', $email)->fetch('email')) { echo json_encode(['message' => 'That email address is already in use. Please use another email address']); } else { $user = ['name' => "{$name}", 'email' => "{$email}", 'password' => "{$passwordEncryption}"]; $result = $db->users->insert($user); $users = array(); foreach ($db->users() as $user) {
$directory = get_template_directory() . "/app"; $assets = get_template_directory_uri(); $loader = new Twig_Loader_Filesystem($directory); $twig = new Twig_Environment($loader); $twig->addExtension(new Twig_Extensions_Extension_I18n()); // here I can use MongoDB if i want to. very flexible. $mongo = new MongoClient("mongodb://localhost/?journal=true&w=1&wTimeoutMS=20000"); $mongodb = $mongo->react_blog; $MongoUser = $mongodb->users; $app = new \Slim\Slim(); $app->add(new \Slim\Middleware\SessionCookie(array('expires' => '20 minutes', 'path' => '/', 'domain' => null, 'secure' => false, 'httponly' => false, 'name' => 'slimblog_dev_session', 'secret' => 'YOU_ARE_SUCH_A_COOL_KID', 'cipher' => MCRYPT_RIJNDAEL_256, 'cipher_mode' => MCRYPT_MODE_CBC, 'date.timezone' => 'UTC'))); $app->add(new CsrfGuard()); $app->get('/', function () use($app, $twig, $assets) { $data = array('user' => 'testuser', 'test' => 'hahahahha', 'static_url' => $assets); if (isset($_SESSION['app_id'])) { echo $twig->render('views/index.php', $data); } else { echo "You gonna login first"; } }); $app->get('/app', function () use($app, $twig, $assets) { $data = array('user' => 'testuser', 'test' => 'hahahahha', 'static_url' => $assets); if (isset($_SESSION['app_id'])) { echo $twig->render('views/index.php', $data); } else { echo "You gonna login first bro"; } }); $app->get('/app/login', function () use($app, $twig, $assets) { $request = $app->request(); $action = $request->params('action'); $data = array('user' => 'testuser', 'test' => 'hahahahha', 'static_url' => $assets, 'action' => $action, 'csrf_key' => $app->view()->getData('csrf_key'), 'csrf_token' => $app->view()->getData('csrf_token'));
$collection->attachRoute(new Route('/calendarAction', array('_controller' => 'PaymentController::listPaymentsOnCalendarAction', 'methods' => 'POST'))); $router = new Router($collection); $router->setBasePath('/'); $route = $router->matchCurrentRequest(); // Vamos a usar el PHPRouter para todas las rutas relacionadas a la pagina de la escuela, // y Slim para todas las rutas de la api REST. // Asique si al llegar una ruta vemos que no pertenece al mapeo de PHPRouter, usamos slim. if ($route) { AuthController::checkPermission($route->getAction()); $route->dispatch(); } else { $slimApp = new \Slim\Slim(); // Retorna un arreglo asociativo con las claves "por_pagar" y "pagas". // Cada arreglo dentro de esas 2 cosas contiene los datos de un alumno // http://localhost/cuotasImpagasYPorPagarDe/21/year/2016 << este tiene datos cargados para ver $slimApp->get('/cuotasImpagasYPorPagarDe/:studentID/year/:year', function ($studentID, $year) { FeeService::listPaidAndToBePaidFeesOfStudentInYear($studentID, $year); }); // Devuelve un arreglo de 12 posiciones, cada posicion representa un mes, y contiene la cantidad de ingresos // en ese mes. $slimApp->get('/ingresosTotalesEn/:year', function ($year) { RevenueService::totalRevenueByMonthInYear($year); }); $slimApp->get('/getUsersPosition', function () { //$positions = [[-57.9749, -34.9205], [-57.9799, -34.9305]]; //echo json_encode($positions); StudentService::getStudentsPositions(); }); // Si slim detecta q la ruta no existe, se va a encargar de retornar el codigo de error y lo q necesite. $slimApp->run(); }
<?php require "vendor/autoload.php"; use Slim\Slim; use Slim\Extras\Views\Twig; $log = new Monolog\Logger('log'); $log->pushHandler(new Monolog\Handler\StreamHandler('log/wol.log', Monolog\Logger::INFO)); $app = new \Slim\Slim(['view' => new Twig(), 'templates.path' => 'template']); // // request // $app->get("/", function () use($app, $log) { require_once 'app/models/WakeUpLanManager.php'; $wol = new WakeUpLanManager($log); echo $app->render('index.html', ['wol_list' => $wol->getWolJson()]); }); $app->get("/wakeup/:id", function ($id) use($app, $log) { $log->info('START'); require_once 'app/models/WakeUpLanManager.php'; $wol = new WakeUpLanManager($log); // WOL実行 $result = $wol->postWol($id, $wol->getWolJson()); $app->response->headers->set('Content-Type', 'application/json'); $app->response->setBody(json_encode(['result' => 'ok'])); }); $app->get("/ping/:id", function ($id = null) use($app, $log) { $log->info('START'); require_once 'app/models/WakeUpLanManager.php'; $wol = new WakeUpLanManager($log); /// ping チェック if (empty($id)) {
$formResult = $formController->parse($entityBody); $formResult->setLogger($log); //form has updated mappings for each question $candidate = new Stratum\Model\Candidate(); $candidate->setLogger($log); $log->debug("parsed input data"); $candidateController = new Stratum\Controller\CandidateController(); $candidateController->setLogger($log); $candidate = $candidateController->populate($candidate, $formResult); $log->debug("Candidate submitted with name " . $candidate->getName()); $controller = new Stratum\Controller\BullhornController(); $controller->setLogger($log); $controller->submit($candidate); }); $app->get('/launch', function () use($app) { $app->redirect('http://northcreek.ca/stratum/launch.html'); }); $app->get('/launchForm', function (Request $request, Response $response) use($log) { // this is all the happy path assuming everything is set up properly from the Bullhorn side //load the id from the request $id = $request->getAttribute('entityid'); //set up the controllers and their loggers $wcontroller = new \Stratum\Controller\WorldappController(); $bcontroller = new \Stratum\Controller\BullhornController(); $bcontroller->setLogger($log); $wcontroller->setLogger($log); //find the correct form $form = $wcontroller->find_form_by_name('Registration Form - Stratum International'); //load the candidate data from Bullhorn $candidate = new Stratum\Model\Candidate(); $candidate->set("id", $id);
$app->configureMode('production', function () use($app) { $app->config(array('log.enable' => true, 'debug' => false)); $handle = fopen('debug.log', 'w'); $app->log->setWriter(new \Slim\LogWriter($handle)); }); // Only invoked if mode is "development" $app->configureMode('development', function () use($app) { $app->config(array('log.enable' => false, 'debug' => true)); }); /** * Perform an API get status * This is not much than a ping on the API server */ $app->get('/status', function () { $response['status'] = 'ok'; echoRespnse(200, $response); exit; }); /** * Try to perform a user log in * If the user is authenticated, then start the session cookie */ $app->post('/login', function () use($app) { // check for required params verify_required_params(array('email', 'password')); // reading post params $email = $app->request()->post('email'); $password = $app->request()->post('password'); $response = array('request' => 'login'); // Sanitize data $email = filter_var($email, FILTER_SANITIZE_EMAIL);
$app->configureMode('production', function () use($app) { $app->config(array('log.enable' => true, 'debug' => false)); $handle = fopen('debug.log', 'w'); $app->log->setWriter(new \Slim\LogWriter($handle)); }); // Only invoked if mode is "development" $app->configureMode('development', function () use($app) { $app->config(array('log.enable' => false, 'debug' => true)); }); /** * Perform an API get status * This is not much than a ping on the API server */ $app->get('/status', function () { $response['status'] = 'ok'; echoRespnse(200, $response); exit; }); /** * Try to perform a user log in * If the user is authenticated, then start the session cookie */ $app->post('/login', function () use($app) { // Dev only // Sleep 3 seconds before processing the request // to display the loader sleep(1); // check for required params verify_required_params(array('email', 'password')); // reading post params $email = $app->request()->post('email');