Пример #1
0
 /**
  * Once a user is authenticated on login this function will be called. Populate the session with what is needed and log anything that needs to be logged
  *
  */
 function postLoginAuthenticate()
 {
     global $reset_theme_on_default_user, $reset_language_on_default_user, $sugar_config;
     //THIS SECTION IS TO ENSURE VERSIONS ARE UPTODATE
     require_once 'modules/Versions/CheckVersions.php';
     $invalid_versions = get_invalid_versions();
     if (!empty($invalid_versions)) {
         if (isset($invalid_versions['Rebuild Relationships'])) {
             unset($invalid_versions['Rebuild Relationships']);
             // flag for pickup in DisplayWarnings.php
             $_SESSION['rebuild_relationships'] = true;
         }
         if (isset($invalid_versions['Rebuild Extensions'])) {
             unset($invalid_versions['Rebuild Extensions']);
             // flag for pickup in DisplayWarnings.php
             $_SESSION['rebuild_extensions'] = true;
         }
         $_SESSION['invalid_versions'] = $invalid_versions;
     }
     //just do a little house cleaning here
     unset($_SESSION['login_password']);
     unset($_SESSION['login_error']);
     unset($_SESSION['login_user_name']);
     unset($_SESSION['ACL']);
     //set the server unique key
     if (isset($sugar_config['unique_key'])) {
         $_SESSION['unique_key'] = $sugar_config['unique_key'];
     }
     //set user language
     if (isset($reset_language_on_default_user) && $reset_language_on_default_user && $GLOBALS['current_user']->user_name == $sugar_config['default_user_name']) {
         $authenticated_user_language = $sugar_config['default_language'];
     } else {
         $authenticated_user_language = isset($_REQUEST['login_language']) ? $_REQUEST['login_language'] : (isset($_REQUEST['ck_login_language_20']) ? $_REQUEST['ck_login_language_20'] : $sugar_config['default_language']);
     }
     $_SESSION['authenticated_user_language'] = $authenticated_user_language;
     $GLOBALS['log']->debug("authenticated_user_language is {$authenticated_user_language}");
     // Clear all uploaded import files for this user if it exists
     require_once 'modules/Import/ImportCacheFiles.php';
     $tmp_file_name = ImportCacheFiles::getImportDir() . "/IMPORT_" . $GLOBALS['current_user']->id;
     if (file_exists($tmp_file_name)) {
         unlink($tmp_file_name);
     }
     return true;
 }
