Example #1
0
 public function getAbsoluteLink($relative)
 {
     $starts = array("http", "www");
     if (str_starts_with_any($relative, $starts)) {
         return $relative;
     }
     return RuntimeService::getInstance()->getRouteUrl() . "/" . $relative;
 }
Example #2
0
 public static function hi_framework($configFolders)
 {
     include_once __DIR__ . DIRECTORY_SEPARATOR . "phplibrary.php";
     SettingsService::getInstance()->addFolder($configFolders);
     RuntimeService::getInstance()->setFrameworkDirectory(__DIR__);
     $val = SettingsService::getInstance()->tryGetValueFor(array("Framework", "DebugMode"));
     if ($val === true) {
         error_reporting(E_ALL);
         ini_set('display_errors', 1);
     } else {
         error_reporting(0);
         ini_set('display_errors', 0);
     }
 }
Example #3
0
 public function __construct()
 {
     parent::__construct();
     //parse language resources
     if ($this->getConfig("DefaultLanguage") == null) {
         LogHelper::getInstance()->logWarning("Default language not configured, switching to first available language");
         $this->activeLangShort = $this->getConfig("LanguageResources")[0]["Language"];
     } else {
         $this->activeLangShort = $this->getConfig("DefaultLanguage");
     }
     foreach ($this->getConfig("LanguageResources") as $languageResource) {
         $this->languages[$languageResource["Language"]] = new Language($languageResource["Language"], $languageResource, RuntimeService::getInstance()->getLocaleDirectory());
     }
     if (isset($this->languages[$this->activeLangShort])) {
         $this->activeLang = $this->languages[$this->activeLangShort];
     } else {
         $this->activeLang = array_values($this->languages)[0];
         LogHelper::getInstance()->logError("Default language not found");
     }
     setlocale(LC_ALL, $this->activeLangShort . ".utf8");
 }
Example #4
0
    public function getFormStart($action = null, $ajax = true)
    {
        if ($action == null) {
            $action = RuntimeService::getInstance()->getTotalUrl();
        } else {
            $action = RouteService::getInstance()->getAbsoluteLink($action);
        }
        $classes = "";
        if (!$ajax) {
            $classes .= 'class="no-ajax"';
        }
        return '
<form ' . $classes . ' action="' . $action . '" method="post">' . $this->getFormToken($action);
    }
Example #5
0
 protected function exitWithControllerRedirect($relativeUrl)
 {
     $preUrl = $this->applicationConfig["Url"] . RuntimeService::getInstance()->getRouteUrl();
     header("HTTP/1.0 302 Found");
     header('Location: ' . $preUrl . "/" . $relativeUrl);
     exit;
 }
