public function __construct(BaseDatabaseModel $model, $friendlyName, $controllerLink = null)
 {
     $this->instance = $model;
     $this->name = ReflectionHelper::getInstance()->getObjectName($model);
     $this->friendlyName = $friendlyName;
     //set defaults
     $this->listName = $friendlyName;
     if ($controllerLink == null) {
         $this->controllerLink = strtolower($friendlyName . "s");
     } else {
         $this->controllerLink = $controllerLink;
     }
 }
Example #2
0
 private function getPropertyName($obj, $prop)
 {
     $modelName = ReflectionHelper::getInstance()->getObjectName($obj);
     return $modelName . "[" . $prop . "]";
 }
Example #3
0
 private function fillInstancesWithPassedId($id)
 {
     $mainObj = GenericDatabaseService::getInstance()->getById($this->getEditObjects()[0]->getInstance(), $id);
     if ($mainObj !== false) {
         $this->getEditObjects()[0]->setInstance($mainObj);
         //get all other models
         for ($i = 1; $i < count($this->getEditObjects()); $i++) {
             $newId = ReflectionHelper::getInstance()->getPropertyOfObjects($this->getEditObjects(), $this->getEditObjects()[$i]->getName() . "Id", 0, $i);
             if ($newId != null) {
                 $this->getEditObjects()[$i]->setInstance(GenericDatabaseService::getInstance()->getById($this->getEditObjects()[$i]->getInstance(), $newId));
             } else {
                 LogHelper::getInstance()->logError("can't find the id of " . $this->getEditObjects()[$i]->getFriendlyName());
                 return false;
             }
         }
         return true;
     }
     return false;
 }
 private function addRelationsToSingle(BaseDatabaseModel $model)
 {
     foreach ($model->getDatabaseArray() as $key => $val) {
         if (strpos($key, "Id") !== false) {
             if ($val > 0) {
                 $objectName = str_replace("Id", "", $key);
                 $fullObjectName = ReflectionHelper::getInstance()->getNamespace($model) . "\\" . $objectName;
                 $obj = new $fullObjectName();
                 $relationObj = $this->GetById($obj, $val, false);
                 if ($relationObj !== false) {
                     $secMethod = "set" . $objectName;
                     $obj->{$secMethod}($relationObj);
                 }
             }
         }
     }
 }
Example #5
0
 private function doLog($level, $message, $object = null)
 {
     $source = ReflectionHelper::getInstance()->getCallStack();
     $addMessage = ReflectionHelper::getInstance()->getObjectAsJson($object);
     if ($addMessage != "") {
         $addMessage = " passed object: " . $addMessage;
     }
     $logItem = new LogItem($source, $level, $message . $addMessage);
     $this->addLogItem($logItem);
 }
 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();
 }