Пример #2
0
 /**
  * Load a user based on the user_name in $this
  * @return -- this if load was successul and null if load failed.
  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
  * All Rights Reserved..
  * Contributor(s): ______________________________________..
  */
 function load_user($user_password)
 {
     global $login_error;
     unset($GLOBALS['login_error']);
     if (isset($_SESSION['loginattempts'])) {
         $_SESSION['loginattempts'] += 1;
     } else {
         $_SESSION['loginattempts'] = 1;
     }
     if ($_SESSION['loginattempts'] > 5) {
         $GLOBALS['log']->fatal('SECURITY: ' . $this->user_name . ' has attempted to login ' . $_SESSION['loginattempts'] . ' times from IP address: ' . $_SERVER['REMOTE_ADDR'] . '.');
     }
     $GLOBALS['log']->debug("Starting user load for {$this->user_name}");
     if (!isset($this->user_name) || $this->user_name == "" || !isset($user_password) || $user_password == "") {
         return null;
     }
     $user_hash = strtolower(md5($user_password));
     if ($this->authenticate_user($user_hash)) {
         $query = "SELECT * from {$this->table_name} where id='{$this->id}'";
     } else {
         $GLOBALS['log']->fatal('SECURITY: User authentication for ' . $this->user_name . ' failed');
         return null;
     }
     $r = $this->db->limitQuery($query, 0, 1, false);
     $a = $this->db->fetchByAssoc($r);
     if (empty($a) || !empty($GLOBALS['login_error'])) {
         $GLOBALS['log']->fatal('SECURITY: User authentication for ' . $this->user_name . ' failed - could not Load User from Database');
         return null;
     }
     // Get the fields for the user
     $row = $a;
     // If there is no user_hash is not present or is out of date, then create a new one.
     if (!isset($row['user_hash']) || $row['user_hash'] != $user_hash) {
         $query = "UPDATE {$this->table_name} SET user_hash='{$user_hash}' where id='{$row['id']}'";
         $this->db->query($query, true, "Error setting new hash for {$row['user_name']}: ");
     }
     // now fill in the fields.
     foreach ($this->column_fields as $field) {
         $GLOBALS['log']->info($field);
         if (isset($row[$field])) {
             $GLOBALS['log']->info("=" . $row[$field]);
             $this->{$field} = $row[$field];
         }
     }
     $this->loadPreferences();
     require_once 'modules/Versions/CheckVersions.php';
     $invalid_versions = get_invalid_versions();
     if (!empty($invalid_versions)) {
         if (isset($invalid_versions['Rebuild Relationships'])) {
             unset($invalid_versions['Rebuild Relationships']);
             // flag for pickup in DisplayWarnings.php
             $_SESSION['rebuild_relationships'] = true;
         }
         if (isset($invalid_versions['Rebuild Extensions'])) {
             unset($invalid_versions['Rebuild Extensions']);
             // flag for pickup in DisplayWarnings.php
             $_SESSION['rebuild_extensions'] = true;
         }
         $_SESSION['invalid_versions'] = $invalid_versions;
     }
     $this->fill_in_additional_detail_fields();
     if ($this->status != "Inactive") {
         $this->authenticated = true;
     }
     unset($_SESSION['loginattempts']);
     return $this;
 }
Пример #3
0
 /**
  * Load a user based on the user_name in $this
  * @param string $user_password Password
  * @param bool $password_encoded Is password md5-encoded or plain text?
  * @return -- this if load was successul and null if load failed.
  */
 function load_user($user_password, $password_encoded = false)
 {
     global $login_error;
     unset($GLOBALS['login_error']);
     if (isset($_SESSION['loginattempts'])) {
         $_SESSION['loginattempts'] += 1;
     } else {
         $_SESSION['loginattempts'] = 1;
     }
     if ($_SESSION['loginattempts'] > 5) {
         $GLOBALS['log']->fatal('SECURITY: ' . $this->user_name . ' has attempted to login ' . $_SESSION['loginattempts'] . ' times from IP address: ' . $_SERVER['REMOTE_ADDR'] . '.');
         return null;
     }
     $GLOBALS['log']->debug("Starting user load for {$this->user_name}");
     if (!isset($this->user_name) || $this->user_name == "" || !isset($user_password) || $user_password == "") {
         return null;
     }
     if (!$password_encoded) {
         $user_password = md5($user_password);
     }
     $row = self::findUserPassword($this->user_name, $user_password);
     if (empty($row) || !empty($GLOBALS['login_error'])) {
         $GLOBALS['log']->fatal('SECURITY: User authentication for ' . $this->user_name . ' failed - could not Load User from Database');
         return null;
     }
     // now fill in the fields.
     $this->loadFromRow($row);
     $this->loadPreferences();
     require_once 'modules/Versions/CheckVersions.php';
     $invalid_versions = get_invalid_versions();
     if (!empty($invalid_versions)) {
         if (isset($invalid_versions['Rebuild Relationships'])) {
             unset($invalid_versions['Rebuild Relationships']);
             // flag for pickup in DisplayWarnings.php
             $_SESSION['rebuild_relationships'] = true;
         }
         if (isset($invalid_versions['Rebuild Extensions'])) {
             unset($invalid_versions['Rebuild Extensions']);
             // flag for pickup in DisplayWarnings.php
             $_SESSION['rebuild_extensions'] = true;
         }
         $_SESSION['invalid_versions'] = $invalid_versions;
     }
     if ($this->status != "Inactive") {
         $this->authenticated = true;
     }
     unset($_SESSION['loginattempts']);
     return $this;
 }