From c1f597699e277f0a7d8635ff2064364e0fa1536c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 20 Jun 2008 13:08:19 +0000 Subject: [PATCH] User profile form added --- .gitattributes | 2 + application/ship-simu/config.php | 9 ++ .../actions/class_ShipSimuProfileAction.php | 67 ++++++++++ .../templates/de/code/login_profile.ctp | 118 ++++++++++++++++++ .../templates/de/code/register_form.ctp | 22 ++-- .../main/helper/web/class_WebFormHelper.php | 86 ++++++++++++- inc/classes/main/user/class_User.php | 23 ++++ 7 files changed, 318 insertions(+), 9 deletions(-) create mode 100644 application/ship-simu/main/actions/class_ShipSimuProfileAction.php create mode 100644 application/ship-simu/templates/de/code/login_profile.ctp diff --git a/.gitattributes b/.gitattributes index 02a4bcf..5364a5e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -57,6 +57,7 @@ application/ship-simu/main/.htaccess -text application/ship-simu/main/actions/.htaccess -text application/ship-simu/main/actions/class_ShipSimuLoginAction.php -text application/ship-simu/main/actions/class_ShipSimuLogoutAction.php -text +application/ship-simu/main/actions/class_ShipSimuProfileAction.php -text application/ship-simu/main/class_ -text application/ship-simu/main/class_BasePersonell.php -text application/ship-simu/main/class_BaseSimulator.php -text @@ -139,6 +140,7 @@ application/ship-simu/templates/de/code/login_failed.ctp -text 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_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 a63a95c..cef723c 100644 --- a/application/ship-simu/config.php +++ b/application/ship-simu/config.php @@ -133,6 +133,12 @@ $cfg->setConfigEntry('login_type', "username"); // username, email, both // CFG: GUEST-LOGIN-ALLOWED $cfg->setConfigEntry('guest_login_allowed', "Y"); +// CFG: EMAIL-CHANGE-CONFIRMATION +$cfg->setConfigEntry('email_change_confirmation', "Y"); + +// CFG: EMAIL-CHANGE-ALLOWED +$cfg->setConfigEntry('email_change_allowed', "Y"); + // CFG: GUEST-LOGIN-USERNAME $cfg->setConfigEntry('guest_login_username', "guest"); @@ -145,6 +151,9 @@ $cfg->setConfigEntry('login_welcome_action_class', "ShipSimuLoginAction"); // CFG: LOGIN-LOGOUT-ACTION-CLASS $cfg->setConfigEntry('login_logout_action_class', "ShipSimuLogoutAction"); +// CFG: LOGIN-PROFILE-ACTION-CLASS +$cfg->setConfigEntry('login_profile_action_class', "ShipSimuProfileAction"); + // CFG: LOGOUT-IMMEDIATE $cfg->setConfigEntry('logout_immediate', "N"); diff --git a/application/ship-simu/main/actions/class_ShipSimuProfileAction.php b/application/ship-simu/main/actions/class_ShipSimuProfileAction.php new file mode 100644 index 0000000..ce27819 --- /dev/null +++ b/application/ship-simu/main/actions/class_ShipSimuProfileAction.php @@ -0,0 +1,67 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class ShipSimuProfileAction extends BaseAction implements Commandable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set description + $this->setObjectDescription("Profile action"); + + // Generate unique key + $this->generateUniqueId(); + } + + /** + * Creates an instance of this action + * + * @return $actionInstance An instance of this action class + */ + public final static function createShipSimuProfileAction () { + // Get a new instance + $actionInstance = new ShipSimuProfileAction(); + + // Return the instance + return $actionInstance; + } + + /** + * Executes the command with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + /* @TODO Maybe we need to do something later here */ + } +} + +// [EOF] +?> diff --git a/application/ship-simu/templates/de/code/login_profile.ctp b/application/ship-simu/templates/de/code/login_profile.ctp new file mode 100644 index 0000000..8b6eaee --- /dev/null +++ b/application/ship-simu/templates/de/code/login_profile.ctp @@ -0,0 +1,118 @@ +prefetchFieldValues('user'); + +// Password can only be changed when the old one is entered and new one twice! +$helper->addFormGroup("pass", "Neues Passwort einrichten:"); +$helper->addFormSubGroup("password", "Bitte gebe zum Ändern deines Passwortes zweimal das gewünschte neue Passwort ein."); +$helper->addFieldText("pass1", "Neues Passwort:"); +$helper->addInputPasswordField("pass1"); +$helper->addFieldText("pass2", "Neues Passwort, Wiederholung:"); +$helper->addInputPasswordField("pass2"); + +// Display current email +$helper->addFormNote("Derzeitige Email-Adresse: ".$helper->getField("email").""); + +// Only for changing email address +if ($helper->ifEmailChangeAllowed()) { + $helper->addFormGroup("email", "Änderung deiner Email-Addresse:"); + $helper->addFormSubGroup("email", "Gebe nur deine Email-Adresse zweimal ein, wenn du diese ändern möchtest!"); + $helper->addFieldText("email1", "Email-Adresse:"); + $helper->addInputTextField("email1"); + $helper->addFieldText("email2", "Wiederholung Email-Adresse:"); + $helper->addInputTextField("email2"); + + if ($helper->ifEmailMustBeUnique()) { + $helper->addFormNote("Die von dir eingegebene Email-Adresse darf nur einmal im Spiel verwendet worden sein."); + } // END - Unique email addresses + + if ($helper->ifEmailChangeRequireConfirmation()) { + $helper->addFormNote("Es wird ein Bestätigungslink an deine neue Email-Adresse gesendet. Bitte klicke diesen dann möglichst schnell an."); + } // END - Change requires confirmation +} // END - email change allowed + +$helper->addFormGroup("profile", "Hier kannst du deine Profildaten ändern."); + +// Persoenliche Daten mit in der Anmeldung abfragen? +if ($helper->ifRegisterIncludesPersonaData()) { + $helper->addFormSubGroup("persona", "Wenn du magst, dann vervollständige deine komplette Adresse mit deinem Namen."); + $helper->addFieldText("surname", "Dein Vorname:"); + $helper->addInputTextFieldWithDefault("surname"); + $helper->addFieldText("family", "Dein Nachname:"); + $helper->addInputTextFieldWithDefault("family"); + $helper->addFieldText("street", "Strasse und Hausnummer:"); + $helper->addInputTextFieldWithDefault("street"); + $helper->addFieldText("city", "Wohnort:"); + $helper->addInputTextFieldWithDefault("city"); +} // END - Persona data + +$helper->addFormSubGroup("zip", "Magst du uns auch deine Postleitzahl verraten?"); +$helper->addFieldText("zip", "Postleitzahl:"); +$helper->addInputTextFieldWithDefault("zip"); + +$helper->addFormSubGroup("chat", "Gebe hier deine Nicknames bzw. Nummern an:"); + +if ($helper->ifChatEnabled("icq")) { + $helper->addFieldText("icq", "ICQ-Nummer:"); + $helper->addInputTextFieldWithDefault("icq"); +} // END - if + +if ($helper->ifChatEnabled("jabber")) { + $helper->addFieldText("jabber", "Jabber:"); + $helper->addInputTextFieldWithDefault("jabber"); +} // END - if + +if ($helper->ifChatEnabled("yahoo")) { + $helper->addFieldText("yahoo", "Yahoo!:"); + $helper->addInputTextFieldWithDefault("yahoo"); +} // END - if + +if ($helper->ifChatEnabled("aol")) { + $helper->addFieldText("aol", "AOL-Screenname:"); + $helper->addInputTextFieldWithDefault("aol"); +} // END - if + +if ($helper->ifChatEnabled("msn")) { + $helper->addFieldText("msn", "MSN:"); + $helper->addInputTextFieldWithDefault("msn"); +} // END - if + +if (!$helper->ifRegisterRequiresEmailVerification()) { + $helper->addFormExtraNote(1, "Die Benachrichtigungen per sind im Loginbereich verfeinerbar, welche du genau haben willst."); +} // END - Extra note + +// Rules already accepted? +if ($helper->ifRulesHaveChanged()) { + $helper->addFormGroup("rules", "Bitte lese dir die Spieleregeln gut durch und kreuze dann "Ja, ich akzeptiere die aktuellen Spielregeln" an."); + $helper->addFieldText("rules", "Ja, ich akzeptiere die aktuellen Spielregeln:"); + $helper->addInputCheckboxField("rules", false); +} else { + $helper->addFormNote("Du hast die aktuellen Spielregeln akzeptiert. Vielen Dank!"); + $helper->addInputHiddenField("rules", "1"); +} + +// Ask again for current account password +$helper->addFormGroup("pass_old", "Bitte gebe zur Bestätigung der Änderungen dein derzeiges Passwort ein."); +$helper->addFieldText("pass_old", "Altes Passwort:"); +$helper->addInputPasswordField("pass_old"); + +// Abschliessender Hinweis und Abschluss des Formulars +$helper->addFormGroup("buttons", "Sind alle Daten nun korrekt eingegeben? Dann sende sie mit einem Klick einfach ab!"); +$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 +
+ +
+ {?shipsimu_profile?} +
diff --git a/application/ship-simu/templates/de/code/register_form.ctp b/application/ship-simu/templates/de/code/register_form.ctp index f579b1b..9f427c2 100644 --- a/application/ship-simu/templates/de/code/register_form.ctp +++ b/application/ship-simu/templates/de/code/register_form.ctp @@ -4,8 +4,7 @@ // BaseHelper. $helper = WebFormHelper::createWebFormHelper($this, "shipsimu_register"); -// Nickname und Passwort sollten immer abgefragt werden, die Email als Loginname -// wuerde aber auch gehen. +// Always ask at least for nickname and password $helper->addFormGroup("login", "Bitte gebe hier gewünschten Nickname und dein Zugangspasswort ein."); $helper->addFormSubGroup("username", "Dein Nickname wird erst nach Absenden des Formulares geprüft. Später bauen wir dann einen automatischen Test ein, der dir sofort zeigt, ob der Nickname bereits vergeben ist."); $helper->addFieldText("username", "Nickname im Spiel:"); @@ -22,13 +21,16 @@ if ($helper->ifRegisterRequiresEmailVerification()) { $helper->addInputTextField("email1"); $helper->addFieldText("email2", "Wiederholung Email-Adresse:"); $helper->addInputTextField("email2"); + if ($helper->ifEmailMustBeUnique()) { $helper->addFormNote("Die von dir eingegebene Email-Adresse darf nur einmal im Spiel verwendet worden sein."); } // END - Unique email addresses + } // END - email verification if ($helper->ifRegisterIncludesProfile()) { $helper->addFormGroup("profile", "Hier kannst du zusätzlich deine Profildaten vorweg eingeben, du kannst sie aber auch nach dem Login vervollständigen!"); + if (!$helper->ifRegisterRequiresEmailVerification()) { $helper->addFormSubGroup("email", "Die Angabe deiner Email-Adresse ist nur dann nötig, wenn du auch Email-Benachrichtigungen (*1) haben möchtest."); $helper->addFieldText("email1", "Email-Adresse:"); @@ -53,30 +55,36 @@ if ($helper->ifRegisterIncludesProfile()) { $helper->addInputTextField("zip"); $helper->addFormSubGroup("chat", "Gebe hier deine Nicknames bzw. Nummern an:"); + if ($helper->ifChatEnabled("icq")) { $helper->addFieldText("icq", "ICQ-Nummer:"); $helper->addInputTextField("icq"); - } + } // END - if + if ($helper->ifChatEnabled("jabber")) { $helper->addFieldText("jabber", "Jabber:"); $helper->addInputTextField("jabber"); - } + } // END - if + if ($helper->ifChatEnabled("yahoo")) { $helper->addFieldText("yahoo", "Yahoo!:"); $helper->addInputTextField("yahoo"); - } + } // END - if + if ($helper->ifChatEnabled("aol")) { $helper->addFieldText("aol", "AOL-Screenname:"); $helper->addInputTextField("aol"); - } + } // END - if + if ($helper->ifChatEnabled("msn")) { $helper->addFieldText("msn", "MSN:"); $helper->addInputTextField("msn"); - } + } // END - if if (!$helper->ifRegisterRequiresEmailVerification()) { $helper->addFormExtraNote(1, "Die Benachrichtigungen per sind im Loginbereich verfeinerbar, welche du genau haben willst."); } // END - Extra note + } // END - ask profile data // Spielregeln abfragen diff --git a/inc/classes/main/helper/web/class_WebFormHelper.php b/inc/classes/main/helper/web/class_WebFormHelper.php index 293a6fc..5debdda 100644 --- a/inc/classes/main/helper/web/class_WebFormHelper.php +++ b/inc/classes/main/helper/web/class_WebFormHelper.php @@ -22,6 +22,11 @@ * along with this program. If not, see . */ class WebFormHelper extends BaseHelper { + /** + * Instance to the class which provides field values + */ + private $valueInstance = null; + /** * Wether the form tag is opened (keep at false or else your forms will * never work!) @@ -98,6 +103,24 @@ class WebFormHelper extends BaseHelper { return $helperInstance; } + /** + * Pre-fetches field default values from the given registry key instance into this class + * + * @param $registryKey + * @return void + * @throws NullPointerException If an instance from registry is null + */ + public function prefetchFieldValues ($registryKey) { + // Get the required instance + $this->valueInstance = Registry::getRegistry()->getInstance($registryKey); + + // Is the instance valid? + if (is_null($this->valueInstance)) { + // Throw an exception + throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + } // END - if + } + /** * Add the form tag or close it an already opened form tag * @@ -164,8 +187,8 @@ class WebFormHelper extends BaseHelper { * Add a text input tag to the form or throw an exception if it is not yet * opened. The field's name will be set as id. * - * @param $fieldName Input field name - * @param $fieldValue Input default value (default: empty) + * @param $fieldName Input field name + * @param $fieldValue Input default value (default: empty) * @return void * @throws FormClosedException If the form is not yet opened */ @@ -187,6 +210,21 @@ class WebFormHelper extends BaseHelper { $this->addContent($inputContent); } + /** + * Add a text input tag to the form with pre-loaded default value + * + * @param $fieldName Input field name + * @return void + */ + public function addInputTextFieldWithDefault ($fieldName) { + // Get the value from instance + $fieldValue = call_user_func_array(array($this->valueInstance, "getField"), array($fieldName)); + //* DEBUG: */ echo __METHOD__.":".$fieldName."=".$fieldValue."
\n"; + + // Add the text field + $this->addInputTextField($fieldName, $fieldValue); + } + /** * Add a password input tag to the form or throw an exception if it is not * yet opened. The field's name will be set as id. @@ -607,6 +645,36 @@ class WebFormHelper extends BaseHelper { return $isAllowed; } + /** + * Checks wether the email address change must be confirmed + * + * @return $requireConfirm Wether email change must be confirmed + */ + public function ifEmailChangeRequireConfirmation () { + $requireConfirm = ($this->getConfigInstance()->readConfig('email_change_confirmation') == "Y"); + return $requireConfirm; + } + + /** + * Checks wether the rules has been updated + * + * @return $rulesUpdated Wether rules has been updated + */ + public function ifRulesHaveChanged () { + /* @TODO Implement check if rules have been changed */ + return false; + } + + /** + * Checks wether email change is allowed + * + * @return $emailChange Wether changing email address is allowed + */ + public function ifEmailChangeAllowed () { + $emailChange = ($this->getConfigInstance()->readConfig('email_change_allowed') == "Y"); + return $emailChange; + } + /** * Flushs the content out (not yet secured against open forms, etc.!) or * throw an exception if it is not yet closed @@ -624,6 +692,20 @@ class WebFormHelper extends BaseHelper { // Send content to template engine $this->getTemplateInstance()->assignVariable($this->formName, $this->getContent()); } + + /** + * Getter for direct field values + * + * @param $fieldName Name of the field we shall fetch + * @return $fieldValue Value from field + */ + public function getField ($fieldName) { + // Get the field value + $fieldValue = call_user_func_array(array($this->valueInstance, "getField"), array($fieldName)); + + // Return it + return $fieldValue; + } } // [EOF] diff --git a/inc/classes/main/user/class_User.php b/inc/classes/main/user/class_User.php index 49b285f..6e9d8f7 100644 --- a/inc/classes/main/user/class_User.php +++ b/inc/classes/main/user/class_User.php @@ -379,6 +379,29 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable { $wrapperInstance->doUpdateByResult($this->resultInstance); } // END - if } + + /** + * Getter for field name + * + * @param $fieldName Field name which we shall get + * @return $fieldValue Field value from the user + */ + public function getField ($fieldName) { + // Default field value + $fieldValue = null; + + // Get current array + $fieldArray = $this->resultInstance->current(); + + // Does the field exist? + if (isset($fieldArray[$fieldName])) { + // Get it + $fieldValue = $fieldArray[$fieldName]; + } // END - if + + // Return it + return $fieldValue; + } } // [EOF] -- 2.30.2