From 6187002fb189cdfcc59a81aae7d217bcf7baaa85 Mon Sep 17 00:00:00 2001 From: Morven Lewis-Everley Date: Sat, 28 Apr 2018 15:08:03 +0100 Subject: [PATCH 1/5] Switch to generating edit account based on Member::frontendFields --- _config/config.yml | 7 +++- changelog.md | 7 +++- code/forms/Users_EditAccountForm.php | 63 +++++++++++++++++++--------- 3 files changed, 55 insertions(+), 22 deletions(-) diff --git a/_config/config.yml b/_config/config.yml index 72b234b..cca95d1 100755 --- a/_config/config.yml +++ b/_config/config.yml @@ -2,9 +2,12 @@ Group: extensions: - Ext_Users_Group Member: + required_fields: + - "FirstName" + - "Surname" + - "Email" extensions: - Ext_Users_Member Controller: extensions: - - Ext_Users_Controller - + - Ext_Users_Controller \ No newline at end of file diff --git a/changelog.md b/changelog.md index 4d154b4..3566d32 100644 --- a/changelog.md +++ b/changelog.md @@ -37,4 +37,9 @@ Minor update to: # 1.2.1 -* Add additional extension hooks when edit form submitted \ No newline at end of file +* Add additional extension hooks when edit form submitted + +# 1.3.0 + +* Switch to using frontend form fields to generate the "Edit Account Details" form +* Add better error handling on edit account submission \ No newline at end of file diff --git a/code/forms/Users_EditAccountForm.php b/code/forms/Users_EditAccountForm.php index 09508af..e7d3ad3 100755 --- a/code/forms/Users_EditAccountForm.php +++ b/code/forms/Users_EditAccountForm.php @@ -3,21 +3,48 @@ class Users_EditAccountForm extends Form { + /** + * These fields will be ignored by the `Users_EditAccountForm` + * when generating fields + */ + private static $ignore_member_fields = array( + "LastVisited", + "FailedLoginCount", + "DateFormat", + "TimeFormat", + "VerificationCode", + "Password", + "HasConfiguredDashboard", + "URLSegment", + "BlogProfileSummary", + "BlogProfileImage" + ); + public function __construct($controller, $name = "Users_EditAccountForm") { - $fields = new FieldList( - HiddenField::create("ID"), - TextField::create( - "FirstName", - _t('Member.FIRSTNAME', "First Name") - ), - TextField::create( - "Surname", - _t('Member.SURNAME', "Surname") - ), - EmailField::create( - "Email", - _t("Member.EMAIL", "Email") + $member = Member::singleton(); + $hidden_fields = array_merge( + $member->config()->hidden_fields, + static::config()->ignore_member_fields + ); + + $fields = $member->getFrontEndFields(); + + // Remove all "hidden fields" + foreach ($hidden_fields as $field_name) { + $fields->removeByName($field_name); + } + + // Add the current member ID + $fields->add(HiddenField::create("ID")); + + // Switch locale field + $fields->replaceField( + 'Locale', + DropdownField::create( + "Locale", + $member->fieldLabel("Locale"), + i18n::get_existing_translations() ) ); @@ -37,11 +64,9 @@ public function __construct($controller, $name = "Users_EditAccountForm") $this->extend("updateFormActions", $actions); - $required = new RequiredFields(array( - "FirstName", - "Surname", - "Email" - )); + $required = new RequiredFields( + $member->config()->required_fields + ); $this->extend("updateRequiredFields", $required); @@ -68,7 +93,7 @@ public function doUpdate($data) $this->extend("onBeforeUpdate", $data); - // Check that a mamber isn't trying to mess up another users profile + // Check that a member isn't trying to mess up another users profile if (Member::currentUserID() && $member->canEdit(Member::currentUser())) { // Save member $this->saveInto($member); From d03453ac08c8dff658c263aa2615042d3fabad56 Mon Sep 17 00:00:00 2001 From: Morven Lewis-Everley Date: Sat, 28 Apr 2018 15:17:26 +0100 Subject: [PATCH 2/5] Update docs --- docs/en/Usage.md | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/docs/en/Usage.md b/docs/en/Usage.md index 3cd5a4f..89bc58b 100644 --- a/docs/en/Usage.md +++ b/docs/en/Usage.md @@ -49,4 +49,39 @@ This module makes `$UserAccountNav` available to all your controllers. You can include this variable in your templates and it will add an account navigation menu. -If you wish to change the styling of this menu, simply edit the `Users_AccountNav.ss` template include. \ No newline at end of file +If you wish to change the styling of this menu, simply edit the `Users_AccountNav.ss` +template include. + +## Adding/Removing fields to the Edit Account form + +By default, this module generates an "Edit your account" view via: + + http://yoursite.com/users/account + +This view uses an instance of `Users_EditAccountForm` to generate the edit form. + +`Users_EditAccountForm` uses `Member::getFrontEndFields()` to generate the fieldlist, +it also uses the `Member.hidden_fields` config variable, as well as it's own +`ignore_member_fields` config variable, to remove fields from the EditForm. + +If you want to remove additional fields from this form (for example `Locale`), you can +add the following to your config.yml: + +```yml +Users_EditAccountForm: + ignore_member_fields: + - "Locale" +``` + +### Updating Required Fields + +This module uses `Member.required_fields` config variable to determine required fields. +If you added the Field `PhoneNumber` and wanted to make it required, you could do as below: + +```yml +Member: + db: + - "PhoneNumber" + required_fields: + - "PhoneNumber" +``` \ No newline at end of file From be265afc92113c8ad1648bb916f8ce7347d74e73 Mon Sep 17 00:00:00 2001 From: Morven Lewis-Everley Date: Sat, 28 Apr 2018 15:21:41 +0100 Subject: [PATCH 3/5] Ensure we catch any exceptions from member when saving the form --- code/forms/Users_EditAccountForm.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/code/forms/Users_EditAccountForm.php b/code/forms/Users_EditAccountForm.php index e7d3ad3..c2be0d2 100755 --- a/code/forms/Users_EditAccountForm.php +++ b/code/forms/Users_EditAccountForm.php @@ -95,14 +95,21 @@ public function doUpdate($data) // Check that a member isn't trying to mess up another users profile if (Member::currentUserID() && $member->canEdit(Member::currentUser())) { - // Save member - $this->saveInto($member); - $member->write(); - - $this->sessionMessage( - _t("Users.DETAILSUPDATED", "Account details updated"), - "success" - ); + try { + // Save member + $this->saveInto($member); + $member->write(); + + $this->sessionMessage( + _t("Users.DETAILSUPDATED", "Account details updated"), + "success" + ); + } catch (Exception $e) { + $this->sessionMessage( + $e->getMessage(), + "warning" + ); + } } else { $this->sessionMessage( _t("Users.CANNOTEDIT", "You cannot edit this account"), From fdc87b2a2d644df8581c88f4d70e6c436fb7cbbe Mon Sep 17 00:00:00 2001 From: Morven Lewis-Everley Date: Sat, 28 Apr 2018 15:44:56 +0100 Subject: [PATCH 4/5] Add first registered to profile summary --- lang/en.yml | 1 + templates/Includes/UsersProfileSummary.ss | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lang/en.yml b/lang/en.yml index 17bf23d..ea35ece 100755 --- a/lang/en.yml +++ b/lang/en.yml @@ -10,6 +10,7 @@ en: DETAILSUPDATED: 'Account details updated' EDITDETAILS: 'Edit account details' EditAccountDetails: 'Edit account details' + FirstRegistered: 'First Registered' HELLO: Hi LOGIN: 'Log in' LOGOUT: Logout diff --git a/templates/Includes/UsersProfileSummary.ss b/templates/Includes/UsersProfileSummary.ss index 38331a0..cb8b569 100644 --- a/templates/Includes/UsersProfileSummary.ss +++ b/templates/Includes/UsersProfileSummary.ss @@ -1,9 +1,10 @@ <% with $CurrentUser %>

