diff --git a/docs/en/changelogs/rc/3.2.0.md b/docs/en/changelogs/rc/3.2.0.md
index 86af6d011..44698bbed 100644
--- a/docs/en/changelogs/rc/3.2.0.md
+++ b/docs/en/changelogs/rc/3.2.0.md
@@ -12,6 +12,8 @@ Otherwise, you'll need to include the module yourself
### Framework
* API: Removed URL routing by controller name
+ * Security: The multiple authenticator login page should now be styled manually - i.e. without the default jQuery UI layout. A new template, Security_MultiAuthenticatorLogin.ss is available.
+ * Security: This controller's templates can be customised by overriding the `getTemplate` function.
## Details
@@ -60,4 +62,4 @@ you can reinstate the old behaviour through a director rule:
---
Director:
rules:
- '$Controller//$Action/$ID/$OtherID': '*'
\ No newline at end of file
+ '$Controller//$Action/$ID/$OtherID': '*'
diff --git a/security/LoginForm.php b/security/LoginForm.php
index dd768b038..6f06fbc61 100644
--- a/security/LoginForm.php
+++ b/security/LoginForm.php
@@ -40,5 +40,15 @@ abstract class LoginForm extends Form {
return new $this->authenticator_class;
}
+
+ /**
+ * Get the authenticator name.
+ * @return string The friendly name for use in templates, etc.
+ */
+ public function getAuthenticatorName() {
+ $authClass = $this->authenticator_class;
+ return $authClass::get_name();
+ }
+
}
diff --git a/security/Security.php b/security/Security.php
index f0994b6b1..033dc485f 100644
--- a/security/Security.php
+++ b/security/Security.php
@@ -347,6 +347,9 @@ class Security extends Controller {
/**
* Show the "login" page
*
+ * For multiple authenticators, Security_MultiAuthenticatorLogin is used.
+ * See getTemplate and getIncludeTemplate for how to override template logic
+ *
* @return string Returns the "login" page as HTML code.
*/
public function login() {
@@ -360,11 +363,6 @@ class Security extends Controller {
if($result instanceof SS_HTTPResponse) return $result;
}
}
-
- $customCSS = project() . '/css/tabs.css';
- if(Director::fileExists($customCSS)) {
- Requirements::css($customCSS);
- }
if(class_exists('SiteTree')) {
$tmpPage = new Page();
@@ -376,7 +374,8 @@ class Security extends Controller {
$controller = Page_Controller::create($tmpPage);
$controller->setDataModel($this->model);
$controller->init();
- } else {
+ }
+ else {
$controller = $this;
}
@@ -385,71 +384,48 @@ class Security extends Controller {
$content = '';
$forms = $this->GetLoginForms();
- if(!count($forms)) {
+ $formCount = count($forms);
+
+ if(!$formCount) {
user_error('No login-forms found, please use Authenticator::register_authenticator() to add one',
E_USER_ERROR);
}
-
- // only display tabs when more than one authenticator is provided
- // to save bandwidth and reduce the amount of custom styling needed
- if(count($forms) > 1) {
- // Needed because the
$message
"; - } - $customisedController = $controller->customise(array( - "Content" => $message, - "Form" => $content, - )); - } else { - $customisedController = $controller->customise(array( - "Form" => $content, - )); - } - + // We've displayed the message in the form output, so reset it for the next run. Session::clear('Security.Message'); - // custom processing + // If many login forms, display all to let user to choose. + if($formCount > 1) { + $viewData = new ArrayData(array( + 'Forms' => new ArrayList($forms), + )); + + $content = $viewData->renderWith( + $this->getIncludeTemplate('MultiAuthenticatorLogin') + ); + } + // Display the form + else { + $content = $forms[0]->forTemplate(); + } + + // Finally, customise the controller to add any form messages and the form. + $customisedController = $controller->customise(array( + "Message" => $message, + "MessageType" => $messageType, + "Form" => $content, + )); + + // Return the customised controller return $customisedController->renderWith( - array('Security_login', 'Security', $this->stat('template_main'), 'BlankPage') + $this->getTemplate('login') ); } @@ -491,7 +467,7 @@ class Security extends Controller { //Controller::$currentController = $controller; return $customisedController->renderWith( - array('Security_lostpassword', 'Security', $this->stat('template_main'), 'BlankPage') + $this->getTemplate('lostpassword') ); } @@ -557,7 +533,7 @@ class Security extends Controller { //Controller::$currentController = $controller; return $customisedController->renderWith( - array('Security_passwordsent', 'Security', $this->stat('template_main'), 'BlankPage') + $this->getTemplate('passwordsent') ); } @@ -661,7 +637,7 @@ class Security extends Controller { } return $customisedController->renderWith( - array('Security_changepassword', 'Security', $this->stat('template_main'), 'BlankPage') + $this->getTemplate('changepassword') ); } @@ -674,6 +650,31 @@ class Security extends Controller { return new ChangePasswordForm($this, 'ChangePasswordForm'); } + /** + * Gets the template for a particular action for use in rendering + * For use in any subclass + * + * @return string|array Returns the template(s) for rendering + */ + public function getTemplate($action) { + return array( + 'Security_' . $action, + 'Security', + $this->stat('template_main'), + 'BlankPage' + ); + } + + /** + * Gets the template for an include used for security. + * For use in any subclass. + * + * @return string|array Returns the template(s) for rendering + */ + public function getIncludeTemplate($name) { + return 'Security_' . $name; + } + /** * Return an existing member with administrator privileges, or create one of necessary. * diff --git a/templates/Includes/Security_MultiAuthenticatorLogin.ss b/templates/Includes/Security_MultiAuthenticatorLogin.ss new file mode 100644 index 000000000..a36a10fbb --- /dev/null +++ b/templates/Includes/Security_MultiAuthenticatorLogin.ss @@ -0,0 +1,13 @@ +