/**
  * Logs video download requests
  * @param MembersAuth $membersAuth
  * @param $inst
  * @param $id
  * @param $accessMethod
  */
 public function logVideoRequest(MembersAuth $membersAuth)
 {
     $inst = mb_strtolower($this->classInst);
     $accessMethod = mb_strtolower($this->accessMethod);
     if ($inst === 'video' && $accessMethod === 'private' && $this->isLogable() && $membersAuth->isMember()) {
         $logger = new VideoDownloads();
         $logger->write($this->id, $this->chrootPath, $membersAuth->getLoginID(), array_key_exists('download', $_REQUEST));
     }
 }
 /**
  * This methods will be called at application startup
  * @param $appInstance
  * @return void
  * @throws \Exception
  */
 public static function addRouteDefinitions(Slim $appInstance)
 {
     $appInstance->map('/protected-storage/:inst/:id/:accessMethod/:path+', function ($inst, $id, $accessMethod, $path) use($appInstance) {
         if (!in_array($accessMethod, cProtectedStorage::$allowedAccessMethods, true)) {
             $appInstance->halt(400, 'Invalid request');
         }
         $fileName = array_pop($path);
         $rel = '';
         foreach ($path as $value) {
             $rel .= $value . '/';
         }
         $rel .= $fileName;
         $user = null;
         if ($accessMethod === 'private') {
             try {
                 $user = new MembersAuth();
                 $user->isUserLoggedIn();
             } catch (LoginExceptions $e) {
                 $appInstance->halt(401, 'Unauthorized');
             }
         }
         $fullPath = $inst . '/' . $id . '/' . $accessMethod . '/' . $rel;
         $controller = new cProtectedStorage($inst, $id, $accessMethod, $rel);
         if ($controller->isCorrectPath($fullPath)) {
             $appInstance->etag(md5($fullPath));
             $appInstance->expires('+1 week');
             $headers = $controller->outputFile();
             if (array_key_exists('download', $_REQUEST)) {
                 $headers['Content-Type'] = 'application/octet-stream';
             }
             foreach ($headers as $key => $value) {
                 $appInstance->response->headers->set($key, $value);
             }
         } else {
             $appInstance->notFound();
         }
     })->via('GET', 'POST');
 }
 /**
  * This methods will be called at application startup
  * @param $appInstance
  * @return void
  */
 public static function addRouteDefinitions(Slim $appInstance)
 {
     $appInstance->get('/', function () {
         print '<h1>A simple frontend</h1>';
     });
     $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 MembersAuth();
                 } catch (SessionExpired $e) {
                     $user = new MembersAuth();
                 }
                 $user->userLogin($_POST['username'], $_POST['password']);
                 $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 MembersAuth();
             if ($user->isUserLoggedInSimple()) {
                 $user->logout();
             }
         } catch (SessionExpired $e) {
         }
     })->via('GET', 'POST');
 }