示例#1
0
 /**
  * Adds a backend routes
  * @param $appInstance
  * @return void
  */
 public static function addRouteDefinitions(Slim $appInstance)
 {
     $appInstance->group('/admin', function () use($appInstance) {
         $appInstance->get('/', function () {
             print '<h1>A Simple Backend</h1>';
         });
         $appInstance->map("/chpass", function () use($appInstance) {
             if (EMA_ADMIN_CHPASS) {
                 AdminPasswordChange_controller::process();
             } else {
                 $appInstance->pass();
             }
         })->via('GET', 'POST');
         $appInstance->map("/update", function () use($appInstance) {
             ClassAndMethodsDispatcher::updateGPMethods();
         })->via('GET', 'POST');
         $appInstance->post("/login", function () use($appInstance) {
             $appInstance->response->headers->set('Cache-Control', 'no-store');
             if (isset($_POST['username']) && is_string($_POST['username']) && (isset($_POST['password']) && is_string($_POST['password']))) {
                 try {
                     try {
                         $user = new UserAuth();
                     } catch (SessionExpired $e) {
                         $user = new UserAuth();
                     }
                     $user->userLogin($_POST['username'], $_POST['password']);
                     if (!$user->isAdmin()) {
                         $user->logout();
                         throw new LoginIncorrect('You are not allowed to login here');
                     }
                     $appInstance->response->headers->set('Content-Type', 'application/json');
                     print json_encode($user->getSessionAuthData());
                 } catch (LoginIncorrect $e) {
                     $appInstance->response->headers->set('Content-Type', 'text/plain');
                     $appInstance->response->setStatus(400);
                     print $e->getMessage();
                 }
             } else {
                 $appInstance->response->headers->set('Content-Type', 'text/plain');
                 $appInstance->response->setStatus(400);
                 print 'Bad request';
             }
         });
         $appInstance->map('/logout', function () use($appInstance) {
             try {
                 $user = new UserAuth();
                 if ($user->isUserLoggedInSimple()) {
                     $user->logout();
                 }
             } catch (SessionExpired $e) {
             }
         })->via('GET', 'POST');
     });
 }
示例#2
0
     } else {
         throw new Exception("Error Processing Request, argument is not a string.", 6004);
     }
 }
 /** Register EMA autoloader */
 spl_autoload_register('emaAutoloader', true);
 /** Instantiate AppConfig */
 if (USE_APP_CONFIG) {
     $GLOBALS['EMA']['config'] = new \ema\engine\AppConfig();
 }
 if (EMA_SKIP_ROUTES_LOADING === false) {
     /** Instance slim application */
     $GLOBALS['EMA']['slim'] = new \Slim\Slim();
     if (UPDATE_AUTOLOADER) {
         \ema\engine\ClassAndMethodsDispatcher::updateInterfacesImplementation();
         \ema\engine\ClassAndMethodsDispatcher::updateGPMethods();
     }
     /** Loading routes */
     $routeLoader = $GLOBALS['EMA']['DB']['connection']->select(AUTOLOADER_TABLE, array("loader", "className"), array('AND' => array('active' => 1, 'router' => 1)));
     if (!empty($routeLoader)) {
         foreach ($routeLoader as $value) {
             require_once $GLOBALS['EMA']['system_path'] . $value['loader'];
             $value['className']::addRouteDefinitions($GLOBALS['EMA']['slim']);
         }
     }
     unset($routeLoader, $value);
     $GLOBALS['EMA']['slim']->add(new \ema\engine\ContentLengthMiddleware());
     if (EMA_DEBUG && EMA_PRINT_STATISTICS) {
         $GLOBALS['EMA']['slim']->add(new \ema\engine\StatisticsMiddleware());
     }
     // Only invoked if mode is "production"