From 27ddc38890fa2709ac419eccf854ab6b439f0d9a Mon Sep 17 00:00:00 2001 From: Morven Lewis-Everley Date: Sat, 28 Apr 2018 16:00:16 +0100 Subject: [PATCH] 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) {