コード例 #1
0
 public function resetPassword($username, $link)
 {
     $newHash = PasswordHelper::getInstance()->createUniqueHash();
     $admin = GenericDatabaseService::getInstance()->getSingle(new UserModel(), array("Username" => $username));
     if ($admin instanceof UserModel) {
         $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: "), LocaleService::getInstance()->translate("your password "));
     }
     return false;
 }
コード例 #2
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;
 }
コード例 #3
0
 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();
 }