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 Security 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 Security, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 34 | class Security extends Controller implements TemplateGlobalProvider |
||
| 35 | { |
||
| 36 | |||
| 37 | private static $allowed_actions = array( |
||
|
|
|||
| 38 | 'index', |
||
| 39 | 'login', |
||
| 40 | 'logout', |
||
| 41 | 'basicauthlogin', |
||
| 42 | 'lostpassword', |
||
| 43 | 'passwordsent', |
||
| 44 | 'changepassword', |
||
| 45 | 'ping', |
||
| 46 | ); |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Default user name. {@link setDefaultAdmin()} |
||
| 50 | * |
||
| 51 | * @var string |
||
| 52 | * @see setDefaultAdmin() |
||
| 53 | */ |
||
| 54 | protected static $default_username; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Default password. {@link setDefaultAdmin()} |
||
| 58 | * |
||
| 59 | * @var string |
||
| 60 | * @see setDefaultAdmin() |
||
| 61 | */ |
||
| 62 | protected static $default_password; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * If set to TRUE to prevent sharing of the session across several sites |
||
| 66 | * in the domain. |
||
| 67 | * |
||
| 68 | * @config |
||
| 69 | * @var bool |
||
| 70 | */ |
||
| 71 | private static $strict_path_checking = false; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * The password encryption algorithm to use by default. |
||
| 75 | * This is an arbitrary code registered through {@link PasswordEncryptor}. |
||
| 76 | * |
||
| 77 | * @config |
||
| 78 | * @var string |
||
| 79 | */ |
||
| 80 | private static $password_encryption_algorithm = 'blowfish'; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Showing "Remember me"-checkbox |
||
| 84 | * on loginform, and saving encrypted credentials to a cookie. |
||
| 85 | * |
||
| 86 | * @config |
||
| 87 | * @var bool |
||
| 88 | */ |
||
| 89 | private static $autologin_enabled = true; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Determine if login username may be remembered between login sessions |
||
| 93 | * If set to false this will disable autocomplete and prevent username persisting in the session |
||
| 94 | * |
||
| 95 | * @config |
||
| 96 | * @var bool |
||
| 97 | */ |
||
| 98 | private static $remember_username = true; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Location of word list to use for generating passwords |
||
| 102 | * |
||
| 103 | * @config |
||
| 104 | * @var string |
||
| 105 | */ |
||
| 106 | private static $word_list = './wordlist.txt'; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @config |
||
| 110 | * @var string |
||
| 111 | */ |
||
| 112 | private static $template = 'BlankPage'; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Template thats used to render the pages. |
||
| 116 | * |
||
| 117 | * @var string |
||
| 118 | * @config |
||
| 119 | */ |
||
| 120 | private static $template_main = 'Page'; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Class to use for page rendering |
||
| 124 | * |
||
| 125 | * @var string |
||
| 126 | * @config |
||
| 127 | */ |
||
| 128 | private static $page_class = Page::class; |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Default message set used in permission failures. |
||
| 132 | * |
||
| 133 | * @config |
||
| 134 | * @var array|string |
||
| 135 | */ |
||
| 136 | private static $default_message_set; |
||
| 137 | |||
| 138 | /** |
||
| 139 | * Random secure token, can be used as a crypto key internally. |
||
| 140 | * Generate one through 'sake dev/generatesecuretoken'. |
||
| 141 | * |
||
| 142 | * @config |
||
| 143 | * @var String |
||
| 144 | */ |
||
| 145 | private static $token; |
||
| 146 | |||
| 147 | /** |
||
| 148 | * The default login URL |
||
| 149 | * |
||
| 150 | * @config |
||
| 151 | * |
||
| 152 | * @var string |
||
| 153 | */ |
||
| 154 | private static $login_url = "Security/login"; |
||
| 155 | |||
| 156 | /** |
||
| 157 | * The default logout URL |
||
| 158 | * |
||
| 159 | * @config |
||
| 160 | * |
||
| 161 | * @var string |
||
| 162 | */ |
||
| 163 | private static $logout_url = "Security/logout"; |
||
| 164 | |||
| 165 | /** |
||
| 166 | * The default lost password URL |
||
| 167 | * |
||
| 168 | * @config |
||
| 169 | * |
||
| 170 | * @var string |
||
| 171 | */ |
||
| 172 | private static $lost_password_url = "Security/lostpassword"; |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Value of X-Frame-Options header |
||
| 176 | * |
||
| 177 | * @config |
||
| 178 | * @var string |
||
| 179 | */ |
||
| 180 | private static $frame_options = 'SAMEORIGIN'; |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Value of the X-Robots-Tag header (for the Security section) |
||
| 184 | * |
||
| 185 | * @config |
||
| 186 | * @var string |
||
| 187 | */ |
||
| 188 | private static $robots_tag = 'noindex, nofollow'; |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Enable or disable recording of login attempts |
||
| 192 | * through the {@link LoginRecord} object. |
||
| 193 | * |
||
| 194 | * @config |
||
| 195 | * @var boolean $login_recording |
||
| 196 | */ |
||
| 197 | private static $login_recording = false; |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @var boolean If set to TRUE or FALSE, {@link database_is_ready()} |
||
| 201 | * will always return FALSE. Used for unit testing. |
||
| 202 | */ |
||
| 203 | protected static $force_database_is_ready = null; |
||
| 204 | |||
| 205 | /** |
||
| 206 | * When the database has once been verified as ready, it will not do the |
||
| 207 | * checks again. |
||
| 208 | * |
||
| 209 | * @var bool |
||
| 210 | */ |
||
| 211 | protected static $database_is_ready = false; |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @var string Default authenticator to use when none is given |
||
| 215 | */ |
||
| 216 | protected static $default_authenticator = 'default'; |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @var Authenticator[] available authenticators |
||
| 220 | */ |
||
| 221 | protected static $authenticators = []; |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @var Member Currently logged in user (if available) |
||
| 225 | */ |
||
| 226 | protected static $currentUser; |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @return array |
||
| 230 | */ |
||
| 231 | public static function getAuthenticators() |
||
| 232 | { |
||
| 233 | return self::$authenticators; |
||
| 234 | } |
||
| 235 | |||
| 236 | /** |
||
| 237 | * @param array|Authenticator $authenticators |
||
| 238 | */ |
||
| 239 | public static function setAuthenticators(array $authenticators) |
||
| 240 | { |
||
| 241 | self::$authenticators = $authenticators; |
||
| 242 | } |
||
| 243 | |||
| 244 | /** |
||
| 245 | * @inheritdoc |
||
| 246 | */ |
||
| 247 | protected function init() |
||
| 248 | { |
||
| 249 | parent::init(); |
||
| 250 | |||
| 251 | // Prevent clickjacking, see https://developer.mozilla.org/en-US/docs/HTTP/X-Frame-Options |
||
| 252 | $frameOptions = static::config()->get('frame_options'); |
||
| 253 | if ($frameOptions) { |
||
| 254 | $this->getResponse()->addHeader('X-Frame-Options', $frameOptions); |
||
| 255 | } |
||
| 256 | |||
| 257 | // Prevent search engines from indexing the login page |
||
| 258 | $robotsTag = static::config()->get('robots_tag'); |
||
| 259 | if ($robotsTag) { |
||
| 260 | $this->getResponse()->addHeader('X-Robots-Tag', $robotsTag); |
||
| 261 | } |
||
| 262 | } |
||
| 263 | |||
| 264 | /** |
||
| 265 | * @inheritdoc |
||
| 266 | */ |
||
| 267 | public function index() |
||
| 268 | { |
||
| 269 | return $this->httpError(404); // no-op |
||
| 270 | } |
||
| 271 | |||
| 272 | /** |
||
| 273 | * Get the selected authenticator for this request |
||
| 274 | * |
||
| 275 | * @param $name string The identifier of the authenticator in your config |
||
| 276 | * @return Authenticator Class name of Authenticator |
||
| 277 | * @throws LogicException |
||
| 278 | */ |
||
| 279 | protected function getAuthenticator($name = 'default') |
||
| 280 | { |
||
| 281 | $authenticators = static::$authenticators; |
||
| 282 | |||
| 283 | if (isset($authenticators[$name])) { |
||
| 284 | return $authenticators[$name]; |
||
| 285 | } |
||
| 286 | |||
| 287 | throw new LogicException('No valid authenticator found'); |
||
| 288 | } |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Get all registered authenticators |
||
| 292 | * |
||
| 293 | * @param int $service The type of service that is requested |
||
| 294 | * @return array Return an array of Authenticator objects |
||
| 295 | */ |
||
| 296 | public function getApplicableAuthenticators($service = Authenticator::LOGIN) |
||
| 297 | { |
||
| 298 | $authenticators = static::$authenticators; |
||
| 299 | |||
| 300 | /** @var Authenticator $class */ |
||
| 301 | foreach ($authenticators as $name => $class) { |
||
| 302 | if (!($class->supportedServices() & $service)) { |
||
| 303 | unset($authenticators[$name]); |
||
| 304 | } |
||
| 305 | } |
||
| 306 | |||
| 307 | return $authenticators; |
||
| 308 | } |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Check if a given authenticator is registered |
||
| 312 | * |
||
| 313 | * @param string $authenticator The configured identifier of the authenicator |
||
| 314 | * @return bool Returns TRUE if the authenticator is registered, FALSE |
||
| 315 | * otherwise. |
||
| 316 | */ |
||
| 317 | public static function hasAuthenticator($authenticator) |
||
| 318 | { |
||
| 319 | $authenticators = static::$authenticators; |
||
| 320 | |||
| 321 | return !empty($authenticators[$authenticator]); |
||
| 322 | } |
||
| 323 | |||
| 324 | /** |
||
| 325 | * Register that we've had a permission failure trying to view the given page |
||
| 326 | * |
||
| 327 | * This will redirect to a login page. |
||
| 328 | * If you don't provide a messageSet, a default will be used. |
||
| 329 | * |
||
| 330 | * @param Controller $controller The controller that you were on to cause the permission |
||
| 331 | * failure. |
||
| 332 | * @param string|array $messageSet The message to show to the user. This |
||
| 333 | * can be a string, or a map of different |
||
| 334 | * messages for different contexts. |
||
| 335 | * If you pass an array, you can use the |
||
| 336 | * following keys: |
||
| 337 | * - default: The default message |
||
| 338 | * - alreadyLoggedIn: The message to |
||
| 339 | * show if the user |
||
| 340 | * is already logged |
||
| 341 | * in and lacks the |
||
| 342 | * permission to |
||
| 343 | * access the item. |
||
| 344 | * |
||
| 345 | * The alreadyLoggedIn value can contain a '%s' placeholder that will be replaced with a link |
||
| 346 | * to log in. |
||
| 347 | * @return HTTPResponse |
||
| 348 | */ |
||
| 349 | public static function permissionFailure($controller = null, $messageSet = null) |
||
| 350 | { |
||
| 351 | self::set_ignore_disallowed_actions(true); |
||
| 352 | |||
| 353 | if (!$controller) { |
||
| 354 | $controller = Controller::curr(); |
||
| 355 | } |
||
| 356 | |||
| 357 | if (Director::is_ajax()) { |
||
| 358 | $response = ($controller) ? $controller->getResponse() : new HTTPResponse(); |
||
| 359 | $response->setStatusCode(403); |
||
| 360 | if (!static::getCurrentUser()) { |
||
| 361 | $response->setBody( |
||
| 362 | _t('SilverStripe\\CMS\\Controllers\\ContentController.NOTLOGGEDIN', 'Not logged in') |
||
| 363 | ); |
||
| 364 | $response->setStatusDescription( |
||
| 365 | _t('SilverStripe\\CMS\\Controllers\\ContentController.NOTLOGGEDIN', 'Not logged in') |
||
| 366 | ); |
||
| 367 | // Tell the CMS to allow re-authentication |
||
| 368 | if (CMSSecurity::enabled()) { |
||
| 369 | $response->addHeader('X-Reauthenticate', '1'); |
||
| 370 | } |
||
| 371 | } |
||
| 372 | |||
| 373 | return $response; |
||
| 374 | } |
||
| 375 | |||
| 376 | // Prepare the messageSet provided |
||
| 377 | if (!$messageSet) { |
||
| 378 | if ($configMessageSet = static::config()->get('default_message_set')) { |
||
| 379 | $messageSet = $configMessageSet; |
||
| 380 | } else { |
||
| 381 | $messageSet = array( |
||
| 382 | 'default' => _t( |
||
| 383 | 'SilverStripe\\Security\\Security.NOTEPAGESECURED', |
||
| 384 | "That page is secured. Enter your credentials below and we will send " |
||
| 385 | . "you right along." |
||
| 386 | ), |
||
| 387 | 'alreadyLoggedIn' => _t( |
||
| 388 | 'SilverStripe\\Security\\Security.ALREADYLOGGEDIN', |
||
| 389 | "You don't have access to this page. If you have another account that " |
||
| 390 | . "can access that page, you can log in again below.", |
||
| 391 | "%s will be replaced with a link to log in." |
||
| 392 | ) |
||
| 393 | ); |
||
| 394 | } |
||
| 395 | } |
||
| 396 | |||
| 397 | if (!is_array($messageSet)) { |
||
| 398 | $messageSet = array('default' => $messageSet); |
||
| 399 | } |
||
| 400 | |||
| 401 | $member = static::getCurrentUser(); |
||
| 402 | |||
| 403 | // Work out the right message to show |
||
| 404 | if ($member && $member->exists()) { |
||
| 405 | $response = ($controller) ? $controller->getResponse() : new HTTPResponse(); |
||
| 406 | $response->setStatusCode(403); |
||
| 407 | |||
| 408 | //If 'alreadyLoggedIn' is not specified in the array, then use the default |
||
| 409 | //which should have been specified in the lines above |
||
| 410 | if (isset($messageSet['alreadyLoggedIn'])) { |
||
| 411 | $message = $messageSet['alreadyLoggedIn']; |
||
| 412 | } else { |
||
| 413 | $message = $messageSet['default']; |
||
| 414 | } |
||
| 415 | |||
| 416 | Security::singleton()->setLoginMessage($message, ValidationResult::TYPE_WARNING); |
||
| 417 | $loginResponse = Security::singleton()->login(); |
||
| 418 | if ($loginResponse instanceof HTTPResponse) { |
||
| 419 | return $loginResponse; |
||
| 420 | } |
||
| 421 | |||
| 422 | $response->setBody((string)$loginResponse); |
||
| 423 | |||
| 424 | $controller->extend('permissionDenied', $member); |
||
| 425 | |||
| 426 | return $response; |
||
| 427 | } else { |
||
| 428 | $message = $messageSet['default']; |
||
| 429 | } |
||
| 430 | |||
| 431 | Security::singleton()->setLoginMessage($message, ValidationResult::TYPE_WARNING); |
||
| 432 | |||
| 433 | Session::set("BackURL", $_SERVER['REQUEST_URI']); |
||
| 434 | |||
| 435 | // TODO AccessLogEntry needs an extension to handle permission denied errors |
||
| 436 | // Audit logging hook |
||
| 437 | $controller->extend('permissionDenied', $member); |
||
| 438 | |||
| 439 | return $controller->redirect(Controller::join_links( |
||
| 440 | Security::config()->uninherited('login_url'), |
||
| 441 | "?BackURL=" . urlencode($_SERVER['REQUEST_URI']) |
||
| 442 | )); |
||
| 443 | } |
||
| 444 | |||
| 445 | /** |
||
| 446 | * @param null|Member $currentUser |
||
| 447 | */ |
||
| 448 | public static function setCurrentUser($currentUser = null) |
||
| 452 | |||
| 453 | /** |
||
| 454 | * @return null|Member |
||
| 455 | */ |
||
| 456 | public static function getCurrentUser() |
||
| 457 | { |
||
| 458 | return self::$currentUser; |
||
| 459 | } |
||
| 460 | |||
| 461 | /** |
||
| 462 | * Get the login forms for all available authentication methods |
||
| 463 | * |
||
| 464 | * @deprecated 5.0.0 Now handled by {@link static::delegateToMultipleHandlers} |
||
| 465 | * |
||
| 466 | * @return array Returns an array of available login forms (array of Form |
||
| 467 | * objects). |
||
| 468 | * |
||
| 469 | */ |
||
| 470 | public function getLoginForms() |
||
| 481 | |||
| 482 | |||
| 483 | /** |
||
| 484 | * Get a link to a security action |
||
| 485 | * |
||
| 486 | * @param string $action Name of the action |
||
| 487 | * @return string Returns the link to the given action |
||
| 488 | */ |
||
| 489 | public function Link($action = null) |
||
| 494 | |||
| 495 | /** |
||
| 496 | * This action is available as a keep alive, so user |
||
| 497 | * sessions don't timeout. A common use is in the admin. |
||
| 498 | */ |
||
| 499 | public function ping() |
||
| 503 | |||
| 504 | /** |
||
| 505 | * Log the currently logged in user out |
||
| 506 | * |
||
| 507 | * Logging out without ID-parameter in the URL, will log the user out of all applicable Authenticators. |
||
| 508 | * |
||
| 509 | * Adding an ID will only log the user out of that Authentication method. |
||
| 510 | * |
||
| 511 | * Logging out of Default will <i>always</i> completely log out the user. |
||
| 512 | * |
||
| 513 | * @param bool $redirect Redirect the user back to where they came. |
||
| 514 | * - If it's false, the code calling logout() is |
||
| 515 | * responsible for sending the user where-ever |
||
| 516 | * they should go. |
||
| 517 | * @return HTTPResponse|null |
||
| 518 | */ |
||
| 519 | public function logout($redirect = true) |
||
| 548 | |||
| 549 | /** |
||
| 550 | * Perform pre-login checking and prepare a response if available prior to login |
||
| 551 | * |
||
| 552 | * @return HTTPResponse Substitute response object if the login process should be curcumvented. |
||
| 553 | * Returns null if should proceed as normal. |
||
| 554 | */ |
||
| 555 | protected function preLogin() |
||
| 588 | |||
| 589 | /** |
||
| 590 | * Prepare the controller for handling the response to this request |
||
| 591 | * |
||
| 592 | * @param string $title Title to use |
||
| 593 | * @return Controller |
||
| 594 | */ |
||
| 595 | protected function getResponseController($title) |
||
| 620 | |||
| 621 | /** |
||
| 622 | * Combine the given forms into a formset with a tabbed interface |
||
| 623 | * |
||
| 624 | * @param $forms |
||
| 625 | * @return string |
||
| 626 | */ |
||
| 627 | protected function generateLoginFormSet($forms) |
||
| 637 | |||
| 638 | /** |
||
| 639 | * Get the HTML Content for the $Content area during login |
||
| 640 | * |
||
| 641 | * @param string &$messageType Type of message, if available, passed back to caller |
||
| 642 | * @return string Message in HTML format |
||
| 643 | */ |
||
| 644 | protected function getLoginMessage(&$messageType = null) |
||
| 660 | |||
| 661 | /** |
||
| 662 | * Set the next message to display for the security login page. Defaults to warning |
||
| 663 | * |
||
| 664 | * @param string $message Message |
||
| 665 | * @param string $messageType Message type. One of ValidationResult::TYPE_* |
||
| 666 | * @param string $messageCast Message cast. One of ValidationResult::CAST_* |
||
| 667 | */ |
||
| 668 | public function setLoginMessage( |
||
| 677 | |||
| 678 | /** |
||
| 679 | * Clear login message |
||
| 680 | */ |
||
| 681 | public static function clearLoginMessage() |
||
| 685 | |||
| 686 | |||
| 687 | /** |
||
| 688 | * Show the "login" page |
||
| 689 | * |
||
| 690 | * For multiple authenticators, Security_MultiAuthenticatorLogin is used. |
||
| 691 | * See getTemplatesFor and getIncludeTemplate for how to override template logic |
||
| 692 | * |
||
| 693 | * @param $request |
||
| 694 | * @param int $service |
||
| 695 | * @return HTTPResponse|string Returns the "login" page as HTML code. |
||
| 696 | * @throws HTTPResponse_Exception |
||
| 697 | */ |
||
| 698 | public function login($request = null, $service = Authenticator::LOGIN) |
||
| 743 | |||
| 744 | /** |
||
| 745 | * Delegate to an number of handlers, extracting their forms and rendering a tabbed form-set. |
||
| 746 | * This is used to built the log-in page where there are multiple authenticators active. |
||
| 747 | * |
||
| 748 | * If a single handler is passed, delegateToHandler() will be called instead |
||
| 749 | * |
||
| 750 | * @param array|RequestHandler[] $handlers |
||
| 751 | * @param string $title The title of the form |
||
| 752 | * @param array $templates |
||
| 753 | * @return array|HTTPResponse|RequestHandler|DBHTMLText|string |
||
| 754 | */ |
||
| 755 | protected function delegateToMultipleHandlers(array $handlers, $title, array $templates) |
||
| 795 | |||
| 796 | /** |
||
| 797 | * Delegate to another RequestHandler, rendering any fragment arrays into an appropriate. |
||
| 798 | * controller. |
||
| 799 | * |
||
| 800 | * @param RequestHandler $handler |
||
| 801 | * @param string $title The title of the form |
||
| 802 | * @param array $templates |
||
| 803 | * @return array|HTTPResponse|RequestHandler|DBHTMLText|string |
||
| 804 | */ |
||
| 805 | protected function delegateToHandler(RequestHandler $handler, $title, array $templates = []) |
||
| 817 | |||
| 818 | /** |
||
| 819 | * Render the given fragments into a security page controller with the given title. |
||
| 820 | * @param string $title string The title to give the security page |
||
| 821 | * @param array $fragments A map of objects to render into the page, e.g. "Form" |
||
| 822 | * @param array $templates An array of templates to use for the render |
||
| 823 | * @return HTTPResponse|DBHTMLText |
||
| 824 | */ |
||
| 825 | protected function renderWrappedController($title, array $fragments, array $templates) |
||
| 852 | |||
| 853 | public function basicauthlogin() |
||
| 858 | |||
| 859 | /** |
||
| 860 | * Show the "lost password" page |
||
| 861 | * |
||
| 862 | * @return string Returns the "lost password" page as HTML code. |
||
| 863 | */ |
||
| 864 | View Code Duplication | public function lostpassword() |
|
| 881 | |||
| 882 | /** |
||
| 883 | * Show the "change password" page. |
||
| 884 | * This page can either be called directly by logged-in users |
||
| 885 | * (in which case they need to provide their old password), |
||
| 886 | * or through a link emailed through {@link lostpassword()}. |
||
| 887 | * In this case no old password is required, authentication is ensured |
||
| 888 | * through the Member.AutoLoginHash property. |
||
| 889 | * |
||
| 890 | * @see ChangePasswordForm |
||
| 891 | * |
||
| 892 | * @return string|HTTPRequest Returns the "change password" page as HTML code, or a redirect response |
||
| 893 | */ |
||
| 894 | View Code Duplication | public function changepassword() |
|
| 909 | |||
| 910 | /** |
||
| 911 | * Create a link to the password reset form. |
||
| 912 | * |
||
| 913 | * GET parameters used: |
||
| 914 | * - m: member ID |
||
| 915 | * - t: plaintext token |
||
| 916 | * |
||
| 917 | * @param Member $member Member object associated with this link. |
||
| 918 | * @param string $autologinToken The auto login token. |
||
| 919 | * @return string |
||
| 920 | */ |
||
| 921 | public static function getPasswordResetLink($member, $autologinToken) |
||
| 927 | |||
| 928 | /** |
||
| 929 | * Determine the list of templates to use for rendering the given action. |
||
| 930 | * |
||
| 931 | * @skipUpgrade |
||
| 932 | * @param string $action |
||
| 933 | * @return array Template list |
||
| 934 | */ |
||
| 935 | public function getTemplatesFor($action) |
||
| 949 | |||
| 950 | /** |
||
| 951 | * Return an existing member with administrator privileges, or create one of necessary. |
||
| 952 | * |
||
| 953 | * Will create a default 'Administrators' group if no group is found |
||
| 954 | * with an ADMIN permission. Will create a new 'Admin' member with administrative permissions |
||
| 955 | * if no existing Member with these permissions is found. |
||
| 956 | * |
||
| 957 | * Important: Any newly created administrator accounts will NOT have valid |
||
| 958 | * login credentials (Email/Password properties), which means they can't be used for login |
||
| 959 | * purposes outside of any default credentials set through {@link Security::setDefaultAdmin()}. |
||
| 960 | * |
||
| 961 | * @return Member |
||
| 962 | */ |
||
| 963 | public static function findAnAdministrator() |
||
| 1015 | |||
| 1016 | /** |
||
| 1017 | * Flush the default admin credentials |
||
| 1018 | */ |
||
| 1019 | public static function clear_default_admin() |
||
| 1024 | |||
| 1025 | |||
| 1026 | /** |
||
| 1027 | * Set a default admin in dev-mode |
||
| 1028 | * |
||
| 1029 | * This will set a static default-admin which is not existing |
||
| 1030 | * as a database-record. By this workaround we can test pages in dev-mode |
||
| 1031 | * with a unified login. Submitted login-credentials are first checked |
||
| 1032 | * against this static information in {@link Security::authenticate()}. |
||
| 1033 | * |
||
| 1034 | * @param string $username The user name |
||
| 1035 | * @param string $password The password (in cleartext) |
||
| 1036 | * @return bool True if successfully set |
||
| 1037 | */ |
||
| 1038 | public static function setDefaultAdmin($username, $password) |
||
| 1050 | |||
| 1051 | /** |
||
| 1052 | * Checks if the passed credentials are matching the default-admin. |
||
| 1053 | * Compares cleartext-password set through Security::setDefaultAdmin(). |
||
| 1054 | * |
||
| 1055 | * @param string $username |
||
| 1056 | * @param string $password |
||
| 1057 | * @return bool |
||
| 1058 | */ |
||
| 1059 | public static function check_default_admin($username, $password) |
||
| 1067 | |||
| 1068 | /** |
||
| 1069 | * Check that the default admin account has been set. |
||
| 1070 | */ |
||
| 1071 | public static function has_default_admin() |
||
| 1075 | |||
| 1076 | /** |
||
| 1077 | * Get default admin username |
||
| 1078 | * |
||
| 1079 | * @return string |
||
| 1080 | */ |
||
| 1081 | public static function default_admin_username() |
||
| 1085 | |||
| 1086 | /** |
||
| 1087 | * Get default admin password |
||
| 1088 | * |
||
| 1089 | * @return string |
||
| 1090 | */ |
||
| 1091 | public static function default_admin_password() |
||
| 1095 | |||
| 1096 | /** |
||
| 1097 | * Encrypt a password according to the current password encryption settings. |
||
| 1098 | * If the settings are so that passwords shouldn't be encrypted, the |
||
| 1099 | * result is simple the clear text password with an empty salt except when |
||
| 1100 | * a custom algorithm ($algorithm parameter) was passed. |
||
| 1101 | * |
||
| 1102 | * @param string $password The password to encrypt |
||
| 1103 | * @param string $salt Optional: The salt to use. If it is not passed, but |
||
| 1104 | * needed, the method will automatically create a |
||
| 1105 | * random salt that will then be returned as return value. |
||
| 1106 | * @param string $algorithm Optional: Use another algorithm to encrypt the |
||
| 1107 | * password (so that the encryption algorithm can be changed over the time). |
||
| 1108 | * @param Member $member Optional |
||
| 1109 | * @return mixed Returns an associative array containing the encrypted |
||
| 1110 | * password and the used salt in the form: |
||
| 1111 | * <code> |
||
| 1112 | * array( |
||
| 1113 | * 'password' => string, |
||
| 1114 | * 'salt' => string, |
||
| 1115 | * 'algorithm' => string, |
||
| 1116 | * 'encryptor' => PasswordEncryptor instance |
||
| 1117 | * ) |
||
| 1118 | * </code> |
||
| 1119 | * If the passed algorithm is invalid, FALSE will be returned. |
||
| 1120 | * |
||
| 1121 | * @see encrypt_passwords() |
||
| 1122 | */ |
||
| 1123 | public static function encrypt_password($password, $salt = null, $algorithm = null, $member = null) |
||
| 1142 | |||
| 1143 | /** |
||
| 1144 | * Checks the database is in a state to perform security checks. |
||
| 1145 | * See {@link DatabaseAdmin->init()} for more information. |
||
| 1146 | * |
||
| 1147 | * @return bool |
||
| 1148 | */ |
||
| 1149 | public static function database_is_ready() |
||
| 1197 | |||
| 1198 | /** |
||
| 1199 | * Resets the database_is_ready cache |
||
| 1200 | */ |
||
| 1201 | public static function clear_database_is_ready() |
||
| 1206 | |||
| 1207 | /** |
||
| 1208 | * For the database_is_ready call to return a certain value - used for testing |
||
| 1209 | */ |
||
| 1210 | public static function force_database_is_ready($isReady) |
||
| 1214 | |||
| 1215 | /** |
||
| 1216 | * @config |
||
| 1217 | * @var string Set the default login dest |
||
| 1218 | * This is the URL that users will be redirected to after they log in, |
||
| 1219 | * if they haven't logged in en route to access a secured page. |
||
| 1220 | * By default, this is set to the homepage. |
||
| 1221 | */ |
||
| 1222 | private static $default_login_dest = ""; |
||
| 1223 | |||
| 1224 | protected static $ignore_disallowed_actions = false; |
||
| 1225 | |||
| 1226 | /** |
||
| 1227 | * Set to true to ignore access to disallowed actions, rather than returning permission failure |
||
| 1228 | * Note that this is just a flag that other code needs to check with Security::ignore_disallowed_actions() |
||
| 1229 | * @param $flag True or false |
||
| 1230 | */ |
||
| 1231 | public static function set_ignore_disallowed_actions($flag) |
||
| 1235 | |||
| 1236 | public static function ignore_disallowed_actions() |
||
| 1240 | |||
| 1241 | /** |
||
| 1242 | * Get the URL of the log-in page. |
||
| 1243 | * |
||
| 1244 | * To update the login url use the "Security.login_url" config setting. |
||
| 1245 | * |
||
| 1246 | * @return string |
||
| 1247 | */ |
||
| 1248 | public static function login_url() |
||
| 1252 | |||
| 1253 | |||
| 1254 | /** |
||
| 1255 | * Get the URL of the logout page. |
||
| 1256 | * |
||
| 1257 | * To update the logout url use the "Security.logout_url" config setting. |
||
| 1258 | * |
||
| 1259 | * @return string |
||
| 1260 | */ |
||
| 1261 | public static function logout_url() |
||
| 1265 | |||
| 1266 | /** |
||
| 1267 | * Get the URL of the logout page. |
||
| 1268 | * |
||
| 1269 | * To update the logout url use the "Security.logout_url" config setting. |
||
| 1270 | * |
||
| 1271 | * @return string |
||
| 1272 | */ |
||
| 1273 | public static function lost_password_url() |
||
| 1277 | |||
| 1278 | /** |
||
| 1279 | * Defines global accessible templates variables. |
||
| 1280 | * |
||
| 1281 | * @return array |
||
| 1282 | */ |
||
| 1283 | public static function get_template_global_variables() |
||
| 1293 | } |
||
| 1294 |