ENHANCEMENT: Coding conventions (check_default_admin())

ENHANCEMENT: only include tab-styling/js when more than one login-method is available

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@42731 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2007-09-27 21:13:59 +00:00
parent 6ec4b77cd5
commit 3bcf84de92
2 changed files with 44 additions and 31 deletions

View File

@ -29,7 +29,7 @@ class MemberAuthenticator extends Authenticator {
$SQL_user = Convert::raw2sql($RAW_data['Email']); $SQL_user = Convert::raw2sql($RAW_data['Email']);
// Default login (see {@setDetaultAdmin()}) // Default login (see {@setDetaultAdmin()})
if(Security::checkDefaultAdmin($RAW_data['Email'], $RAW_data['Password'])) { if(Security::check_default_admin($RAW_data['Email'], $RAW_data['Password'])) {
$member = Security::findAnAdministrator(); $member = Security::findAnAdministrator();
} else { } else {
$member = DataObject::get_one("Member", "Email = '$SQL_user' AND Password IS NOT NULL"); $member = DataObject::get_one("Member", "Email = '$SQL_user' AND Password IS NOT NULL");

View File

@ -192,14 +192,6 @@ class Security extends Controller {
* @return string Returns the "login" page as HTML code. * @return string Returns the "login" page as HTML code.
*/ */
public function login() { public function login() {
Requirements::javascript("jsparty/loader.js");
Requirements::javascript("jsparty/prototype.js");
Requirements::javascript("jsparty/behaviour.js");
Requirements::javascript("jsparty/prototype_improvements.js");
Requirements::javascript("jsparty/tabstrip/tabstrip.js");
Requirements::javascript("jsparty/scriptaculous/effects.js");
Requirements::css("jsparty/tabstrip/tabstrip.css");
$customCSS = project() . '/css/tabs.css'; $customCSS = project() . '/css/tabs.css';
if(Director::fileExists($customCSS)) { if(Director::fileExists($customCSS)) {
Requirements::css($customCSS); Requirements::css($customCSS);
@ -213,15 +205,29 @@ class Security extends Controller {
$controller->init(); $controller->init();
//Controller::$currentController = $controller; //Controller::$currentController = $controller;
if(SSViewer::hasTemplate("Security_login")) { $content = '';
return $controller->renderWith(array("Security_login", "Page")); $forms = $this->GetLoginForms();
if(!count($forms)) {
} else { 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) {
Requirements::javascript("jsparty/loader.js");
Requirements::javascript("jsparty/prototype.js");
Requirements::javascript("jsparty/behaviour.js");
Requirements::javascript("jsparty/prototype_improvements.js");
Requirements::javascript("jsparty/tabstrip/tabstrip.js");
Requirements::javascript("jsparty/scriptaculous/effects.js");
Requirements::css("jsparty/tabstrip/tabstrip.css");
Requirements::css("sapphire/css/Form.css");
Requirements::css("sapphire/css/Security_login.css");
// Needed because the <base href=".."> in the template makes problems // Needed because the <base href=".."> in the template makes problems
// with the tabstrip library otherwise // with the tabstrip library otherwise
$link_base = Director::absoluteURL($this->Link("login")); $link_base = Director::absoluteURL($this->Link("login"));
$forms = $this->GetLoginForms();
$content = '<div id="Form_EditForm">'; $content = '<div id="Form_EditForm">';
$content .= '<ul class="tabstrip">'; $content .= '<ul class="tabstrip">';
$content_forms = ''; $content_forms = '';
@ -232,25 +238,32 @@ class Security extends Controller {
} }
$content .= "</ul>\n" . $content_forms . "\n</div>\n"; $content .= "</ul>\n" . $content_forms . "\n</div>\n";
} else {
if(strlen($message = Session::get('Security.Message.message')) > 0) { $content .= $forms[0]->forTemplate();
$message_type = Session::get('Security.Message.type'); }
if($message_type == 'bad') {
$message = "<p class=\"message $message_type\">$message</p>"; if(strlen($message = Session::get('Security.Message.message')) > 0) {
} else { $message_type = Session::get('Security.Message.type');
$message = "<p>$message</p>"; if($message_type == 'bad') {
} $message = "<p class=\"message $message_type\">$message</p>";
$customisedController = $controller->customise(array(
"Content" => $message,
"Form" => $content
));
} else { } else {
$customisedController = $controller->customise(array( $message = "<p>$message</p>";
"Content" => $content
));
} }
$customisedController = $controller->customise(array(
"Content" => $message,
"Form" => $content
));
} else {
$customisedController = $controller->customise(array(
"Content" => $content
));
}
// custom processing
if(SSViewer::hasTemplate("Security_login")) {
return $customisedController->renderWith(array("Security_login", "Page"));
} else {
return $customisedController->renderWith("Page"); return $customisedController->renderWith("Page");
} }
} }
@ -485,7 +498,7 @@ class Security extends Controller {
* @param string $password * @param string $password
* @return bool * @return bool
*/ */
public static function checkDefaultAdmin($username, $password) { public static function check_default_admin($username, $password) {
return ( return (
self::$default_username == $username self::$default_username == $username
&& self::$default_password == $password && self::$default_password == $password