From 78ac3f712218ecd8012105c21335dd45693e149a Mon Sep 17 00:00:00 2001 From: viniciuscb Date: Wed, 3 Nov 2004 21:37:01 +0000 Subject: [PATCH] Fix: Added support for e-mail in user_id. --- phpgwapi/inc/class.sessions.inc.php | 52 ++++++++++++++++-------- phpgwapi/inc/class.sessions_db.inc.php | 4 +- phpgwapi/inc/class.sessions_php4.inc.php | 4 +- phpgwapi/inc/functions.inc.php | 3 +- 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/phpgwapi/inc/class.sessions.inc.php b/phpgwapi/inc/class.sessions.inc.php index 2f06aea02f..eb8f454601 100644 --- a/phpgwapi/inc/class.sessions.inc.php +++ b/phpgwapi/inc/class.sessions.inc.php @@ -129,14 +129,22 @@ */ var $xmlrpc_method_called; + /** + * @var Array with the name of the system domains + */ + var $phpgw_domains; + /** * Constructor just loads up some defaults from cookies */ - function sessions_() + function sessions_($domain_names=null) { $this->db = $GLOBALS['phpgw']->db; $this->sessionid = get_var('sessionid',array('GET','COOKIE')); $this->kp3 = get_var('kp3',array('GET','COOKIE')); + + $this->phpgw_domains = $domain_names; + /* Create the crypto object */ $GLOBALS['phpgw']->crypto = CreateObject('phpgwapi.crypto'); if ($GLOBALS['phpgw_info']['server']['usecookies']) @@ -245,9 +253,27 @@ function split_login_domain($both,&$login,&$domain) { $parts = explode('@',$both); - $domain = count($parts) > 1 ? array_pop($parts) : - $GLOBALS['phpgw_info']['server']['default_domain']; - $login = implode('@',$parts); + +// var_dump(debug_backtrace()); + //conference - for strings like vinicius@thyamad.com@default , + //allows that user have a login that is his e-mail. (viniciuscb) + if (count($parts) > 1) + { + $probable_domain = array_pop($parts); + //Last part of login string, when separated by @, is a domain name + if (in_array($probable_domain,$this->phpgw_domains)) + { + $got_login = true; + $domain = $probable_domain; + $login = implode('@',$parts); + } + } + + if (!$got_login) + { + $domain = $GLOBALS['phpgw_info']['server']['default_domain']; + $login = $both; + } } /** @@ -283,7 +309,7 @@ $this->session_flags = $session['session_flags']; - sessions_::split_login_domain($session['session_lid'],$this->account_lid,$this->account_domain); + $this->split_login_domain($session['session_lid'],$this->account_lid,$this->account_domain); $GLOBALS['phpgw_info']['user']['kp3'] = $this->kp3; @@ -465,7 +491,7 @@ } $this->clean_sessions(); - sessions_::split_login_domain($login,$this->account_lid,$this->account_domain); + $this->split_login_domain($login,$this->account_lid,$this->account_domain); $now = time(); @@ -794,21 +820,15 @@ function create_server($login,$passwd) { $GLOBALS['phpgw']->interserver = CreateObject('phpgwapi.interserver'); - $this->login = $login; +// $this->login = $login; $this->passwd = $passwd; $this->clean_sessions(); $login_array = explode('@', $login); - $this->account_lid = $login_array[0]; +// $this->account_lid = $login_array[0]; $now = time(); - if ($login_array[1] != '') - { - $this->account_domain = $login_array[1]; - } - else - { - $this->account_domain = $GLOBALS['phpgw_info']['server']['default_domain']; - } + $this->split_login_domain($login,$this->account_lid,$this->account_domain); + $this->login = $this->account_lid . '@' . $this->account_domain; $serverdata = array( 'server_name' => $this->account_domain, diff --git a/phpgwapi/inc/class.sessions_db.inc.php b/phpgwapi/inc/class.sessions_db.inc.php index e708cce67c..72452e166e 100644 --- a/phpgwapi/inc/class.sessions_db.inc.php +++ b/phpgwapi/inc/class.sessions_db.inc.php @@ -25,9 +25,9 @@ class sessions extends sessions_ { - function sessions() + function sessions($domain_names=null) { - $this->sessions_(); + $this->sessions_($domain_names); } function read_session() diff --git a/phpgwapi/inc/class.sessions_php4.inc.php b/phpgwapi/inc/class.sessions_php4.inc.php index d11f40c6f1..445e15e052 100644 --- a/phpgwapi/inc/class.sessions_php4.inc.php +++ b/phpgwapi/inc/class.sessions_php4.inc.php @@ -26,9 +26,9 @@ class sessions extends sessions_ { - function sessions() + function sessions($domain_names=null) { - $this->sessions_(); + $this->sessions_($domain_names); //controls the time out for php4 sessions - skwashd 18-May-2003 ini_set('session.gc_maxlifetime', $GLOBALS['phpgw_info']['server']['sessions_timeout']); session_name('sessionid'); diff --git a/phpgwapi/inc/functions.inc.php b/phpgwapi/inc/functions.inc.php index c7b1dfe1b0..fcceb7f369 100644 --- a/phpgwapi/inc/functions.inc.php +++ b/phpgwapi/inc/functions.inc.php @@ -127,6 +127,7 @@ $GLOBALS['phpgw_info']['server']['db_type'] = $GLOBALS['phpgw_domain'][$GLOBALS['phpgw_info']['server']['default_domain']]['db_type']; } + $domain_names = array_keys($GLOBALS['phpgw_domain']); if ($GLOBALS['phpgw_info']['flags']['currentapp'] != 'login' && ! $GLOBALS['phpgw_info']['server']['show_domain_selectbox']) { unset ($GLOBALS['phpgw_domain']); // we kill this for security reasons @@ -230,7 +231,7 @@ $GLOBALS['phpgw']->auth = CreateObject('phpgwapi.auth'); $GLOBALS['phpgw']->accounts = CreateObject('phpgwapi.accounts'); $GLOBALS['phpgw']->acl = CreateObject('phpgwapi.acl'); - $GLOBALS['phpgw']->session = CreateObject('phpgwapi.sessions'); + $GLOBALS['phpgw']->session = CreateObject('phpgwapi.sessions',$domain_names); $GLOBALS['phpgw']->preferences = CreateObject('phpgwapi.preferences'); $GLOBALS['phpgw']->applications = CreateObject('phpgwapi.applications'); print_debug('main class loaded', 'messageonly','api');