- <% _t('Member.FIRSTNAME',"First Name") %> $FirstName
- <% _t('Member.SURNAME',"Surname") %> $Surname
- <% _t("Member.EMAIL","Email") %> $Email
+ <%t Member.FIRSTNAME "First Name" %> $FirstName
+ <%t Member.SURNAME "Surname" %> $Surname
+ <%t Member.EMAIL "Email" %> $Email
+ <%t Users.FirstRegistered "First Registered" %> $Created.Ago

<% end_with %> \ No newline at end of file From 27ddc38890fa2709ac419eccf854ab6b439f0d9a Mon Sep 17 00:00:00 2001 From: Morven Lewis-Everley Date: Sat, 28 Apr 2018 16:00:16 +0100 Subject: [PATCH 5/5] PHPBCF --- code/Users.php | 86 +++++-------- code/control/Users_Account_Controller.php | 142 ++++++++++++++------- code/control/Users_Register_Controller.php | 87 +++++++++---- code/extensions/Ext_Users_Controller.php | 3 +- code/extensions/Ext_Users_Group.php | 3 + code/extensions/Ext_Users_Member.php | 38 ++++-- code/forms/Users_EditAccountForm.php | 18 +++ 7 files changed, 236 insertions(+), 141 deletions(-) diff --git a/code/Users.php b/code/Users.php index 1e4071f..7450885 100644 --- a/code/Users.php +++ b/code/Users.php @@ -5,45 +5,45 @@ * config, but will probably be extended in future to provide additional * functionality. * - * @author i-lateral (http://www.i-lateral.com) - * @package users + * @package Users + * @author i-lateral */ class Users extends Object { - /** - * Minimum character length of the password required + /** + * Minimum character length of the password required * on registration/account editing - * - * @var int + * + * @var int * @config - */ - private static $password_min_length = 6; + */ + private static $password_min_length = 6; - /** - * Maximum character length of the password required + /** + * Maximum character length of the password required * on registration/account editing - * - * @var int + * + * @var int * @config - */ - private static $password_max_length = 16; + */ + private static $password_max_length = 16; - /** - * Enforces strong password (at least one digit and one alphanumeric - * character) on registration/account editing - * - * @var boolean + /** + * Enforces strong password (at least one digit and one alphanumeric + * character) on registration/account editing + * + * @var boolean * @config - */ - private static $password_require_strong = false; + */ + private static $password_require_strong = false; /** * Stipulate if a user requires verification. NOTE this does not * actually deny the user the ability to login, it only alerts them * that they need validiation * - * @var Boolean + * @var boolean * @config */ private static $require_verification = true; @@ -52,7 +52,7 @@ class Users extends Object * Stipulate whether to send a verification email to users after * registration * - * @var Boolean + * @var boolean * @config */ private static $send_verification_email = false; @@ -61,7 +61,7 @@ class Users extends Object * Stipulate the sender address for emails sent from this module. If * not set, use the default @Email.admin_email instead. * - * @var strong + * @var string * @config */ private static $send_email_from; @@ -69,7 +69,7 @@ class Users extends Object /** * Auto login users after registration * - * @var Boolean + * @var boolean * @config */ private static $login_after_register = true; @@ -78,30 +78,20 @@ class Users extends Object * Add new users to the following groups. This is a list of group codes. * Adding a new code will add the user to this group * - * @var array + * @var array * @config */ private static $new_user_groups = array( "users-frontend" ); - /** - * Add a group to the list of groups a new user is added to on - * registering. - * - * @param string Group code that will be used - */ - public static function addNewUserGroup($code) - { - Deprecation::notice("1.3", "addNewUserGroup depreciated, use global config instead"); - self::config()->new_user_groups[] = $code; - } - /** * Remove a group from the list of groups a new user is added to on * registering. * - * @param string Group code that will be used + * @param string $code Group code that will be used + * + * @return void */ public static function removeNewUserGroup($code) { @@ -114,30 +104,20 @@ public static function removeNewUserGroup($code) * Groups a user will be added to when verified. This should be an * array of group "codes", NOT names or ID's * - * @var array + * @var array * @config */ private static $verification_groups = array( "users-verified" ); - /** - * Add a group to the list of groups a new user is added to on - * registering. - * - * @param string Group code that will be used - */ - public static function addVerificationGroup($code) - { - Deprecation::notice("1.3", "addVerificationGroup depreciated, use global config instead"); - self::config()->verification_groups[] = $code; - } - /** * Remove a group from the list of groups a new user is added to on * registering. * - * @param string Group code that will be used + * @param string $code Group code that will be used + * + * @return void */ public static function removeVerificationGroup($code) { diff --git a/code/control/Users_Account_Controller.php b/code/control/Users_Account_Controller.php index d7dc21c..22ca09c 100755 --- a/code/control/Users_Account_Controller.php +++ b/code/control/Users_Account_Controller.php @@ -3,7 +3,9 @@ /** * Controller that is used to allow users to manage their accounts via * the front end of the site. - * + * + * @package Users + * @author i-lateral */ class Users_Account_Controller extends Controller implements PermissionProvider { @@ -18,7 +20,7 @@ class Users_Account_Controller extends Controller implements PermissionProvider /** * Allowed sub-URL's on this controller * - * @var array + * @var array * @config */ private static $allowed_actions = array( @@ -48,7 +50,8 @@ public function getMember() /** * Setter for member * - * @param Member $member + * @param Member $member A member to associate + * * @return self */ public function setMember(Member $member) @@ -97,8 +100,9 @@ public function init() /** * Get the link to this controller * - * @param string $action - * @return string|null + * @param string $action The URL endpoint for this controller + * + * @return string */ public function Link($action = null) { @@ -111,8 +115,9 @@ public function Link($action = null) /** * Get an absolute link to this controller * - * @param string $action - * @return string|null + * @param string $action The URL endpoint for this controller + * + * @return string */ public function AbsoluteLink($action = null) { @@ -123,8 +128,9 @@ public function AbsoluteLink($action = null) * Get a relative (to the root url of the site) link to this * controller * - * @param string $action - * @return string|null + * @param string $action The URL endpoint for this controller + * + * @return string */ public function RelativeLink($action = null) { @@ -135,7 +141,9 @@ public function RelativeLink($action = null) /** * If content controller exists, return it's menu function + * * @param int $level Menu level to return. + * * @return ArrayList */ public function getMenu($level = 1) @@ -146,6 +154,13 @@ public function getMenu($level = 1) } } + /** + * Shortcut for getMenu + * + * @param int $level Menu level to return. + * + * @return ArrayList + */ public function Menu($level) { return $this->getMenu(); @@ -153,40 +168,49 @@ public function Menu($level) /** * Display the currently outstanding orders for the current user - * + * + * @return HTMLText */ public function index() { // Setup default profile summary sections $sections = ArrayList::create(); - $sections->push(ArrayData::create(array( - "Title" => "", - "Content" => $this->renderWith( - "UsersProfileSummary", - array("CurrentUser" => Member::currentUser()) + $sections->push( + ArrayData::create( + array( + "Title" => "", + "Content" => $this->renderWith( + "UsersProfileSummary", + array("CurrentUser" => Member::currentUser()) + ) + ) ) - ))); + ); // Allow users to add extra content sections to the // summary $this->extend("updateIndexSections", $sections); - $this->customise(array( + $this->customise( + array( "Title" => _t('Users.ProfileSummary', 'Profile Summary'), "MetaTitle" => _t('Users.ProfileSummary', 'Profile Summary'), "Content" => $this->renderWith( "UsersAccountSections", array("Sections" => $sections) ) - )); + ) + ); $this->extend("onBeforeIndex"); - return $this->renderWith(array( + return $this->renderWith( + array( "UserAccount", "Page" - )); + ) + ); } public function edit() @@ -198,19 +222,23 @@ public function edit() $form->loadDataFrom($member); } - $this->customise(array( + $this->customise( + array( "Title" => _t("Users.EditAccountDetails", "Edit account details"), "MetaTitle" => _t("Users.EditAccountDetails", "Edit account details"), "Form" => $form - )); + ) + ); $this->extend("onBeforeEdit"); - return $this->renderWith(array( + return $this->renderWith( + array( "UserAccount_edit", "UserAccount", "Page" - )); + ) + ); } public function changepassword() @@ -229,24 +257,28 @@ public function changepassword() $password_set = $this->request->getVar("s"); if($password_set && $password_set == 1) { $form->sessionMessage( - _t("Users.PasswordChangedSuccessfully","Password Changed Successfully"), + _t("Users.PasswordChangedSuccessfully", "Password Changed Successfully"), "good" ); } - $this->customise(array( + $this->customise( + array( "Title" => _t("Security.ChangeYourPassword", "Change your password"), "MetaTitle" => _t("Security.ChangeYourPassword", "Change your password"), "Form" => $form - )); + ) + ); $this->extend("onBeforeChangePassword"); - return $this->renderWith(array( + return $this->renderWith( + array( "UserAccount_changepassword", "UserAccount", "Page" - )); + ) + ); } /** @@ -306,26 +338,38 @@ public function getAccountMenu() $curr_action = $this->request->param("Action"); - $menu->add(ArrayData::create(array( - "ID" => 0, - "Title" => _t('Users.PROFILESUMMARY', "Profile Summary"), - "Link" => $this->Link(), - "LinkingMode" => (!$curr_action) ? "current" : "link" - ))); - - $menu->add(ArrayData::create(array( - "ID" => 10, - "Title" => _t('Users.EDITDETAILS', "Edit account details"), - "Link" => $this->Link("edit"), - "LinkingMode" => ($curr_action == "edit") ? "current" : "link" - ))); - - $menu->add(ArrayData::create(array( - "ID" => 30, - "Title" => _t('Users.CHANGEPASSWORD', "Change password"), - "Link" => $this->Link("changepassword"), - "LinkingMode" => ($curr_action == "changepassword") ? "current" : "link" - ))); + $menu->add( + ArrayData::create( + array( + "ID" => 0, + "Title" => _t('Users.PROFILESUMMARY', "Profile Summary"), + "Link" => $this->Link(), + "LinkingMode" => (!$curr_action) ? "current" : "link" + ) + ) + ); + + $menu->add( + ArrayData::create( + array( + "ID" => 10, + "Title" => _t('Users.EDITDETAILS', "Edit account details"), + "Link" => $this->Link("edit"), + "LinkingMode" => ($curr_action == "edit") ? "current" : "link" + ) + ) + ); + + $menu->add( + ArrayData::create( + array( + "ID" => 30, + "Title" => _t('Users.CHANGEPASSWORD', "Change password"), + "Link" => $this->Link("changepassword"), + "LinkingMode" => ($curr_action == "changepassword") ? "current" : "link" + ) + ) + ); $this->extend("updateAccountMenu", $menu); diff --git a/code/control/Users_Register_Controller.php b/code/control/Users_Register_Controller.php index a5d9460..4939516 100755 --- a/code/control/Users_Register_Controller.php +++ b/code/control/Users_Register_Controller.php @@ -10,6 +10,8 @@ * This is done by adding verified users to the groups stipulated by the * $verification_groups config variable * + * @package Users + * @author i-lateral */ class Users_Register_Controller extends Controller { @@ -38,6 +40,7 @@ class Users_Register_Controller extends Controller * email from multiple locations * * @param $member Member object to send email to + * * @return boolean */ protected function send_verification_email(Member $member) @@ -52,7 +55,8 @@ protected function send_verification_email(Member $member) /** * Get the link to this controller * - * @param string $action + * @param string $action The URL endpoint for this controller + * * @return string */ public function Link($action = null) @@ -66,8 +70,9 @@ public function Link($action = null) /** * Get an absolute link to this controller * - * @param string $action - * @return false|string + * @param string $action The URL endpoint for this controller + * + * @return string */ public function AbsoluteLink($action = null) { @@ -78,7 +83,8 @@ public function AbsoluteLink($action = null) * Get a relative (to the root url of the site) link to this * controller * - * @param string $action + * @param string $action The URL endpoint for this controller + * * @return string */ public function RelativeLink($action = null) @@ -90,7 +96,9 @@ public function RelativeLink($action = null) /** * If content controller exists, return it's menu function + * * @param int $level Menu level to return. + * * @return ArrayList */ public function getMenu($level = 1) @@ -101,6 +109,13 @@ public function getMenu($level = 1) } } + /** + * Shortcut for getMenu + * + * @param int $level Menu level to return. + * + * @return ArrayList + */ public function Menu($level) { return $this->getMenu(); @@ -109,24 +124,29 @@ public function Menu($level) /** * Default action this controller will deal with * - * @param SS_HTTPRequest $request + * @param SS_HTTPRequest $request Current request + * * @return HTMLText */ public function index(SS_HTTPRequest $request) { - $this->customise(array( + $this->customise( + array( 'Title' => _t('Users.Register', 'Register'), 'MetaTitle' => _t('Users.Register', 'Register'), 'Form' => $this->RegisterForm(), - )); + ) + ); $this->extend("updateIndexAction"); - return $this->renderWith(array( + return $this->renderWith( + array( "Users_Register", "Users", "Page" - )); + ) + ); } @@ -134,7 +154,8 @@ public function index(SS_HTTPRequest $request) * Send a verification email to the user provided (if verification * emails are enabled and account is not already verified) * - * @param SS_HTTPRequest $request + * @param SS_HTTPRequest $request Current request + * * @return HTMLText */ public function sendverification(SS_HTTPRequest $request) @@ -156,31 +177,35 @@ public function sendverification(SS_HTTPRequest $request) $sent = $this->send_verification_email($member); } - $this->customise(array( - "Title" => _t('Users.AccountVerification','Account Verification'), - "MetaTitle" => _t('Users.AccountVerification','Account Verification'), + $this->customise( + array( + "Title" => _t('Users.AccountVerification', 'Account Verification'), + "MetaTitle" => _t('Users.AccountVerification', 'Account Verification'), "Content" => $this->renderWith( "UsersSendVerificationContent", array("Sent" => $sent) ), "Sent" => $sent - )); + ) + ); $this->extend("updateSendVerificationAction"); - return $this->renderWith(array( + return $this->renderWith( + array( "Users_Register_sendverification", "Users", "Page" - )); + ) + ); } - /** * Verify the provided user (ID) using the verification code (Other * ID) provided * - * @param SS_HTTPRequest $request + * @param SS_HTTPRequest $request Current Request + * * @return HTMLText */ public function verify(SS_HTTPRequest $request) @@ -204,23 +229,27 @@ public function verify(SS_HTTPRequest $request) } } - $this->customise(array( - "Title" => _t('Users.AccountVerification','Account Verification'), - "MetaTitle" => _t('Users.AccountVerification','Account Verification'), + $this->customise( + array( + "Title" => _t('Users.AccountVerification', 'Account Verification'), + "MetaTitle" => _t('Users.AccountVerification', 'Account Verification'), "Content" => $this->renderWith( "UsersVerifyContent", array("Verify" => $verify) ), "Verify" => $verify - )); + ) + ); $this->extend("onAfterVerify", $member); - return $this->renderWith(array( + return $this->renderWith( + array( "Users_Register_verify", "Users", "Page" - )); + ) + ); } /** @@ -258,12 +287,14 @@ public function RegisterForm() ); // Setup required fields - $required = new RequiredFields(array( + $required = new RequiredFields( + array( "FirstName", "Surname", "Email", "Password" - )); + ) + ); $form = Form::create( $this, @@ -297,7 +328,9 @@ public function RegisterForm() * etc) * * @param array $data User submitted data - * @param Form $form Registration form + * @param Form $form Registration form + * + * @return SS_HTTPResponse */ public function doRegister($data, $form) { diff --git a/code/extensions/Ext_Users_Controller.php b/code/extensions/Ext_Users_Controller.php index ac7c6de..b8fafc0 100755 --- a/code/extensions/Ext_Users_Controller.php +++ b/code/extensions/Ext_Users_Controller.php @@ -3,7 +3,8 @@ * Extension for Controller that provide methods such as member management * interface to templates * - * @package users + * @package Users + * @author i-lateral */ class Ext_Users_Controller extends Extension { diff --git a/code/extensions/Ext_Users_Group.php b/code/extensions/Ext_Users_Group.php index c121b60..05a942c 100755 --- a/code/extensions/Ext_Users_Group.php +++ b/code/extensions/Ext_Users_Group.php @@ -2,6 +2,9 @@ /** * Overwrite group object so we can setup some more default groups + * + * @package Users + * @author i-lateral */ class Ext_Users_Group extends DataExtension { diff --git a/code/extensions/Ext_Users_Member.php b/code/extensions/Ext_Users_Member.php index 3e8f745..a4babff 100755 --- a/code/extensions/Ext_Users_Member.php +++ b/code/extensions/Ext_Users_Member.php @@ -1,13 +1,22 @@ + */ class Ext_Users_Member extends DataExtension { private static $db = array( "VerificationCode" => "Varchar(40)" ); - private static $has_many = array(); - + /** + * Is the current member verified? + * + * @return boolean + */ public function isVerified() { return Permission::checkMember($this->owner, "USERS_VERIFIED"); @@ -17,7 +26,8 @@ public function isVerified() * Register a new user account using the provided data * and then return the current member * - * @param array $data + * @param array $data Array of data to create member from + * * @return Member */ public function Register($data) @@ -36,9 +46,11 @@ public function Register($data) // Add member to any groups that have been specified if (count(Users::config()->new_user_groups)) { - $groups = Group::get()->filter(array( + $groups = Group::get()->filter( + array( "Code" => Users::config()->new_user_groups - )); + ) + ); foreach ($groups as $group) { $group->Members()->add($this->owner); @@ -82,13 +94,17 @@ public function sendVerificationEmail() ->setTo($this->owner->Email) ->setSubject($subject) ->setTemplate('UsersAccountVerification') - ->populateTemplate(ArrayData::create(array( - "Link" => Controller::join_links( - $controller->AbsoluteLink("verify"), - $this->owner->ID, - $this->owner->VerificationCode + ->populateTemplate( + ArrayData::create( + array( + "Link" => Controller::join_links( + $controller->AbsoluteLink("verify"), + $this->owner->ID, + $this->owner->VerificationCode + ) + ) ) - ))); + ); $email->send(); diff --git a/code/forms/Users_EditAccountForm.php b/code/forms/Users_EditAccountForm.php index c2be0d2..341465e 100755 --- a/code/forms/Users_EditAccountForm.php +++ b/code/forms/Users_EditAccountForm.php @@ -1,11 +1,19 @@ + */ class Users_EditAccountForm extends Form { /** * These fields will be ignored by the `Users_EditAccountForm` * when generating fields + * + * @var array */ private static $ignore_member_fields = array( "LastVisited", @@ -20,6 +28,14 @@ class Users_EditAccountForm extends Form "BlogProfileImage" ); + /** + * Setup this form + * + * @param Controller $controller Current Controller + * @param string $name Name of this form + * + * @return void + */ public function __construct($controller, $name = "Users_EditAccountForm") { $member = Member::singleton(); @@ -85,6 +101,8 @@ public function __construct($controller, $name = "Users_EditAccountForm") * Register a new member * * @param array $data User submitted data + * + * @return SS_HTTPResponse */ public function doUpdate($data) {