Ejemplo n.º 1
0
 /**
  * Show the "login" page
  *
  * @return string Returns the "login" page as HTML code.
  */
 public function login()
 {
     // Event handler for pre-login, with an option to let it break you out of the login form
     $eventResults = $this->extend('onBeforeSecurityLogin');
     // If there was a redirection, return
     if (Director::redirected_to()) {
         return;
     } else {
         if ($eventResults) {
             foreach ($eventResults as $result) {
                 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();
         $tmpPage->Title = _t('Security.LOGIN', 'Log in');
         $tmpPage->URLSegment = "Security";
         // Disable ID-based caching  of the log-in page by making it a random number
         $tmpPage->ID = -1 * rand(1, 10000000);
         $controller = new Page_Controller($tmpPage);
         $controller->setModel($this->model);
         $controller->init();
         //Controller::$currentController = $controller;
     } else {
         $controller = $this;
     }
     $content = '';
     $forms = $this->GetLoginForms();
     if (!count($forms)) {
         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::css(SAPPHIRE_DIR . "/css/Form.css");
         // Needed because the <base href=".."> in the template makes problems
         // with the tabstrip library otherwise
         $link_base = Director::absoluteURL($this->Link("login"));
         Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery/jquery.js');
         Requirements::javascript(SAPPHIRE_DIR . "/javascript/jquery_improvements.js");
         Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/jquery-ui.js');
         Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js');
         Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
         Requirements::css(SAPPHIRE_DIR . '/css/Security_login.css');
         Requirements::javascript(SAPPHIRE_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));
     }
     Session::clear('Security.Message');
     // custom processing
     return $customisedController->renderWith(array('Security_login', 'Security', $this->stat('template_main'), 'BlankPage'));
 }