mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-28 01:28:53 +01:00
- re-write of the phpgwapi::accounts_ldap::auto_add function
- set a default account email address as well as a user preference email address in the users' preferences - actually check if the account creation succeeds before we commit the transaction to the database. - remove some crap and make function readable
This commit is contained in:
parent
99ffa6ebc1
commit
606c1064be
@ -942,13 +942,9 @@
|
||||
|
||||
function auto_add($accountname, $passwd, $default_prefs = False, $default_acls = False, $expiredate = 0, $account_status = 'A')
|
||||
{
|
||||
if ($expiredate)
|
||||
if ($expiredate == 0)
|
||||
{
|
||||
$expires = mktime(2,0,0,date('n',$expiredate), (int)date('d',$expiredate), date('Y',$expiredate));
|
||||
}
|
||||
else
|
||||
{
|
||||
if($GLOBALS['phpgw_info']['server']['auto_create_expire'])
|
||||
if(isset($GLOBALS['phpgw_info']['server']['auto_create_expire']) == True)
|
||||
{
|
||||
if($GLOBALS['phpgw_info']['server']['auto_create_expire'] == 'never')
|
||||
{
|
||||
@ -957,16 +953,16 @@
|
||||
else
|
||||
{
|
||||
$expiredate = time() + $GLOBALS['phpgw_info']['server']['auto_create_expire'];
|
||||
$expires = mktime(2,0,0,date('n',$expiredate), (int)date('d',$expiredate), date('Y',$expiredate));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* expire in 30 days by default */
|
||||
$expiredate = time() + ((60 * 60) * (30 * 24));
|
||||
$expires = mktime(2,0,0,date('n',$expiredate), (int)date('d',$expiredate), date('Y',$expiredate));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* expire in 30 days by default */
|
||||
$expiredate = time() + ((60 * 60) * (30 * 24));
|
||||
}
|
||||
|
||||
$expires = mktime(2,0,0,date('n',$expiredate), (int)date('d',$expiredate), date('Y',$expiredate));
|
||||
|
||||
$default_group_id = $this->name2id($GLOBALS['phpgw_info']['server']['default_group_lid']);
|
||||
if (!$default_group_id)
|
||||
@ -987,55 +983,80 @@
|
||||
'account_expires' => $expires,
|
||||
'account_primary_group' => $primary_group,
|
||||
);
|
||||
if ($GLOBALS['auto_create_acct']['email'])
|
||||
|
||||
/* attempt to set an email address */
|
||||
if (isset($GLOBALS['auto_create_acct']['email']) == True && $GLOBALS['auto_create_acct']['email'] != '')
|
||||
{
|
||||
$acct_info['account_email'] = $GLOBALS['auto_create_acct']['email'];
|
||||
}
|
||||
$this->create($acct_info,$default_prefs);
|
||||
$accountid = $this->name2id($accountname);
|
||||
elseif(isset($GLOBALS['phpgw_info']['server']['mail_suffix']) == True && $GLOBALS['phpgw_info']['server']['mail_suffix'] != '')
|
||||
{
|
||||
$acct_info['account_email'] = $accountname . '@' . $GLOBALS['phpgw_info']['server']['mail_suffix'];
|
||||
}
|
||||
|
||||
$this->db->transaction_begin();
|
||||
if ($default_acls == False)
|
||||
{
|
||||
$apps = Array(
|
||||
'addressbook',
|
||||
'calendar',
|
||||
'email',
|
||||
'notes',
|
||||
'todo',
|
||||
'phpwebhosting',
|
||||
'manual'
|
||||
);
|
||||
|
||||
$this->create($acct_info,$default_prefs); /* create the account */
|
||||
|
||||
$default_group_lid = $GLOBALS['phpgw_info']['server']['default_group_lid'];
|
||||
$default_group_id = $this->name2id($default_group_lid);
|
||||
$defaultgroupid = $default_group_id ? $default_group_id : $this->name2id('Default');
|
||||
if($defaultgroupid)
|
||||
$accountid = $this->name2id($accountname); /* grab the account id or an error code */
|
||||
|
||||
if ($accountid) /* begin account setup */
|
||||
{
|
||||
if($primary_group)
|
||||
{
|
||||
$this->db->query("INSERT INTO phpgw_acl (acl_appname, acl_location, acl_account, acl_rights) VALUES('phpgw_group', "
|
||||
. $defaultgroupid . ", " . $accountid . ", 1)",__LINE__,__FILE__);
|
||||
. $primary_group . ", " . $accountid . ", 1)",__LINE__,__FILE__);
|
||||
}
|
||||
$this->db->query("INSERT INTO phpgw_acl (acl_appname, acl_location, acl_account, acl_rights)VALUES('preferences', 'changepassword', ".$accountid.", 1)",__LINE__,__FILE__);
|
||||
@reset($apps);
|
||||
while(list($key,$app) = each($apps))
|
||||
|
||||
/* FIXME - we are assuming the auth method is capable of password changing
|
||||
* $this->db->query("INSERT INTO phpgw_acl (acl_appname, acl_location, acl_account, acl_rights)VALUES('preferences', 'changepassword', ".$accountid.", 1)",__LINE__,__FILE__);
|
||||
*/
|
||||
|
||||
/* if we have an mail address set it in the uesrs' email preference */
|
||||
if (isset($GLOBALS['auto_create_acct']['email']) && $GLOBALS['auto_create_acct']['email'] != '')
|
||||
{
|
||||
$this->db->query("INSERT INTO phpgw_acl (acl_appname, acl_location, acl_account, acl_rights) VALUES ('".$app."', 'run', ".$accountid.", 1)",__LINE__,__FILE__);
|
||||
$GLOBALS['phpgw']->acl->acl($accountid); /* needed als preferences::save_repository calls acl */
|
||||
$GLOBALS['phpgw']->preferences->preferences($accountid);
|
||||
$GLOBALS['phpgw']->preferences->read_repository();
|
||||
$GLOBALS['phpgw']->preferences->add('email','address',$GLOBALS['auto_create_acct']['email']);
|
||||
$GLOBALS['phpgw']->preferences->save_repository();
|
||||
}
|
||||
/* use the default mail domain to set the uesrs' email preference */
|
||||
elseif(isset($GLOBALS['phpgw_info']['server']['mail_suffix']) && $GLOBALS['phpgw_info']['server']['mail_suffix'] != '')
|
||||
{
|
||||
$GLOBALS['phpgw']->acl->acl($accountid); /* needed als preferences::save_repository calls acl */
|
||||
$GLOBALS['phpgw']->preferences->preferences($accountid);
|
||||
$GLOBALS['phpgw']->preferences->read_repository();
|
||||
$GLOBALS['phpgw']->preferences->add('email','address', $accountname . '@' . $GLOBALS['phpgw_info']['server']['mail_suffix']);
|
||||
$GLOBALS['phpgw']->preferences->save_repository();
|
||||
}
|
||||
|
||||
/* commit the new account transaction */
|
||||
$this->db->transaction_commit();
|
||||
|
||||
/* does anyone know what the heck this is required for? */
|
||||
$GLOBALS['hook_values']['account_lid'] = $acct_info['account_lid'];
|
||||
$GLOBALS['hook_values']['account_id'] = $accountid;
|
||||
$GLOBALS['hook_values']['new_passwd'] = $acct_info['account_passwd'];
|
||||
$GLOBALS['hook_values']['account_status'] = $acct_info['account_status'];
|
||||
$GLOBALS['hook_values']['account_firstname'] = $acct_info['account_firstname'];
|
||||
$GLOBALS['hook_values']['account_lastname'] = $acct_info['account_lastname'];
|
||||
$GLOBALS['phpgw']->hooks->process($GLOBALS['hook_values']+array(
|
||||
'location' => 'addaccount'
|
||||
),False,True); // called for every app now, not only enabled ones
|
||||
|
||||
} /* end account setup */
|
||||
else /* if no account id abort the account creation */
|
||||
{
|
||||
$this->db->transaction_abort();
|
||||
}
|
||||
$this->db->transaction_commit();
|
||||
|
||||
$GLOBALS['hook_values']['account_lid'] = $acct_info['account_lid'];
|
||||
$GLOBALS['hook_values']['account_id'] = $accountid;
|
||||
$GLOBALS['hook_values']['new_passwd'] = $acct_info['account_passwd'];
|
||||
$GLOBALS['hook_values']['account_status'] = $acct_info['account_status'];
|
||||
$GLOBALS['hook_values']['account_firstname'] = $acct_info['account_lid'];
|
||||
$GLOBALS['hook_values']['account_lastname'] = 'eGW Account';
|
||||
$GLOBALS['phpgw']->hooks->process($GLOBALS['hook_values']+array(
|
||||
'location' => 'addaccount'
|
||||
),False,True); // called for every app now, not only enabled ones
|
||||
|
||||
/*
|
||||
* If we succeeded in creating the account (above), return the accountid, else,
|
||||
* return the error value from $this->name2id($accountname)
|
||||
*/
|
||||
return $accountid;
|
||||
}
|
||||
} /* end auto_add() */
|
||||
|
||||
function get_account_name($account_id,&$lid,&$fname,&$lname)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user