From b32540971288c1c95139d65e75c72c1e456c9337 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 21 Jun 2008 13:58:21 +0000 Subject: [PATCH] Account status page partly implemented, backtrace now without own saveBacktrace() call --- .gitattributes | 1 + application/ship-simu/config.php | 2 +- .../templates/de/code/login_form.ctp | 2 - .../templates/de/code/login_profile.ctp | 3 +- .../de/code/login_status_problem.ctp | 63 +++++++ .../templates/de/code/register_form.ctp | 1 - .../exceptions/class_FrameworkException.php | 7 + .../main/class_BaseFrameworkSystem.php | 170 ++++++++++++------ .../main/debug/class_DebugWebOutput.php | 2 +- .../main/helper/web/class_WebFormHelper.php | 42 ++++- .../main/template/class_TemplateEngine.php | 24 +-- .../debug/class_DebugMiddleware.php | 4 +- 12 files changed, 244 insertions(+), 77 deletions(-) create mode 100644 application/ship-simu/templates/de/code/login_status_problem.ctp diff --git a/.gitattributes b/.gitattributes index 090307a..dba150e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -142,6 +142,7 @@ application/ship-simu/templates/de/code/login_form.ctp -text application/ship-simu/templates/de/code/login_logout.ctp -text application/ship-simu/templates/de/code/login_main.ctp -text application/ship-simu/templates/de/code/login_profile.ctp -text +application/ship-simu/templates/de/code/login_status_problem.ctp -text application/ship-simu/templates/de/code/login_welcome.ctp -text application/ship-simu/templates/de/code/logout_done.ctp -text application/ship-simu/templates/de/code/register_form.ctp -text diff --git a/application/ship-simu/config.php b/application/ship-simu/config.php index 26e173d..b373a1b 100644 --- a/application/ship-simu/config.php +++ b/application/ship-simu/config.php @@ -101,7 +101,7 @@ $cfg->setConfigEntry('login_failed_url', "index.php?app=ship-simu&page=login_fai $cfg->setConfigEntry('logout_done_url', "index.php?app=ship-simu&page=logout_done"); // CFG: LOGIN-USER-STATUS-URL -$cfg->setConfigEntry('login_user_status_url', "index.php?app=ship-simu&page=login_area&action=login_status_problem"); +$cfg->setConfigEntry('login_user_status_url', "index.php?app=ship-simu&page=login_area&action=status_problem"); // CFG: LOGIN-DEFAULT-ACTION $cfg->setConfigEntry('login_default_action', "welcome"); diff --git a/application/ship-simu/templates/de/code/login_form.ctp b/application/ship-simu/templates/de/code/login_form.ctp index d890f18..31688cc 100644 --- a/application/ship-simu/templates/de/code/login_form.ctp +++ b/application/ship-simu/templates/de/code/login_form.ctp @@ -40,7 +40,6 @@ if ($helper->ifLoginIsEnabled()) { } // Formular schliessen -$helper->addFormTag(); $helper->flushContent(); // Ist Gastlogin erlaubt? @@ -51,7 +50,6 @@ if ($helper->ifGuestLoginAllowed()) { $helper->addInputHiddenField("pass", $this->getConfigInstance()->readConfig('guest_login_password')); $helper->addFormGroup("buttons", "Gastlogins sind in der Funkionsweise eingeschränkt. Mehr dazu unter "Gastlogin"."); $helper->addInputSubmitButton("Als Gast einloggen"); - $helper->addFormTag(); $helper->flushContent(); } diff --git a/application/ship-simu/templates/de/code/login_profile.ctp b/application/ship-simu/templates/de/code/login_profile.ctp index c74c749..f79bbaa 100644 --- a/application/ship-simu/templates/de/code/login_profile.ctp +++ b/application/ship-simu/templates/de/code/login_profile.ctp @@ -106,11 +106,10 @@ $helper->addFormGroup("buttons", "Sind alle Daten nun korrekt eingegeben? Dann s $helper->addInputResetButton("Alles nochmal eingeben"); $helper->addInputSubmitButton("Accountdaten aktualisieren"); $helper->addFormNote("Deine Daten werden nach den gültigen Datenschutzgesetzten gespeichert und werden nicht an Dritte weitergegeben. Weiteres dazu siehe Link "Datenschutz"."); -$helper->addFormTag(); $helper->flushContent(); ?>
- Ihre Profildaten bearbeiten + Deine Profildaten bearbeiten
diff --git a/application/ship-simu/templates/de/code/login_status_problem.ctp b/application/ship-simu/templates/de/code/login_status_problem.ctp new file mode 100644 index 0000000..9738a23 --- /dev/null +++ b/application/ship-simu/templates/de/code/login_status_problem.ctp @@ -0,0 +1,63 @@ +prefetchFieldValues('user'); + +// Add submit button or notice +if ($helper->ifUserAccountUnconfirmed()) { + $helper->addInputSubmitButton("Bestätigungslink erneut aussenden"); +} elseif ($helper->ifUserAccountLocked()) { + $helper->addFormNote("Dein Account wurde gesperrt! Grund der Sperre: + ".$helper->getField('lock_reason')." + Bitte melde dich beim Support, damit dieser dir weiterhelfen kann." + ); +} elseif ($helper->ifUserAccountGuest()) { + $helper->addFormNote("Gästeaccounts sind in der Funktionalität + leicht eingeschränkt. Bitte melde dich an, damit du ein + vollwertiges Account bekommst." + ); +} + +// Flush content and automatically close the form +$helper->flushContent(); + +if ($helper->ifUserAccountUnconfirmed()) { + // Build the form for confirmation + $helper = WebFormHelper::createWebFormHelper($this, "confirm_code"); + + // Add code box + $helper->addFormGroup("code", "Bitte gebe hier den Bestätigungscode aus der Willkommensemail ein. Solltest du diese nicht erhalten haben, kannst du dir diesen jetzt zusenden lassen."); + $helper->addFieldText("code", "Bestätigungscode aus der Mail:"); + $helper->addInputTextField("code"); + + // Add submit button + $helper->addFormGroup("submit", "Bitte einmal abschicken und das Ergebnis abwarten!"); + $helper->addInputResetButton("Nochmal eingeben"); + $helper->addInputSubmitButton("Bestätigungscode zusenden"); + + // Flush content and automatically close the form + $helper->flushContent(); +} // END - if +?> +
+ Problem mit deinem Account gefunden: +
+ +
+ Du bist möglicherweise für deine ausgewählte Aktion nicht + berechtigt oder du hast noch deine Email-Adresse nicht bestätigt. Du + kannst dir nun den Bestätigungslink erneut aussenden lassen, oder den + Bestätigungscode unten eingeben. + + + +
+ {?confirm_code?} +
+
diff --git a/application/ship-simu/templates/de/code/register_form.ctp b/application/ship-simu/templates/de/code/register_form.ctp index 9f427c2..a2221fa 100644 --- a/application/ship-simu/templates/de/code/register_form.ctp +++ b/application/ship-simu/templates/de/code/register_form.ctp @@ -97,7 +97,6 @@ $helper->addFormGroup("buttons", "Wenn du alle benötigten Felder korrekt au $helper->addInputResetButton("Alles nochmal eingeben"); $helper->addInputSubmitButton("Anmeldung zum Spiel abschliessen"); $helper->addFormNote("Deine Daten werden nach den gültigen Datenschutzgesetzten gespeichert und werden nicht an Dritte weitergegeben. Weiteres dazu siehe Link "Datenschutz"."); -$helper->addFormTag(); $helper->flushContent(); ?>
diff --git a/inc/classes/exceptions/class_FrameworkException.php b/inc/classes/exceptions/class_FrameworkException.php index e74dd5a..34e4802 100644 --- a/inc/classes/exceptions/class_FrameworkException.php +++ b/inc/classes/exceptions/class_FrameworkException.php @@ -54,7 +54,14 @@ abstract class FrameworkException extends ReflectionException { * @return void */ private final function saveBackTrace () { + // Get full backtrace $this->backTrace = debug_backtrace(); + + // Remove this call + $dummy = array_shift($this->backTrace); + + // resort the array + ksort($this->backTrace); } /** diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index a828dc7..48d9e3a 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -33,6 +33,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ private static $langInstance = null; + /** + * Debug instance + */ + private static $debugInstance = null; + /** * Instance of a request class */ @@ -307,6 +312,44 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { } } + /** + * Setter for search instance + * + * @param $searchInstance Searchable criteria instance + * @return void + */ + public final function setSearchInstance (LocalSearchCriteria $searchInstance) { + $this->searchInstance = $searchInstance; + } + + /** + * Getter for search instance + * + * @return $searchInstance Searchable criteria instance + */ + public final function getSearchInstance () { + return $this->searchInstance; + } + + /** + * Setter for resolver instance + * + * @param $resolverInstance Instance of a command resolver class + * @return void + */ + public final function setResolverInstance (Resolver $resolverInstance) { + $this->resolverInstance = $resolverInstance; + } + + /** + * Getter for resolver instance + * + * @return $resolverInstance Instance of a command resolver class + */ + public final function getResolverInstance () { + return $this->resolverInstance; + } + /** * Setter for language instance * @@ -321,29 +364,30 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { /** * Getter for configuration instance * - * @return $cfhInstance - Configuration instance + * @return $cfgInstance Configuration instance */ protected final function getConfigInstance () { - return Registry::getRegistry()->getInstance('config'); + $cfgInstance = Registry::getRegistry()->getInstance('config'); + return $cfgInstance; } /** * Setter for debug instance * - * @param $debugInstance The instance for debug output class + * @param $debugInstance The instance for debug output class * @return void */ public final function setDebugInstance (DebugMiddleware $debugInstance) { - Registry::getRegistry()->addInstance('debug', $debugInstance); + self::$debugInstance = $debugInstance; } /** * Getter for debug instance * - * @return $debug - Instance to class DebugConsoleOutput or DebugWebOutput + * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput */ public final function getDebugInstance () { - return Registry::getRegistry()->getInstance('debug'); + return self::$debugInstance; } /** @@ -941,29 +985,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { } } - /** - * Converts e.g. a command from URL to a valid class by keeping out bad characters - * - * @param $str The string, what ever it is needs to be converted - * @return $className Generated class name - */ - public function convertToClassName ($str) { - // Init class name - $className = ""; - - // Convert all dashes in underscores - $str = str_replace("-", "_", $str); - - // Now use that underscores to get classname parts for hungarian style - foreach (explode("_", $str) as $strPart) { - // Make the class name part lower case and first upper case - $className .= ucfirst(strtolower($strPart)); - } // END - foreach - - // Return class name - return $className; - } - /** * Outputs a debug backtrace and stops further script execution * @@ -978,41 +999,88 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { } /** - * Setter for search instance + * Outputs a debug message wether to debug instance (should be set!) or dies with or pints the message * - * @param $searchInstance Searchable criteria instance + * @param $message Message we shall send out... + * @param $doPrint Wether we shall print or die here which last is the default * @return void */ - public final function setSearchInstance (LocalSearchCriteria $searchInstance) { - $this->searchInstance = $searchInstance; - } + public function debugOutput ($message, $doPrint = false) { + // Get debug instance + $debugInstance = $this->getDebugInstance(); - /** - * Getter for search instance - * - * @return $searchInstance Searchable criteria instance - */ - public final function getSearchInstance () { - return $this->searchInstance; + // Is the debug instance there? + if (is_object($debugInstance)) { + // Use debug output handler + $debugInstance->output($message); + if (!$doPrint) die(); // Die here if not printed + } else { + // Put directly out + // DO NOT REWRITE THIS TO app_die() !!! + if ($doPrint) { + print($message); + } else { + die($message); + } + } } /** - * Setter for resolver instance + * Converts e.g. a command from URL to a valid class by keeping out bad characters * - * @param $resolverInstance Instance of a command resolver class - * @return void + * @param $str The string, what ever it is needs to be converted + * @return $className Generated class name */ - public final function setResolverInstance (Resolver $resolverInstance) { - $this->resolverInstance = $resolverInstance; + public function convertToClassName ($str) { + // Init class name + $className = ""; + + // Convert all dashes in underscores + $str = str_replace("-", "_", $str); + + // Now use that underscores to get classname parts for hungarian style + foreach (explode("_", $str) as $strPart) { + // Make the class name part lower case and first upper case + $className .= ucfirst(strtolower($strPart)); + } // END - foreach + + // Return class name + return $className; } /** - * Getter for resolver instance + * Marks up the code by adding e.g. line numbers * - * @return $resolverInstance Instance of a command resolver class - */ - public final function getResolverInstance () { - return $this->resolverInstance; + * @param $phpCode Unmarked PHP code + * @return $markedCode Marked PHP code + */ + public function markupCode ($phpCode) { + // Get last error + $errorArray = error_get_last(); + + // Init the code with error message + $markedCode = ""; + if (is_array($errorArray)) { + // Get error infos + $markedCode = sprintf("
File: %s, Line: %s, Message: %s, Type: %s
", + basename($errorArray['file']), + $errorArray['line'], + $errorArray['message'], + $errorArray['type'] + ); + } // END - if + + // Add line number to the code + foreach (explode("\n", $phpCode) as $lineNo=>$code) { + // Add line numbers + $markedCode .= sprintf("%s: %s\n", + ($lineNo+1), + htmlentities($code, ENT_QUOTES) + ); + } // END - foreach + + // Return the code + return $markedCode; } } diff --git a/inc/classes/main/debug/class_DebugWebOutput.php b/inc/classes/main/debug/class_DebugWebOutput.php index 81dd64d..48c9aad 100644 --- a/inc/classes/main/debug/class_DebugWebOutput.php +++ b/inc/classes/main/debug/class_DebugWebOutput.php @@ -58,7 +58,7 @@ class DebugWebOutput extends BaseFrameworkSystem implements Debugger, OutputStre * @return void */ public final function outputStream ($output) { - trigger_error($output); + print($output); } /** diff --git a/inc/classes/main/helper/web/class_WebFormHelper.php b/inc/classes/main/helper/web/class_WebFormHelper.php index 1369fe4..6457409 100644 --- a/inc/classes/main/helper/web/class_WebFormHelper.php +++ b/inc/classes/main/helper/web/class_WebFormHelper.php @@ -200,7 +200,7 @@ class WebFormHelper extends BaseHelper { } // END - if // Generate the content - $inputContent = sprintf("", + $inputContent = sprintf("", $fieldName, $fieldName, $fieldValue @@ -242,7 +242,7 @@ class WebFormHelper extends BaseHelper { } // END - if // Generate the content - $inputContent = sprintf("", + $inputContent = sprintf("", $fieldName, $fieldName, $fieldValue @@ -299,7 +299,7 @@ class WebFormHelper extends BaseHelper { if ($fieldChecked === false) $checked = " "; // Generate the content - $inputContent = sprintf("", + $inputContent = sprintf("", $fieldName, $fieldName, $checked @@ -675,9 +675,39 @@ class WebFormHelper extends BaseHelper { return $emailChange; } + /** + * Checks wether the user account is unconfirmed + * + * @return $isUnconfirmed Wether the user account is unconfirmed + */ + public function ifUserAccountUnconfirmed () { + $isUnconfirmed = ($this->getField('user_status') === $this->getConfigInstance()->readConfig('user_status_unconfirmed')); + return $isUnconfirmed; + } + + /** + * Checks wether the user account is locked + * + * @return $isUnconfirmed Wether the user account is locked + */ + public function ifUserAccountLocked () { + $isUnconfirmed = ($this->getField('user_status') === $this->getConfigInstance()->readConfig('user_status_locked')); + return $isUnconfirmed; + } + + /** + * Checks wether the user account is a guest + * + * @return $isUnconfirmed Wether the user account is a guest + */ + public function ifUserAccountGuest () { + $isUnconfirmed = ($this->getField('user_status') === $this->getConfigInstance()->readConfig('user_status_guest')); + return $isUnconfirmed; + } + /** * Flushs the content out (not yet secured against open forms, etc.!) or - * throw an exception if it is not yet closed + * close the form automatically * * @return void * @throws FormOpenedException If the form is still open @@ -685,8 +715,8 @@ class WebFormHelper extends BaseHelper { public function flushContent () { // Is the form still open? if ($this->formOpened === true) { - // Throw an exception - throw new FormOpenedException ($this, self::EXCEPTION_OPENED_FORM); + // Close the form automatically + $this->addFormTag(); } // END - if // Send content to template engine diff --git a/inc/classes/main/template/class_TemplateEngine.php b/inc/classes/main/template/class_TemplateEngine.php index 2a828c0..a9b4574 100644 --- a/inc/classes/main/template/class_TemplateEngine.php +++ b/inc/classes/main/template/class_TemplateEngine.php @@ -1022,14 +1022,23 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate $eval = str_replace( "<%php", "\";", str_replace( - "%>", "\$result .= \"", $eval + "%>", "\n\$result .= \"", $eval ) ); // Did something change? if (strlen($eval) != $eval) { // Run the constructed command. This will "compile" all variables in - eval($eval); + @eval($eval); + } // END - if + + // Goes something wrong? + if (!isset($result)) { + // Output eval command + $this->debugOutput(sprintf("Failed eval() code:
%s
", $this->markupCode($eval, true)), true); + + // Output backtrace here + $this->debugBacktrace(); } // END - if // Set raw template data @@ -1118,15 +1127,8 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate $this->getTemplateType() ); - if ((is_object($this->getDebugInstance())) && (method_exists($this->getDebugInstance(), 'output'))) { - // Use debug output handler - $this->getDebugInstance()->output($msg); - die(); - } else { - // Put directly out - // DO NOT REWRITE THIS TO app_die() !!! - die($msg); - } + // Write the problem to the world... + $this->debugOutput($msg); break; } } diff --git a/inc/classes/middleware/debug/class_DebugMiddleware.php b/inc/classes/middleware/debug/class_DebugMiddleware.php index 1f5e6e0..ed1f8d0 100644 --- a/inc/classes/middleware/debug/class_DebugMiddleware.php +++ b/inc/classes/middleware/debug/class_DebugMiddleware.php @@ -117,7 +117,7 @@ class DebugMiddleware extends BaseMiddleware implements Registerable { } elseif (!is_object($this->outputInstance)) { // The debug output instance is not an object throw new NoObjectException($this->ouputInstance, self::EXCEPTION_IS_NO_OBJECT); - } elseif (!method_exists($this->outputInstance, 'outputStream')) { + } elseif (!$this->outputInstance instanceof Debugger) { // The required method outputStream() is missing throw new MissingMethodException(array($this->outputInstance, 'outputStream'), self::EXCEPTION_MISSING_METHOD); } @@ -126,7 +126,7 @@ class DebugMiddleware extends BaseMiddleware implements Registerable { if (empty($outStream)) { // Initialization phase return; - } + } // END - if // Use the output instance $this->outputInstance->outputStream($outStream); -- 2.39.5