mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-08-22 02:26:11 +02:00
Merge pull request #1807 from willmorgan/master
Allow easier control of Security templates with AJAX, etc.
This commit is contained in:
commit
7ab175374b
@ -12,6 +12,8 @@ Otherwise, you'll need to include the module yourself
|
|||||||
### Framework
|
### Framework
|
||||||
|
|
||||||
* API: Removed URL routing by controller name
|
* 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
|
## Details
|
||||||
|
|
||||||
|
@ -40,5 +40,15 @@ abstract class LoginForm extends Form {
|
|||||||
|
|
||||||
return new $this->authenticator_class;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,6 +347,9 @@ class Security extends Controller {
|
|||||||
/**
|
/**
|
||||||
* Show the "login" page
|
* 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.
|
* @return string Returns the "login" page as HTML code.
|
||||||
*/
|
*/
|
||||||
public function login() {
|
public function login() {
|
||||||
@ -361,11 +364,6 @@ class Security extends Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$customCSS = project() . '/css/tabs.css';
|
|
||||||
if(Director::fileExists($customCSS)) {
|
|
||||||
Requirements::css($customCSS);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(class_exists('SiteTree')) {
|
if(class_exists('SiteTree')) {
|
||||||
$tmpPage = new Page();
|
$tmpPage = new Page();
|
||||||
$tmpPage->Title = _t('Security.LOGIN', 'Log in');
|
$tmpPage->Title = _t('Security.LOGIN', 'Log in');
|
||||||
@ -376,7 +374,8 @@ class Security extends Controller {
|
|||||||
$controller = Page_Controller::create($tmpPage);
|
$controller = Page_Controller::create($tmpPage);
|
||||||
$controller->setDataModel($this->model);
|
$controller->setDataModel($this->model);
|
||||||
$controller->init();
|
$controller->init();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$controller = $this;
|
$controller = $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,71 +384,48 @@ class Security extends Controller {
|
|||||||
|
|
||||||
$content = '';
|
$content = '';
|
||||||
$forms = $this->GetLoginForms();
|
$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',
|
user_error('No login-forms found, please use Authenticator::register_authenticator() to add one',
|
||||||
E_USER_ERROR);
|
E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// only display tabs when more than one authenticator is provided
|
// Handle any for messages from validation, etc.
|
||||||
// to save bandwidth and reduce the amount of custom styling needed
|
$message = Session::get('Security.Message.message');
|
||||||
if(count($forms) > 1) {
|
$messageType = '';
|
||||||
// Needed because the <base href=".."> in the template makes problems
|
if(!empty($message)) {
|
||||||
// with the tabstrip library otherwise
|
$messageType = Session::get('Security.Message.type');
|
||||||
$link_base = Director::absoluteURL($this->Link("login"));
|
|
||||||
|
|
||||||
Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.js');
|
|
||||||
Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery-ui/jquery-ui.js');
|
|
||||||
|
|
||||||
Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js');
|
|
||||||
|
|
||||||
Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
|
|
||||||
|
|
||||||
Requirements::css(FRAMEWORK_DIR . '/css/Security_login.css');
|
|
||||||
|
|
||||||
Requirements::javascript(FRAMEWORK_DIR . '/javascript/TabSet.js');
|
|
||||||
|
|
||||||
$content = '<div id="Form_EditForm">';
|
|
||||||
$content .= '<div class="ss-tabset">';
|
|
||||||
$content .= '<ul>';
|
|
||||||
$content_forms = '';
|
|
||||||
|
|
||||||
foreach($forms as $form) {
|
|
||||||
$content .= "<li><a href=\"#{$form->FormName()}_tab\">"
|
|
||||||
. $form->getAuthenticator()->get_name()
|
|
||||||
. "</a></li>\n";
|
|
||||||
|
|
||||||
$content_forms .= '<div class="tab" id="' . $form->FormName() . '_tab">'
|
|
||||||
. $form->forTemplate() . "</div>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
$content .= "</ul>\n" . $content_forms . "\n</div>\n</div>\n";
|
|
||||||
} else {
|
|
||||||
$content .= $forms[0]->forTemplate();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(strlen($message = Session::get('Security.Message.message')) > 0) {
|
|
||||||
$message_type = Session::get('Security.Message.type');
|
|
||||||
if($message_type == 'bad') {
|
|
||||||
$message = "<p class=\"message $message_type\">$message</p>";
|
|
||||||
} else {
|
|
||||||
$message = "<p>$message</p>";
|
|
||||||
}
|
|
||||||
|
|
||||||
$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');
|
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(
|
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;
|
//Controller::$currentController = $controller;
|
||||||
return $customisedController->renderWith(
|
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;
|
//Controller::$currentController = $controller;
|
||||||
return $customisedController->renderWith(
|
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(
|
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');
|
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.
|
* Return an existing member with administrator privileges, or create one of necessary.
|
||||||
*
|
*
|
||||||
|
13
templates/Includes/Security_MultiAuthenticatorLogin.ss
Normal file
13
templates/Includes/Security_MultiAuthenticatorLogin.ss
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<ul>
|
||||||
|
<% loop Forms %>
|
||||||
|
<li>
|
||||||
|
<a href="#{$FormName}">$AuthenticatorName</a>
|
||||||
|
</li>
|
||||||
|
<% end_loop %>
|
||||||
|
</ul>
|
||||||
|
<% loop Forms %>
|
||||||
|
<div class="form-tab" id="{$FormName}">
|
||||||
|
<h3>$AuthenticatorName</h3>
|
||||||
|
$forTemplate
|
||||||
|
</div>
|
||||||
|
<% end_loop %>
|
Loading…
Reference in New Issue
Block a user