Example #6
0
            <div class="secondary-menu-items">
                <ul class="tiles">
                    <li>
                        <a class="tile float-right" href="logout">
                            <span class="flaticon-cancel22" aria-hidden="true"></span>Logout
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    <?php 
    }
    ?>

    <?php 
    if (count($this->getSubMenu()) > 0) {
        ?>
        <div class="submenu-items">
            <ul class="oneline-nav">
                <?php 
        foreach ($this->getSubMenu() as $menuEntry) {
            echo '<li ' . PartHelper::getInstance()->getClassesForMenuSubItem(RuntimeService::getInstance()->getControllerParams(), $menuEntry->getHref()) . '>
                            <a href="' . RuntimeService::getInstance()->getRouteUrl() . "/" . $menuEntry->getHref() . '">' . $menuEntry->getName() . '</a>
                      </li>';
        }
        ?>
            </ul>
        </div>
    <?php 
    }
}
 public function Display()
 {
     $user = $this->authService->getUser();
     if ($user !== false) {
         $this->exitWithControllerRedirect($this->loggedInRedirect);
     }
     if (count($this->params) == 0) {
         $view = new GenericCenterView("LoginController", "login", null, true);
         return $this->returnView($view);
     } else {
         if (count($this->params) > 0) {
             if ($this->params[0] == "login") {
                 if (isset($this->request["login"]) && $this->request["login"] == "true") {
                     //fill object
                     ReflectionHelper::getInstance()->writeFromPostArrayToObjectProperties($this->instance, $this->request);
                     $admin = GenericDatabaseService::getInstance()->getSingle($this->instance, array("Username" => $this->instance->getEmail()), true);
                     if ($admin instanceof LoginDatabaseModel && PasswordHelper::getInstance()->validatePasswort($this->instance->getPassword(), $admin->getPasswordHash())) {
                         AuthenticationService::getInstance()->setUser($admin);
                         $this->exitWithRedirect($this->loggedInRedirect);
                     } else {
                         LogHelper::getInstance()->logUserError("login unsuccessful!");
                         $this->instance->setPassword("");
                     }
                 }
                 $view = new GenericCenterView("LoginController", "login", null, true);
                 $view->assign("model", $this->instance);
                 return $this->returnView($view);
             } else {
                 if ($this->params[0] == "logout") {
                     $this->authService->setUser(null);
                     $this->exitWithControllerRedirect("/");
                 } else {
                     return parent::Display();
                 }
             }
         } else {
             if (count($this->params) > 1) {
                 if ($this->params[0] == "activateAccount" && PasswordHelper::getInstance()->checkIfHashIsValid($this->params[1])) {
                     $admin = GenericDatabaseService::getInstance()->getSingle($this->instance, array("AuthHash" => $this->params[1]), true);
                     if ($admin instanceof LoginDatabaseModel) {
                         if (isset($this->request["activateAccount"]) && $this->request["activateAccount"] == true) {
                             ReflectionHelper::getInstance()->writeFromPostArrayToObjectProperties($this->request, $admin);
                             if ($this->canSetPassword($admin)) {
                                 $admin->setPasswordHash(PasswordHelper::getInstance()->convertToPasswordHash($admin->getPassword()));
                                 $admin->setAuthHash("");
                                 GenericDatabaseService::getInstance()->update($admin, array("Id", "AuthHash", "PasswordHash"));
                             }
                         }
                         $view = new GenericCenterView("LoginController", "addpass", null, true);
                         return $this->returnView($view);
                     } else {
                         LogHelper::getInstance()->logUserInfo("link not valid anymore");
                         $view = new GenericCenterView("LoginController", "login", null, true);
                         return $this->returnView($view);
                     }
                 } else {
                     if ($this->params[0] == "forgotpass") {
                         if (isset($this->request["forgotpass"]) && $this->request["forgotpass"] == "true") {
                             $newHash = PasswordHelper::getInstance()->createUniqueHash();
                             $admin = GenericDatabaseService::getInstance()->getSingle($this->instance, array("Username" => $this->request["Username"]));
                             if ($admin instanceof LoginDatabaseModel) {
                                 $admin->setAuthHash($newHash);
                                 GenericDatabaseService::getInstance()->update($admin, array("Id", "AuthHash"));
                                 return EmailService::getInstance()->sendEmailFromServer(LocaleService::getInstance()->translate("password reset"), LocaleService::getInstance()->translate("your password was reset. click following link to set a new one: " . RuntimeService::getInstance()->getRouteUrl() . "/activateAccount/" . $newHash), $admin->getAuthHash());
                             }
                             LogHelper::getInstance()->logUserInfo("you will be contacted by us per email.");
                         }
                         $view = new GenericCenterView("LoginController", "forgotpass", null, true);
                         return $this->returnView($view);
                     }
                 }
             }
         }
     }
     return parent::Display();
 }
Example #8
0
// $_GET und $_POST zusammenfasen
$request = array_merge($_GET, $_POST);
$files = $_FILES;
include_once $_SERVER['DOCUMENT_ROOT'] . "/src/Framework/hook.php";
try {
    try {
        hi_framework();
        $controllerModel = RouteService::getInstance()->getController($_SERVER['REQUEST_URI']);
        RuntimeService::getInstance()->setParams($_SERVER['REQUEST_URI'], $controllerModel);
        RuntimeService::getInstance()->setParams($_SERVER['REQUEST_URI'], $controllerModel);
        if ($controllerModel instanceof ControllerModel) {
            $controllerName = $controllerModel->getController();
            $controller = new $controllerName($request, RuntimeService::getInstance()->getControllerParams(), $files);
            $output = $controller->Display();
            echo $output;
            bye_framework();
        } else {
            $controller = new FrameworkController($request, RuntimeService::getInstance()->getControllerParams(), $files);
            $output = $controller->Display(FrameworkController::CONTROLLER_NOT_FOUND);
            echo $output;
            bye_framework();
        }
    } catch (Exception $ex) {
        LogHelper::getInstance()->logException($ex);
        bye_framework(false);
    }
} catch (Exception $ex) {
    //this will never ever happen!
    echo $ex;
    bye_framework();
}