Changes up to 2.3.7 merged into unstable branch.
[fa-stable.git] / includes / current_user.inc
index 1c7d161183a560d493ee685b891bba6020d1bfc5..591524f4626e6b5ad899add3804b23567df97e7f 100644 (file)
@@ -63,11 +63,20 @@ class current_user
                $this->set_company($company);
            $this->logged = false;
 
-               $Auth_Result = get_user_for_login($loginname, $password);
+               set_global_connection();
 
-               if (db_num_rows($Auth_Result) > 0)
+               // Use external authentication source if any.
+               // Keep in mind you need to have user data set for $loginname
+               // in FA users table anyway to successfully log in.
+               $Auth_Result = hook_authenticate($loginname, $password);
+
+               if (!isset($Auth_Result))       // if not used: standard method
+                       $Auth_Result = get_user_auth($loginname, md5($password));
+
+               if ($Auth_Result)
                {
-                       $myrow = db_fetch($Auth_Result);
+                       $myrow = get_user_by_login($loginname);
+
                        $this->old_db = isset($myrow["full_access"]);
                        if (! @$myrow["inactive"]) {
                                if ($this->old_db) { 
@@ -525,6 +534,9 @@ function array_search_key($needle, $haystack, $valuekey=null)
 function flush_dir($path, $wipe = false) 
 {
        $dir = opendir($path);
+       if(!$dir)
+               return;
+
        while(false !== ($fname = readdir($dir))) {
                if($fname=='.' || $fname=='..' || $fname=='CVS' || (!$wipe && $fname=='index.php')) continue;
                if(is_dir($path.'/'.$fname)) {