Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Member often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Member, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 62 | class Member extends DataObject |
||
| 63 | { |
||
| 64 | |||
| 65 | private static $db = array( |
||
|
|
|||
| 66 | 'FirstName' => 'Varchar', |
||
| 67 | 'Surname' => 'Varchar', |
||
| 68 | 'Email' => 'Varchar(254)', // See RFC 5321, Section 4.5.3.1.3. (256 minus the < and > character) |
||
| 69 | 'TempIDHash' => 'Varchar(160)', // Temporary id used for cms re-authentication |
||
| 70 | 'TempIDExpired' => 'Datetime', // Expiry of temp login |
||
| 71 | 'Password' => 'Varchar(160)', |
||
| 72 | 'AutoLoginHash' => 'Varchar(160)', // Used to auto-login the user on password reset |
||
| 73 | 'AutoLoginExpired' => 'Datetime', |
||
| 74 | // This is an arbitrary code pointing to a PasswordEncryptor instance, |
||
| 75 | // not an actual encryption algorithm. |
||
| 76 | // Warning: Never change this field after its the first password hashing without |
||
| 77 | // providing a new cleartext password as well. |
||
| 78 | 'PasswordEncryption' => "Varchar(50)", |
||
| 79 | 'Salt' => 'Varchar(50)', |
||
| 80 | 'PasswordExpiry' => 'Date', |
||
| 81 | 'LockedOutUntil' => 'Datetime', |
||
| 82 | 'Locale' => 'Varchar(6)', |
||
| 83 | // handled in registerFailedLogin(), only used if $lock_out_after_incorrect_logins is set |
||
| 84 | 'FailedLoginCount' => 'Int', |
||
| 85 | ); |
||
| 86 | |||
| 87 | private static $belongs_many_many = array( |
||
| 88 | 'Groups' => Group::class, |
||
| 89 | ); |
||
| 90 | |||
| 91 | private static $has_many = array( |
||
| 92 | 'LoggedPasswords' => MemberPassword::class, |
||
| 93 | 'RememberLoginHashes' => RememberLoginHash::class, |
||
| 94 | ); |
||
| 95 | |||
| 96 | private static $table_name = "Member"; |
||
| 97 | |||
| 98 | private static $default_sort = '"Surname", "FirstName"'; |
||
| 99 | |||
| 100 | private static $indexes = array( |
||
| 101 | 'Email' => true, |
||
| 102 | //Removed due to duplicate null values causing MSSQL problems |
||
| 103 | //'AutoLoginHash' => Array('type'=>'unique', 'value'=>'AutoLoginHash', 'ignoreNulls'=>true) |
||
| 104 | ); |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @config |
||
| 108 | * @var boolean |
||
| 109 | */ |
||
| 110 | private static $notify_password_change = false; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * All searchable database columns |
||
| 114 | * in this object, currently queried |
||
| 115 | * with a "column LIKE '%keywords%' |
||
| 116 | * statement. |
||
| 117 | * |
||
| 118 | * @var array |
||
| 119 | * @todo Generic implementation of $searchable_fields on DataObject, |
||
| 120 | * with definition for different searching algorithms |
||
| 121 | * (LIKE, FULLTEXT) and default FormFields to construct a searchform. |
||
| 122 | */ |
||
| 123 | private static $searchable_fields = array( |
||
| 124 | 'FirstName', |
||
| 125 | 'Surname', |
||
| 126 | 'Email', |
||
| 127 | ); |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @config |
||
| 131 | * @var array |
||
| 132 | */ |
||
| 133 | private static $summary_fields = array( |
||
| 134 | 'FirstName', |
||
| 135 | 'Surname', |
||
| 136 | 'Email', |
||
| 137 | ); |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @config |
||
| 141 | * @var array |
||
| 142 | */ |
||
| 143 | private static $casting = array( |
||
| 144 | 'Name' => 'Varchar', |
||
| 145 | ); |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Internal-use only fields |
||
| 149 | * |
||
| 150 | * @config |
||
| 151 | * @var array |
||
| 152 | */ |
||
| 153 | private static $hidden_fields = array( |
||
| 154 | 'AutoLoginHash', |
||
| 155 | 'AutoLoginExpired', |
||
| 156 | 'PasswordEncryption', |
||
| 157 | 'PasswordExpiry', |
||
| 158 | 'LockedOutUntil', |
||
| 159 | 'TempIDHash', |
||
| 160 | 'TempIDExpired', |
||
| 161 | 'Salt', |
||
| 162 | ); |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @config |
||
| 166 | * @var array See {@link set_title_columns()} |
||
| 167 | */ |
||
| 168 | private static $title_format = null; |
||
| 169 | |||
| 170 | /** |
||
| 171 | * The unique field used to identify this member. |
||
| 172 | * By default, it's "Email", but another common |
||
| 173 | * field could be Username. |
||
| 174 | * |
||
| 175 | * @config |
||
| 176 | * @var string |
||
| 177 | * @skipUpgrade |
||
| 178 | */ |
||
| 179 | private static $unique_identifier_field = 'Email'; |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Object for validating user's password |
||
| 183 | * |
||
| 184 | * @config |
||
| 185 | * @var PasswordValidator |
||
| 186 | */ |
||
| 187 | private static $password_validator = null; |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @config |
||
| 191 | * The number of days that a password should be valid for. |
||
| 192 | * By default, this is null, which means that passwords never expire |
||
| 193 | */ |
||
| 194 | private static $password_expiry_days = null; |
||
| 195 | |||
| 196 | /** |
||
| 197 | * @config |
||
| 198 | * @var Int Number of incorrect logins after which |
||
| 199 | * the user is blocked from further attempts for the timespan |
||
| 200 | * defined in {@link $lock_out_delay_mins}. |
||
| 201 | */ |
||
| 202 | private static $lock_out_after_incorrect_logins = 10; |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @config |
||
| 206 | * @var integer Minutes of enforced lockout after incorrect password attempts. |
||
| 207 | * Only applies if {@link $lock_out_after_incorrect_logins} greater than 0. |
||
| 208 | */ |
||
| 209 | private static $lock_out_delay_mins = 15; |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @config |
||
| 213 | * @var String If this is set, then a session cookie with the given name will be set on log-in, |
||
| 214 | * and cleared on logout. |
||
| 215 | */ |
||
| 216 | private static $login_marker_cookie = null; |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Indicates that when a {@link Member} logs in, Member:session_regenerate_id() |
||
| 220 | * should be called as a security precaution. |
||
| 221 | * |
||
| 222 | * This doesn't always work, especially if you're trying to set session cookies |
||
| 223 | * across an entire site using the domain parameter to session_set_cookie_params() |
||
| 224 | * |
||
| 225 | * @config |
||
| 226 | * @var boolean |
||
| 227 | */ |
||
| 228 | private static $session_regenerate_id = true; |
||
| 229 | |||
| 230 | |||
| 231 | /** |
||
| 232 | * Default lifetime of temporary ids. |
||
| 233 | * |
||
| 234 | * This is the period within which a user can be re-authenticated within the CMS by entering only their password |
||
| 235 | * and without losing their workspace. |
||
| 236 | * |
||
| 237 | * Any session expiration outside of this time will require them to login from the frontend using their full |
||
| 238 | * username and password. |
||
| 239 | * |
||
| 240 | * Defaults to 72 hours. Set to zero to disable expiration. |
||
| 241 | * |
||
| 242 | * @config |
||
| 243 | * @var int Lifetime in seconds |
||
| 244 | */ |
||
| 245 | private static $temp_id_lifetime = 259200; |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Ensure the locale is set to something sensible by default. |
||
| 249 | */ |
||
| 250 | public function populateDefaults() |
||
| 255 | |||
| 256 | public function requireDefaultRecords() |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Get the default admin record if it exists, or creates it otherwise if enabled |
||
| 265 | * |
||
| 266 | * @return Member |
||
| 267 | */ |
||
| 268 | public static function default_admin() |
||
| 305 | |||
| 306 | /** |
||
| 307 | * Check if the passed password matches the stored one (if the member is not locked out). |
||
| 308 | * |
||
| 309 | * @param string $password |
||
| 310 | * @return ValidationResult |
||
| 311 | */ |
||
| 312 | public function checkPassword($password) |
||
| 343 | |||
| 344 | /** |
||
| 345 | * Check if this user is the currently configured default admin |
||
| 346 | * |
||
| 347 | * @return bool |
||
| 348 | */ |
||
| 349 | public function isDefaultAdmin() |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Returns a valid {@link ValidationResult} if this member can currently log in, or an invalid |
||
| 357 | * one with error messages to display if the member is locked out. |
||
| 358 | * |
||
| 359 | * You can hook into this with a "canLogIn" method on an attached extension. |
||
| 360 | * |
||
| 361 | * @return ValidationResult |
||
| 362 | */ |
||
| 363 | public function canLogIn() |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Returns true if this user is locked out |
||
| 386 | * |
||
| 387 | * @return bool |
||
| 388 | */ |
||
| 389 | public function isLockedOut() |
||
| 397 | |||
| 398 | /** |
||
| 399 | * Set a {@link PasswordValidator} object to use to validate member's passwords. |
||
| 400 | * |
||
| 401 | * @param PasswordValidator $pv |
||
| 402 | */ |
||
| 403 | public static function set_password_validator($pv) |
||
| 407 | |||
| 408 | /** |
||
| 409 | * Returns the current {@link PasswordValidator} |
||
| 410 | * |
||
| 411 | * @return PasswordValidator |
||
| 412 | */ |
||
| 413 | public static function password_validator() |
||
| 417 | |||
| 418 | |||
| 419 | public function isPasswordExpired() |
||
| 427 | |||
| 428 | /** |
||
| 429 | * @deprecated 5.0.0 Use Security::setCurrentUser() or IdentityStore::logIn() |
||
| 430 | * |
||
| 431 | */ |
||
| 432 | public function logIn() |
||
| 440 | |||
| 441 | /** |
||
| 442 | * Called before a member is logged in via session/cookie/etc |
||
| 443 | */ |
||
| 444 | public function beforeMemberLoggedIn() |
||
| 449 | |||
| 450 | /** |
||
| 451 | * Called after a member is logged in via session/cookie/etc |
||
| 452 | */ |
||
| 453 | public function afterMemberLoggedIn() |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Trigger regeneration of TempID. |
||
| 470 | * |
||
| 471 | * This should be performed any time the user presents their normal identification (normally Email) |
||
| 472 | * and is successfully authenticated. |
||
| 473 | */ |
||
| 474 | public function regenerateTempID() |
||
| 483 | |||
| 484 | /** |
||
| 485 | * Check if the member ID logged in session actually |
||
| 486 | * has a database record of the same ID. If there is |
||
| 487 | * no logged in user, FALSE is returned anyway. |
||
| 488 | * |
||
| 489 | * @deprecated Not needed anymore, as it returns Security::getCurrentUser(); |
||
| 490 | * |
||
| 491 | * @return boolean TRUE record found FALSE no record found |
||
| 492 | */ |
||
| 493 | public static function logged_in_session_exists() |
||
| 508 | |||
| 509 | /** |
||
| 510 | * @deprecated Use Security::setCurrentUser(null) or an IdentityStore |
||
| 511 | * Logs this member out. |
||
| 512 | */ |
||
| 513 | public function logOut() |
||
| 526 | |||
| 527 | /** |
||
| 528 | * Utility for generating secure password hashes for this member. |
||
| 529 | * |
||
| 530 | * @param string $string |
||
| 531 | * @return string |
||
| 532 | * @throws PasswordEncryptor_NotFoundException |
||
| 533 | */ |
||
| 534 | public function encryptWithUserSettings($string) |
||
| 551 | |||
| 552 | /** |
||
| 553 | * Generate an auto login token which can be used to reset the password, |
||
| 554 | * at the same time hashing it and storing in the database. |
||
| 555 | * |
||
| 556 | * @param int $lifetime The lifetime of the auto login hash in days (by default 2 days) |
||
| 557 | * |
||
| 558 | * @returns string Token that should be passed to the client (but NOT persisted). |
||
| 559 | * |
||
| 560 | * @todo Make it possible to handle database errors such as a "duplicate key" error |
||
| 561 | */ |
||
| 562 | public function generateAutologinTokenAndStoreHash($lifetime = 2) |
||
| 579 | |||
| 580 | /** |
||
| 581 | * Check the token against the member. |
||
| 582 | * |
||
| 583 | * @param string $autologinToken |
||
| 584 | * |
||
| 585 | * @returns bool Is token valid? |
||
| 586 | */ |
||
| 587 | public function validateAutoLoginToken($autologinToken) |
||
| 594 | |||
| 595 | /** |
||
| 596 | * Return the member for the auto login hash |
||
| 597 | * |
||
| 598 | * @param string $hash The hash key |
||
| 599 | * @param bool $login Should the member be logged in? |
||
| 600 | * |
||
| 601 | * @return Member the matching member, if valid |
||
| 602 | * @return Member |
||
| 603 | */ |
||
| 604 | public static function member_from_autologinhash($hash, $login = false) |
||
| 618 | |||
| 619 | /** |
||
| 620 | * Find a member record with the given TempIDHash value |
||
| 621 | * |
||
| 622 | * @param string $tempid |
||
| 623 | * @return Member |
||
| 624 | */ |
||
| 625 | public static function member_from_tempid($tempid) |
||
| 637 | |||
| 638 | /** |
||
| 639 | * Returns the fields for the member form - used in the registration/profile module. |
||
| 640 | * It should return fields that are editable by the admin and the logged-in user. |
||
| 641 | * |
||
| 642 | * @return FieldList Returns a {@link FieldList} containing the fields for |
||
| 643 | * the member form. |
||
| 644 | */ |
||
| 645 | public function getMemberFormFields() |
||
| 665 | |||
| 666 | /** |
||
| 667 | * Builds "Change / Create Password" field for this member |
||
| 668 | * |
||
| 669 | * @return ConfirmedPasswordField |
||
| 670 | */ |
||
| 671 | public function getMemberPasswordField() |
||
| 696 | |||
| 697 | |||
| 698 | /** |
||
| 699 | * Returns the {@link RequiredFields} instance for the Member object. This |
||
| 700 | * Validator is used when saving a {@link CMSProfileController} or added to |
||
| 701 | * any form responsible for saving a users data. |
||
| 702 | * |
||
| 703 | * To customize the required fields, add a {@link DataExtension} to member |
||
| 704 | * calling the `updateValidator()` method. |
||
| 705 | * |
||
| 706 | * @return Member_Validator |
||
| 707 | */ |
||
| 708 | public function getValidator() |
||
| 716 | |||
| 717 | |||
| 718 | /** |
||
| 719 | * Returns the current logged in user |
||
| 720 | * |
||
| 721 | * @deprecated 5.0.0 use Security::getCurrentUser() |
||
| 722 | * |
||
| 723 | * @return Member |
||
| 724 | */ |
||
| 725 | public static function currentUser() |
||
| 734 | |||
| 735 | /** |
||
| 736 | * Temporarily act as the specified user, limited to a $callback, but |
||
| 737 | * without logging in as that user. |
||
| 738 | * |
||
| 739 | * E.g. |
||
| 740 | * <code> |
||
| 741 | * Member::logInAs(Security::findAnAdministrator(), function() { |
||
| 742 | * $record->write(); |
||
| 743 | * }); |
||
| 744 | * </code> |
||
| 745 | * |
||
| 746 | * @param Member|null|int $member Member or member ID to log in as. |
||
| 747 | * Set to null or 0 to act as a logged out user. |
||
| 748 | * @param $callback |
||
| 749 | */ |
||
| 750 | public static function actAs($member, $callback) |
||
| 766 | |||
| 767 | /** |
||
| 768 | * Get the ID of the current logged in user |
||
| 769 | * |
||
| 770 | * @deprecated 5.0.0 use Security::getCurrentUser() |
||
| 771 | * |
||
| 772 | * @return int Returns the ID of the current logged in user or 0. |
||
| 773 | */ |
||
| 774 | public static function currentUserID() |
||
| 787 | |||
| 788 | /* |
||
| 789 | * Generate a random password, with randomiser to kick in if there's no words file on the |
||
| 790 | * filesystem. |
||
| 791 | * |
||
| 792 | * @return string Returns a random password. |
||
| 793 | */ |
||
| 794 | public static function create_new_password() |
||
| 816 | |||
| 817 | /** |
||
| 818 | * Event handler called before writing to the database. |
||
| 819 | */ |
||
| 820 | public function onBeforeWrite() |
||
| 911 | |||
| 912 | public function onAfterWrite() |
||
| 922 | |||
| 923 | public function onAfterDelete() |
||
| 930 | |||
| 931 | /** |
||
| 932 | * Delete the MemberPassword objects that are associated to this user |
||
| 933 | * |
||
| 934 | * @return $this |
||
| 935 | */ |
||
| 936 | protected function deletePasswordLogs() |
||
| 945 | |||
| 946 | /** |
||
| 947 | * Filter out admin groups to avoid privilege escalation, |
||
| 948 | * If any admin groups are requested, deny the whole save operation. |
||
| 949 | * |
||
| 950 | * @param array $ids Database IDs of Group records |
||
| 951 | * @return bool True if the change can be accepted |
||
| 952 | */ |
||
| 953 | public function onChangeGroups($ids) |
||
| 966 | |||
| 967 | |||
| 968 | /** |
||
| 969 | * Check if the member is in one of the given groups. |
||
| 970 | * |
||
| 971 | * @param array|SS_List $groups Collection of {@link Group} DataObjects to check |
||
| 972 | * @param boolean $strict Only determine direct group membership if set to true (Default: false) |
||
| 973 | * @return bool Returns TRUE if the member is in one of the given groups, otherwise FALSE. |
||
| 974 | */ |
||
| 975 | public function inGroups($groups, $strict = false) |
||
| 987 | |||
| 988 | |||
| 989 | /** |
||
| 990 | * Check if the member is in the given group or any parent groups. |
||
| 991 | * |
||
| 992 | * @param int|Group|string $group Group instance, Group Code or ID |
||
| 993 | * @param boolean $strict Only determine direct group membership if set to TRUE (Default: FALSE) |
||
| 994 | * @return bool Returns TRUE if the member is in the given group, otherwise FALSE. |
||
| 995 | */ |
||
| 996 | public function inGroup($group, $strict = false) |
||
| 1025 | |||
| 1026 | /** |
||
| 1027 | * Adds the member to a group. This will create the group if the given |
||
| 1028 | * group code does not return a valid group object. |
||
| 1029 | * |
||
| 1030 | * @param string $groupcode |
||
| 1031 | * @param string $title Title of the group |
||
| 1032 | */ |
||
| 1033 | public function addToGroupByCode($groupcode, $title = "") |
||
| 1054 | |||
| 1055 | /** |
||
| 1056 | * Removes a member from a group. |
||
| 1057 | * |
||
| 1058 | * @param string $groupcode |
||
| 1059 | */ |
||
| 1060 | public function removeFromGroupByCode($groupcode) |
||
| 1068 | |||
| 1069 | /** |
||
| 1070 | * @param array $columns Column names on the Member record to show in {@link getTitle()}. |
||
| 1071 | * @param String $sep Separator |
||
| 1072 | */ |
||
| 1073 | public static function set_title_columns($columns, $sep = ' ') |
||
| 1080 | |||
| 1081 | //------------------- HELPER METHODS -----------------------------------// |
||
| 1082 | |||
| 1083 | /** |
||
| 1084 | * Get the complete name of the member, by default in the format "<Surname>, <FirstName>". |
||
| 1085 | * Falls back to showing either field on its own. |
||
| 1086 | * |
||
| 1087 | * You can overload this getter with {@link set_title_format()} |
||
| 1088 | * and {@link set_title_sql()}. |
||
| 1089 | * |
||
| 1090 | * @return string Returns the first- and surname of the member. If the ID |
||
| 1091 | * of the member is equal 0, only the surname is returned. |
||
| 1092 | */ |
||
| 1093 | public function getTitle() |
||
| 1118 | |||
| 1119 | /** |
||
| 1120 | * Return a SQL CONCAT() fragment suitable for a SELECT statement. |
||
| 1121 | * Useful for custom queries which assume a certain member title format. |
||
| 1122 | * |
||
| 1123 | * @return String SQL |
||
| 1124 | */ |
||
| 1125 | public static function get_title_sql() |
||
| 1148 | |||
| 1149 | |||
| 1150 | /** |
||
| 1151 | * Get the complete name of the member |
||
| 1152 | * |
||
| 1153 | * @return string Returns the first- and surname of the member. |
||
| 1154 | */ |
||
| 1155 | public function getName() |
||
| 1159 | |||
| 1160 | |||
| 1161 | /** |
||
| 1162 | * Set first- and surname |
||
| 1163 | * |
||
| 1164 | * This method assumes that the last part of the name is the surname, e.g. |
||
| 1165 | * <i>A B C</i> will result in firstname <i>A B</i> and surname <i>C</i> |
||
| 1166 | * |
||
| 1167 | * @param string $name The name |
||
| 1168 | */ |
||
| 1169 | public function setName($name) |
||
| 1175 | |||
| 1176 | |||
| 1177 | /** |
||
| 1178 | * Alias for {@link setName} |
||
| 1179 | * |
||
| 1180 | * @param string $name The name |
||
| 1181 | * @see setName() |
||
| 1182 | */ |
||
| 1183 | public function splitName($name) |
||
| 1187 | |||
| 1188 | /** |
||
| 1189 | * Return the date format based on the user's chosen locale, |
||
| 1190 | * falling back to the default format defined by the {@link i18n.get_locale()} setting. |
||
| 1191 | * |
||
| 1192 | * @return string ISO date format |
||
| 1193 | */ |
||
| 1194 | View Code Duplication | public function getDateFormat() |
|
| 1207 | |||
| 1208 | /** |
||
| 1209 | * Get user locale |
||
| 1210 | */ |
||
| 1211 | public function getLocale() |
||
| 1220 | |||
| 1221 | /** |
||
| 1222 | * Return the time format based on the user's chosen locale, |
||
| 1223 | * falling back to the default format defined by the {@link i18n.get_locale()} setting. |
||
| 1224 | * |
||
| 1225 | * @return string ISO date format |
||
| 1226 | */ |
||
| 1227 | View Code Duplication | public function getTimeFormat() |
|
| 1240 | |||
| 1241 | //---------------------------------------------------------------------// |
||
| 1242 | |||
| 1243 | |||
| 1244 | /** |
||
| 1245 | * Get a "many-to-many" map that holds for all members their group memberships, |
||
| 1246 | * including any parent groups where membership is implied. |
||
| 1247 | * Use {@link DirectGroups()} to only retrieve the group relations without inheritance. |
||
| 1248 | * |
||
| 1249 | * @todo Push all this logic into Member_GroupSet's getIterator()? |
||
| 1250 | * @return Member_Groupset |
||
| 1251 | */ |
||
| 1252 | public function Groups() |
||
| 1261 | |||
| 1262 | /** |
||
| 1263 | * @return ManyManyList |
||
| 1264 | */ |
||
| 1265 | public function DirectGroups() |
||
| 1269 | |||
| 1270 | /** |
||
| 1271 | * Get a member SQLMap of members in specific groups |
||
| 1272 | * |
||
| 1273 | * If no $groups is passed, all members will be returned |
||
| 1274 | * |
||
| 1275 | * @param mixed $groups - takes a SS_List, an array or a single Group.ID |
||
| 1276 | * @return Map Returns an Map that returns all Member data. |
||
| 1277 | */ |
||
| 1278 | public static function map_in_groups($groups = null) |
||
| 1307 | |||
| 1308 | |||
| 1309 | /** |
||
| 1310 | * Get a map of all members in the groups given that have CMS permissions |
||
| 1311 | * |
||
| 1312 | * If no groups are passed, all groups with CMS permissions will be used. |
||
| 1313 | * |
||
| 1314 | * @param array $groups Groups to consider or NULL to use all groups with |
||
| 1315 | * CMS permissions. |
||
| 1316 | * @return Map Returns a map of all members in the groups given that |
||
| 1317 | * have CMS permissions. |
||
| 1318 | */ |
||
| 1319 | public static function mapInCMSGroups($groups = null) |
||
| 1371 | |||
| 1372 | |||
| 1373 | /** |
||
| 1374 | * Get the groups in which the member is NOT in |
||
| 1375 | * |
||
| 1376 | * When passed an array of groups, and a component set of groups, this |
||
| 1377 | * function will return the array of groups the member is NOT in. |
||
| 1378 | * |
||
| 1379 | * @param array $groupList An array of group code names. |
||
| 1380 | * @param array $memberGroups A component set of groups (if set to NULL, |
||
| 1381 | * $this->groups() will be used) |
||
| 1382 | * @return array Groups in which the member is NOT in. |
||
| 1383 | */ |
||
| 1384 | public function memberNotInGroups($groupList, $memberGroups = null) |
||
| 1399 | |||
| 1400 | |||
| 1401 | /** |
||
| 1402 | * Return a {@link FieldList} of fields that would appropriate for editing |
||
| 1403 | * this member. |
||
| 1404 | * |
||
| 1405 | * @return FieldList Return a FieldList of fields that would appropriate for |
||
| 1406 | * editing this member. |
||
| 1407 | */ |
||
| 1408 | public function getCMSFields() |
||
| 1480 | |||
| 1481 | /** |
||
| 1482 | * @param bool $includerelations Indicate if the labels returned include relation fields |
||
| 1483 | * @return array |
||
| 1484 | */ |
||
| 1485 | public function fieldLabels($includerelations = true) |
||
| 1508 | |||
| 1509 | /** |
||
| 1510 | * Users can view their own record. |
||
| 1511 | * Otherwise they'll need ADMIN or CMS_ACCESS_SecurityAdmin permissions. |
||
| 1512 | * This is likely to be customized for social sites etc. with a looser permission model. |
||
| 1513 | * |
||
| 1514 | * @param Member $member |
||
| 1515 | * @return bool |
||
| 1516 | */ |
||
| 1517 | public function canView($member = null) |
||
| 1541 | |||
| 1542 | /** |
||
| 1543 | * Users can edit their own record. |
||
| 1544 | * Otherwise they'll need ADMIN or CMS_ACCESS_SecurityAdmin permissions |
||
| 1545 | * |
||
| 1546 | * @param Member $member |
||
| 1547 | * @return bool |
||
| 1548 | */ |
||
| 1549 | View Code Duplication | public function canEdit($member = null) |
|
| 1578 | |||
| 1579 | /** |
||
| 1580 | * Users can edit their own record. |
||
| 1581 | * Otherwise they'll need ADMIN or CMS_ACCESS_SecurityAdmin permissions |
||
| 1582 | * |
||
| 1583 | * @param Member $member |
||
| 1584 | * @return bool |
||
| 1585 | */ |
||
| 1586 | View Code Duplication | public function canDelete($member = null) |
|
| 1619 | |||
| 1620 | /** |
||
| 1621 | * Validate this member object. |
||
| 1622 | */ |
||
| 1623 | public function validate() |
||
| 1641 | |||
| 1642 | /** |
||
| 1643 | * Change password. This will cause rehashing according to |
||
| 1644 | * the `PasswordEncryption` property. |
||
| 1645 | * |
||
| 1646 | * @param string $password Cleartext password |
||
| 1647 | * @return ValidationResult |
||
| 1648 | */ |
||
| 1649 | public function changePassword($password) |
||
| 1661 | |||
| 1662 | /** |
||
| 1663 | * Tell this member that someone made a failed attempt at logging in as them. |
||
| 1664 | * This can be used to lock the user out temporarily if too many failed attempts are made. |
||
| 1665 | */ |
||
| 1666 | public function registerFailedLogin() |
||
| 1681 | |||
| 1682 | /** |
||
| 1683 | * Tell this member that a successful login has been made |
||
| 1684 | */ |
||
| 1685 | public function registerSuccessfulLogin() |
||
| 1693 | |||
| 1694 | /** |
||
| 1695 | * Get the HtmlEditorConfig for this user to be used in the CMS. |
||
| 1696 | * This is set by the group. If multiple configurations are set, |
||
| 1697 | * the one with the highest priority wins. |
||
| 1698 | * |
||
| 1699 | * @return string |
||
| 1700 | */ |
||
| 1701 | public function getHtmlEditorConfigForCMS() |
||
| 1720 | } |
||
| 1721 |