Changeset 2256 for branches

Show
Ignore:
Timestamp:
11/26/10 15:59:08 (18 months ago)
Author:
petsagouris
Message:

[Branch 1.5] Various too small edits out of me being a code monkey (code formatting).

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/1.5/libs/AdminAuth.php

    r1912 r2256  
    3232        { 
    3333                // Authenticate the admin if the User Signin plugin is INACTIVE: 
    34                 if (!$h->isActive('signin')) 
    35                 { 
    36                         if (($h->pageName != 'admin_login') && !$this->isAdminCookie($h)) 
    37                         { 
    38                                 header('Location: ' . SITEURL . 'admin_index.php?page=admin_login'); 
    39                                 die; exit; 
    40                         } 
    41                 } 
    42                  
     34                if (!$h->isActive('signin')) { 
     35                        if (($h->pageName != 'admin_login') && !$this->isAdminCookie($h)) { 
     36                                header('Location: '.SITEURL.'admin_index.php?page=admin_login'); 
     37                                die; 
     38                                exit; 
     39                        } 
     40                } 
     41 
    4342                // Authenticate the admin if a Signin plugin is ACTIVE and site is OPEN: 
    44                 if (is_object($h->currentUser) && $h->isActive('signin') && (SITE_OPEN == 'true')) 
    45                 { 
     43                if (is_object($h->currentUser) && $h->isActive('signin') && (SITE_OPEN == 'true')) { 
    4644                        // This first condition happens when the Users plugin is activated  
    4745                        // and there's no cookie for the Admin yet. 
    48                         if (($h->currentUser->name == "") && $h->isActive('signin'))  
    49                         { 
    50                                 header('Location: ' . SITEURL . 'index.php?page=login'); 
    51                                 die; exit; 
    52                         }  
    53                         elseif ($h->currentUser->getPermission('can_access_admin') != 'yes')  
    54                         { 
     46                        if (($h->currentUser->name == "") && $h->isActive('signin')) { 
     47                                header('Location: '.SITEURL.'index.php?page=login'); 
     48                                die; 
     49                                exit; 
     50                        } elseif ($h->currentUser->getPermission('can_access_admin') != 'yes') { 
    5551                                // maybe the user has permission to access a specific plugin settings page? 
    5652                                $plugin = $h->cage->get->testAlnumLines('plugin'); 
    5753                                if ($plugin && ($h->pageName == "plugin_settings")) { 
    58                                         $permission = "can_" . $plugin . "_settings"; 
     54                                        $permission = "can_".$plugin."_settings"; 
    5955                                        if ($h->currentUser->getPermission($permission) == 'yes') { 
    60                                                 $h->sidebars = false; // hide sidebars 
     56                                                $h->sidebars = FALSE; // hide sidebars 
    6157                                                $h->displayTemplate('index'); 
    62                                                 die(); exit; 
     58                                                die(); 
     59                                                exit; 
    6360                                        } 
    6461                                } 
    65                                  
     62 
    6663                                // User doesn't have permission to access Admin 
    6764                                $h->messages[$h->lang['main_access_denied']] = 'red'; 
    6865                                $h->displayTemplate('admin_denied'); 
    69                                 die(); exit; 
    70                         } 
    71                 } 
    72                  
     66                                die(); 
     67                                exit; 
     68                        } 
     69                } 
     70 
    7371                // If we get this far, we know that the user has admin access. 
    74                  
     72 
    7573                return $h->pageName; 
    7674        } 
    77          
    78          
    79          /** 
     75 
     76        /** 
    8077         * Admin login 
    8178         *  
     
    8582        { 
    8683                // Check username 
    87                 if (!$username_check = $h->cage->post->testUsername('username')) {  
    88                         $username_check = '';  
    89                 }  
    90                  
     84                if (!$username_check = $h->cage->post->testUsername('username')) { 
     85                        $username_check = ''; 
     86                } 
     87 
    9188                // Check password 
    9289                if (!$password_check = $h->cage->post->testPassword('password')) { 
    93                         $password_check = '';  
    94                 } 
    95                  
     90                        $password_check = ''; 
     91                } 
     92 
    9693                if ($h->cage->post->keyExists('login_attempted') || $h->cage->post->keyExists('forgotten_password')) { 
    9794                        // if either the login or forgot password form is submitted, check the CSRF key 
    98                          
     95 
    9996                        if (!$h->csrf()) { 
    10097                                $h->message = $h->lang["error_csrf"]; 
    10198                                $h->messageType = "red"; 
    102                                 return false; 
    103                         } 
    104                 } 
    105                  
    106                 if ($username_check != '' || $password_check != '')  
    107                 { 
     99                                return FALSE; 
     100                        } 
     101                } 
     102 
     103                if ($username_check != '' || $password_check != '') { 
    108104                        $login_result = $h->currentUser->loginCheck($h, $username_check, $password_check); 
    109                          
     105 
    110106                        if ($login_result) { 
    111107                                //success 
     
    113109                                $h->currentUser->getUser($h, 0, $username_check); 
    114110                                $this->setAdminCookie($h, $username_check); 
    115                                 $h->currentUser->loggedIn = true; 
     111                                $h->currentUser->loggedIn = TRUE; 
    116112                                $h->currentUser->updateUserLastLogin($h); 
    117                                 $h->sidebars = true; 
     113                                $h->sidebars = TRUE; 
    118114                                $h->pageName = 'admin_home'; // a wee hack 
    119                                 return true; 
     115                                return TRUE; 
    120116                        } else { 
    121117                                // login failed 
     
    123119                                $h->messageType = "red"; 
    124120                        } 
    125                 }  
    126                 else  
    127                 { 
     121                } else { 
    128122                        if ($h->cage->post->keyExists('login_attempted')) { 
    129123                                $h->message = $h->lang["admin_login_failed"]; 
     
    132126                        $username_check = ''; 
    133127                        $password_check = ''; 
    134                          
     128 
    135129                        // forgotten password request 
    136130                        if ($h->cage->post->keyExists('forgotten_password')) { 
    137131                                $this->adminPassword($h); 
    138132                        } 
    139                          
     133 
    140134                        // confirming forgotten password email 
    141135                        $passconf = $h->cage->get->getAlnum('passconf'); 
    142136                        $userid = $h->cage->get->testInt('userid'); 
    143                          
     137 
    144138                        if ($passconf && $userid) { 
    145139                                if ($h->currentUser->newRandomPassword($h, $userid, $passconf)) { 
     
    152146                        } 
    153147                } 
    154                  
    155                 return false; 
    156         } 
    157          
    158          
    159          /** 
     148 
     149                return FALSE; 
     150        } 
     151 
     152        /** 
    160153         * Admin password forgotten 
    161154         *  
     
    165158        { 
    166159                // Check email 
    167                 if (!$email_check = $h->cage->post->testEmail('email')) {  
    168                         $email_check = '';  
     160                if (!$email_check = $h->cage->post->testEmail('email')) { 
     161                        $email_check = ''; 
    169162                        // login failed 
    170163                        $h->message = $h->lang["admin_login_email_invalid"]; 
    171164                        $h->messageType = "red"; 
    172                         return false; 
    173                 }  
     165                        return FALSE; 
     166                } 
    174167 
    175168                $valid_email = $h->emailExists($email_check, 'admin'); 
    176169                $userid = $h->getUserIdFromEmail($valid_email); 
    177                  
     170 
    178171                if ($valid_email && $userid) { 
    179172                        //success 
     
    181174                        $h->message = $h->lang['admin_email_password_conf_sent']; 
    182175                        $h->messageType = "green"; 
    183                         return true; 
     176                        return TRUE; 
    184177                } else { 
    185178                        // login failed 
    186179                        $h->message = $h->lang["admin_login_email_invalid"]; 
    187180                        $h->messageType = "red"; 
    188                         return false; 
    189                 } 
    190         } 
    191          
    192          
    193          /** 
     181                        return FALSE; 
     182                } 
     183        } 
     184 
     185        /** 
    194186         * Admin login form 
    195187         */ 
     
    199191                if (!$username_check = $h->cage->post->testUsername('username')) { 
    200192                        $username_check = ''; 
    201                 }  
    202                  
     193                } 
     194 
    203195                // Check password 
    204196                if (!$password_check = $h->cage->post->testPassword('password')) { 
    205                         $password_check = '';  
    206                 } 
    207                  
     197                        $password_check = ''; 
     198                } 
     199 
    208200                // Check email (for forgotten password form) 
    209201                if (!$email_check = $h->cage->post->testEmail('email')) { 
    210                         $email_check = '';  
    211                 } 
    212                  
    213                 require_once(ADMIN_THEMES . ADMIN_THEME . 'admin_login.php'); 
    214         } 
    215          
    216          
     202                        $email_check = ''; 
     203                } 
     204 
     205                require_once(ADMIN_THEMES.ADMIN_THEME.'admin_login.php'); 
     206        } 
     207 
    217208        /** 
    218209         * Set a 30-day cookie for the administrator 
     
    222213        public function setAdminCookie($h) 
    223214        { 
    224                 if (!$h->currentUser->name)  
    225                 {  
     215                if (!$h->currentUser->name) { 
    226216                        echo $this->lang["admin_login_error_cookie"]; 
    227                         return false; 
    228                 }  
    229                 else  
    230                 { 
    231                         $strCookie=base64_encode( 
    232                                 join(':', array($h->currentUser->name,  
    233                                 $h->currentUser->generateHash($h->currentUser->name, md5(SITEURL)), 
    234                                 md5($h->currentUser->password))) 
     217                        return FALSE; 
     218                } else { 
     219                        $strCookie = base64_encode( 
     220                                                        join(':', array($h->currentUser->name, 
     221                                                                $h->currentUser->generateHash($h->currentUser->name, md5(SITEURL)), 
     222                                                                md5($h->currentUser->password))) 
    235223                        ); 
    236                          
     224 
    237225                        // (2592000 = 60 seconds * 60 mins * 24 hours * 30 days.) 
    238226                        $month = 2592000 + time(); 
    239                          
     227 
    240228                        if (strpos(SITEURL, "localhost") !== false) { 
    241                              setcookie("hotaru_user", $h->currentUser->name, $month, "/"); 
    242                              setcookie("hotaru_key", $strCookie, $month, "/"); 
     229                                setcookie("hotaru_user", $h->currentUser->name, $month, "/"); 
     230                                setcookie("hotaru_key", $strCookie, $month, "/"); 
    243231                        } else { 
    244                              $parsed = parse_url(SITEURL);  
    245                                          
    246                              // now we need a dot in front of that so cookies work across subdomains: 
    247                              setcookie("hotaru_user", $h->currentUser->name, $month, "/", "." . $parsed['host']); 
    248                              setcookie("hotaru_key", $strCookie, $month, "/", "." . $parsed['host']); 
    249                         }   
    250                          
    251                         return true; 
    252                 } 
    253         } 
    254  
    255          /** 
    256          *  Checks if a cookie exists and if it belongs to an Admin user 
     232                                $parsed = parse_url(SITEURL); 
     233 
     234                                // now we need a dot in front of that so cookies work across subdomains: 
     235                                setcookie("hotaru_user", $h->currentUser->name, $month, "/", ".".$parsed['host']); 
     236                                setcookie("hotaru_key", $strCookie, $month, "/", ".".$parsed['host']); 
     237                        } 
     238 
     239                        return TRUE; 
     240                } 
     241        } 
     242 
     243        /** 
     244         * Checks if a cookie exists and if it belongs to an Admin user 
     245         * NOTE: This is ONLY used if the User Signin plugin is inactive. 
    257246         * 
    258247         * @return bool 
    259          * 
    260          * NOTE!!! This is ONLY used if the User Signin plugin is inactive. 
    261248         */ 
    262249        public function isAdminCookie($h) 
    263250        { 
    264                 if (!$h->currentUser->checkCookie($h)) { return false; } 
    265                  
    266                 if (!$h->isAdmin($h->currentUser->name)) { return false; } 
     251                if (!$h->currentUser->checkCookie($h)) { 
     252                        return FALSE; 
     253                } 
     254 
     255                if (!$h->isAdmin($h->currentUser->name)) { 
     256                        return FALSE; 
     257                } 
    267258 
    268259                //success... 
    269                 return true; 
    270         } 
    271          
    272          /** 
     260                return TRUE; 
     261        } 
     262 
     263        /** 
    273264         * Admin logout 
    274265         * 
     
    278269        { 
    279270                $h->currentUser->destroyCookieAndSession(); 
    280                 header("Location: " . SITEURL); 
    281                 return true; 
    282         } 
     271                header("Location: ".SITEURL); 
     272                return TRUE; 
     273        } 
     274 
    283275} 
    284 ?>