public function update(BaseDatabaseModel $model, array $allowedArr = null)
 {
     $arr = $model->getDatabaseArray();
     $arr["ChangeDateTime"] = FormatHelper::getInstance()->dateTimeFromString("now");
     $arr["ChangedById"] = AuthenticationService::getInstance()->getUser()->getId();
     $table = $this->getTableName($model);
     $arr = $this->cleanUpGenericArray($arr);
     $params = $arr;
     if (is_array($allowedArr)) {
         $params = array();
         foreach ($allowedArr as $item) {
             $params[$item] = $arr[$item];
         }
     }
     if (!isset($arr["Id"]) || $arr["Id"] == 0) {
         return false;
     } else {
         return $this->updateInternal($table, $params);
     }
 }
 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();
 }