[Jaws-commits] r12504 - in trunk/jaws/html: . gadgets/ControlPanel include include/Jaws

afz at jaws-project.com afz at jaws-project.com
Fri Jan 27 21:52:59 UTC 2012


Author: afz
Date: 2012-01-27 21:52:59 +0000 (Fri, 27 Jan 2012)
New Revision: 12504

Modified:
   trunk/jaws/html/admin.php
   trunk/jaws/html/gadgets/ControlPanel/AdminHTML.php
   trunk/jaws/html/include/Jaws.php
   trunk/jaws/html/include/Jaws/Session.php
Log:
Now can select authentication method via login box if it is set to non-default

Modified: trunk/jaws/html/admin.php
===================================================================
--- trunk/jaws/html/admin.php	2012-01-27 21:49:23 UTC (rev 12503)
+++ trunk/jaws/html/admin.php	2012-01-27 21:52:59 UTC (rev 12504)
@@ -81,14 +81,15 @@
             }
         }
 
-        $remember = $request->get('remember', 'post');
-        $remember = isset($remember)? true : false;
-        $login = $GLOBALS['app']->Session->Login($user, $passwd, $remember);
+        $param = $request->get(array('redirect_to', 'remember', 'auth_method'), 'post');
+        $login = $GLOBALS['app']->Session->Login($user,
+                                                 $passwd, 
+                                                 isset($param['remember']),
+                                                 $param['auth_method']);
         if (!Jaws_Error::isError($login)) {
             // Can enter to Control Panel?
             if ($GLOBALS['app']->Session->GetPermission('ControlPanel', 'default_admin')) {
-                $redirectTo = $request->get('redirect_to', 'post');
-                $redirectTo = isset($redirectTo)? $redirectTo : '';
+                $redirectTo = isset($param['redirect_to'])? $param['redirect_to'] : '';
                 if (substr($redirectTo, 0, 1) == '?') {
                     $redirectTo = str_replace('&', '&', $redirectTo);
                 } else {

Modified: trunk/jaws/html/gadgets/ControlPanel/AdminHTML.php
===================================================================
--- trunk/jaws/html/gadgets/ControlPanel/AdminHTML.php	2012-01-27 21:49:23 UTC (rev 12503)
+++ trunk/jaws/html/gadgets/ControlPanel/AdminHTML.php	2012-01-27 21:52:59 UTC (rev 12504)
@@ -216,6 +216,11 @@
         $tpl->SetVariable('control-panel', _t('CONTROLPANEL_NAME'));
 
         $request =& Jaws_Request::getInstance();
+        $reqpost = $request->get(array('username', 'auth_method', 'remember', 'usecrypt'), 'post');
+        if (empty($reqpost['auth_method'])) {
+            $reqpost['auth_method'] = $request->get('auth_method', 'get');
+        }
+
         $form =& Piwi::CreateWidget('Form', BASE_SCRIPT, 'post');
         $form->setID('login_form');
         $form->shouldValidate($use_crypt, $use_crypt);
@@ -244,22 +249,37 @@
         $fieldset->SetDirection('vertical');
         $fieldset->SetStyle('width: 100%;');
 
-        $username = $request->get('username', 'post');
-        $usernameEntry =& Piwi::CreateWidget('Entry', 'username',
-                                             isset($username) ? $username : '');
+        $usernameEntry =& Piwi::CreateWidget('Entry', 'username', (string) $reqpost['username']);
         $usernameEntry->SetTitle(_t('GLOBAL_USERNAME'));
         $fieldset->Add($usernameEntry);
-
         $tpl->SetVariable('loadObject', $usernameEntry->GetID());
 
         $passEntry =& Piwi::CreateWidget('PasswordEntry', 'password', '');
         $passEntry->SetTitle(_t('GLOBAL_PASSWORD'));
         $fieldset->Add($passEntry);
 
+        $auth_method = $GLOBALS['app']->Registry->Get('/config/auth_method');
+        if (!empty($reqpost['auth_method']) || $auth_method !== 'Default') {
+            $authmethod =& Piwi::CreateWidget('Combo', 'auth_method');
+            $authmethod->SetTitle(_t('CONTROLPANEL_AUTH_METHOD'));
+            foreach ($GLOBALS['app']->GetAuthMethods() as $method) {
+                $authmethod->AddOption($method, $method);
+            }
+            if (!empty($reqpost['auth_method'])) {
+                $authmethod->SetDefault($reqpost['auth_method']);
+            } else {
+                $authmethod->SetDefault($auth_method);
+            }
+            $fieldset->Add($authmethod);
+        }
+
         $rememberMe =& Piwi::CreateWidget('CheckButtons', 'remember');
         $rememberMe->setID('remember');
         $rememberMe->setColumns(1);
         $rememberMe->AddOption(_t('GLOBAL_REMEMBER_ME'), 'true');
+        if (!empty($reqpost['remember'])) {
+            $rememberMe->SetDefault('true');
+        }
         $fieldset->Add($rememberMe);
 
         if ($use_crypt) {
@@ -267,7 +287,9 @@
             $useCrypt->setID('usecrypt');
             $useCrypt->setColumns(1);
             $useCrypt->AddOption(_t('CONTROLPANEL_LOGIN_SECURE'), 'true');
-            $useCrypt->SetDefault('true');
+            if (empty($reqpost['username']) || !empty($reqpost['usecrypt'])) {
+                $useCrypt->SetDefault('true');
+            }
             $fieldset->Add($useCrypt);
         }
 

Modified: trunk/jaws/html/include/Jaws/Session.php
===================================================================
--- trunk/jaws/html/include/Jaws/Session.php	2012-01-27 21:49:23 UTC (rev 12503)
+++ trunk/jaws/html/include/Jaws/Session.php	2012-01-27 21:52:59 UTC (rev 12504)
@@ -128,20 +128,27 @@
     /**
      * Login
      *
-     * @param   string  $username Username
-     * @param   string  $password Password
-     * @param   boolean $remember Remember me
+     * @param   string  $username   Username
+     * @param   string  $password   Password
+     * @param   boolean $remember   Remember me
+     * @param   string  $authmethod Authentication method
      * @return  boolean True if succeed.
      */
-    function Login($username, $password, $remember)
+    function Login($username, $password, $remember, $authmethod = '')
     {
         if (isset($GLOBALS['log'])) {
             $GLOBALS['log']->Log(JAWS_LOG_DEBUG, 'LOGGIN IN');
         }
 
         if ($username !== '' && $password !== '') {
-            require_once JAWS_PATH . 'include/Jaws/Auth/' . $this->_AuthMethod . '.php';
-            $className = 'Jaws_Auth_' . $this->_AuthMethod;
+            if (!empty($authmethod)) {
+                $authmethod = preg_replace('#[^[:alnum:]_-]#', '', $authmethod);
+            } else {
+                $authmethod = $this->_AuthMethod;
+            }
+
+            require_once JAWS_PATH . 'include/Jaws/Auth/' . $authmethod . '.php';
+            $className = 'Jaws_Auth_' . $authmethod;
             $this->_AuthModel = new $className();
             $result = $this->_AuthModel->Auth($username, $password);
             if (!Jaws_Error::isError($result)) {

Modified: trunk/jaws/html/include/Jaws.php
===================================================================
--- trunk/jaws/html/include/Jaws.php	2012-01-27 21:49:23 UTC (rev 12503)
+++ trunk/jaws/html/include/Jaws.php	2012-01-27 21:52:59 UTC (rev 12504)
@@ -449,7 +449,7 @@
      */
     function GetAuthMethods()
     {
-        $path = JAWS_PATH . 'include/Jaws/AuthScripts';
+        $path = JAWS_PATH . 'include/Jaws/Auth';
         if (is_dir($path)) {
             $methods = array();
             $dir = scandir($path);



More information about the Jaws-commits mailing list