2014-03-17 16:28:20 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EGroupware: Admin app UI: edit/add account
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <rb@stylite.de>
|
|
|
|
* @package admin
|
2019-09-26 22:31:30 +02:00
|
|
|
* @copyright (c) 2014-19 by Ralf Becker <rb@stylite.de>
|
2014-03-17 16:28:20 +01:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
*/
|
|
|
|
|
2016-04-27 21:12:20 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
use EGroupware\Api\Framework;
|
|
|
|
use EGroupware\Api\Acl;
|
|
|
|
use EGroupware\Api\Etemplate;
|
|
|
|
|
2014-03-17 16:28:20 +01:00
|
|
|
/**
|
|
|
|
* UI for admin: edit/add account
|
|
|
|
*/
|
|
|
|
class admin_account
|
|
|
|
{
|
2014-03-19 14:20:46 +01:00
|
|
|
/**
|
|
|
|
* Functions callable via menuaction
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $public_functions = array(
|
|
|
|
'delete' => true,
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook to edit account data via "Account" tab in addressbook edit dialog
|
|
|
|
*
|
|
|
|
* @param array $content
|
|
|
|
* @return array
|
2016-04-27 21:12:20 +02:00
|
|
|
* @throws Api\Exception\NotFound
|
2014-03-19 14:20:46 +01:00
|
|
|
*/
|
2014-03-17 16:28:20 +01:00
|
|
|
public function addressbook_edit(array $content)
|
|
|
|
{
|
2014-03-18 16:10:57 +01:00
|
|
|
if ((string)$content['owner'] === '0' && $GLOBALS['egw_info']['user']['apps']['admin'])
|
2014-03-17 16:28:20 +01:00
|
|
|
{
|
2014-03-18 16:10:57 +01:00
|
|
|
$deny_edit = $content['account_id'] ? $GLOBALS['egw']->acl->check('account_access', 16, 'admin') :
|
|
|
|
$GLOBALS['egw']->acl->check('account_access', 4, 'admin');
|
|
|
|
//error_log(__METHOD__."() contact_id=$content[contact_id], account_id=$content[account_id], deny_edit=".array2string($deny_edit));
|
|
|
|
|
2018-08-03 11:49:40 +02:00
|
|
|
if (!$content['account_id'] && $deny_edit) return; // no right to add new accounts, should not happen by AB ACL
|
2014-03-18 16:10:57 +01:00
|
|
|
|
2014-03-17 16:28:20 +01:00
|
|
|
// load our translations
|
2016-04-27 21:12:20 +02:00
|
|
|
Api\Translation::add_app('admin');
|
2014-03-17 16:28:20 +01:00
|
|
|
|
|
|
|
if ($content['id']) // existing account
|
|
|
|
{
|
2014-03-27 20:00:52 +01:00
|
|
|
// invalidate account, before reading it, to code with changed to DB or LDAP outside EGw
|
2016-04-27 21:12:20 +02:00
|
|
|
Api\Accounts::cache_invalidate((int)$content['account_id']);
|
2014-03-17 16:28:20 +01:00
|
|
|
if (!($account = $GLOBALS['egw']->accounts->read($content['account_id'])))
|
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
throw new Api\Exception\NotFound('Account data NOT found!');
|
2014-03-17 16:28:20 +01:00
|
|
|
}
|
|
|
|
if ($account['account_expires'] == -1) $account['account_expires'] = '';
|
|
|
|
unset($account['account_pwd']); // do NOT send to client
|
2018-08-03 11:49:40 +02:00
|
|
|
$account['account_groups'] = array_keys($account['memberships']);
|
2016-04-27 21:12:20 +02:00
|
|
|
$acl = new Acl($content['account_id']);
|
2014-03-17 16:28:20 +01:00
|
|
|
$acl->read_repository();
|
|
|
|
$account['anonymous'] = $acl->check('anonymous', 1, 'phpgwapi');
|
|
|
|
$account['changepassword'] = !$acl->check('nopasswordchange', 1, 'preferences');
|
2016-04-27 21:12:20 +02:00
|
|
|
$auth = new Api\Auth();
|
2014-03-17 16:28:20 +01:00
|
|
|
if (($account['account_lastpwd_change'] = $auth->getLastPwdChange($account['account_lid'])) === false)
|
|
|
|
{
|
|
|
|
$account['account_lastpwd_change'] = null;
|
|
|
|
}
|
|
|
|
$account['mustchangepassword'] = isset($account['account_lastpwd_change']) &&
|
|
|
|
(string)$account['account_lastpwd_change'] === '0';
|
|
|
|
}
|
|
|
|
else // new account
|
|
|
|
{
|
|
|
|
$account = array(
|
|
|
|
'account_status' => 'A',
|
2018-08-03 11:49:40 +02:00
|
|
|
'account_groups' => array(),
|
2014-03-17 16:28:20 +01:00
|
|
|
'anonymous' => false,
|
2014-03-18 16:10:57 +01:00
|
|
|
'changepassword' => true, //old default: (bool)$GLOBALS['egw_info']['server']['change_pwd_every_x_days'],
|
2014-03-17 16:28:20 +01:00
|
|
|
'mustchangepassword' => false,
|
2014-03-18 16:10:57 +01:00
|
|
|
'account_primary_group' => $GLOBALS['egw']->accounts->name2id('Default'),
|
2014-03-27 20:00:52 +01:00
|
|
|
'homedirectory' => $GLOBALS['egw_info']['server']['ldap_account_home'],
|
|
|
|
'loginshell' => $GLOBALS['egw_info']['server']['ldap_account_shell'],
|
2014-03-17 16:28:20 +01:00
|
|
|
);
|
|
|
|
}
|
2014-09-05 14:23:36 +02:00
|
|
|
// should we show extra ldap attributes home-directory and login-shell
|
|
|
|
$account['ldap_extra_attributes'] = $GLOBALS['egw_info']['server']['ldap_extra_attributes'] &&
|
2016-03-08 09:26:14 +01:00
|
|
|
get_class($GLOBALS['egw']->accounts->backend) === 'EGroupware\\Api\\Accounts\\Ldap';
|
2014-09-05 14:23:36 +02:00
|
|
|
|
2014-03-18 16:10:57 +01:00
|
|
|
$readonlys = array();
|
|
|
|
|
2015-07-01 16:58:07 +02:00
|
|
|
// at least ADS does not allow to unset it and SQL backend does not implement it either
|
|
|
|
if ($account['mustchangepassword'])
|
|
|
|
{
|
|
|
|
$readonlys['mustchangepassword'] = true;
|
|
|
|
}
|
|
|
|
|
2014-03-18 16:10:57 +01:00
|
|
|
if ($deny_edit)
|
|
|
|
{
|
|
|
|
foreach(array_keys($account) as $key)
|
|
|
|
{
|
|
|
|
$readonlys[$key] = true;
|
|
|
|
}
|
|
|
|
$readonlys['account_passwd'] = $readonlys['account_passwd2'] = true;
|
|
|
|
}
|
2014-03-17 16:28:20 +01:00
|
|
|
return array(
|
2016-02-03 16:20:50 +01:00
|
|
|
'name' => 'admin.account',
|
2014-03-17 16:28:20 +01:00
|
|
|
'prepend' => true,
|
|
|
|
'label' => 'Account',
|
|
|
|
'data' => $account,
|
2014-03-28 18:58:17 +01:00
|
|
|
// save old values to only trigger save, if one of the following values change (contact data get saved anyway)
|
2018-08-03 11:49:40 +02:00
|
|
|
'preserve' => empty($content['id']) ? array() :
|
|
|
|
array('old_account' => array_intersect_key($account, array_flip(array(
|
|
|
|
'account_lid', 'account_status', 'account_groups', 'anonymous', 'changepassword',
|
|
|
|
'mustchangepassword', 'account_primary_group', 'homedirectory', 'loginshell',
|
|
|
|
'account_expires', 'account_firstname', 'account_lastname', 'account_email'))),
|
|
|
|
'deny_edit' => $deny_edit),
|
2014-03-18 16:10:57 +01:00
|
|
|
'readonlys' => $readonlys,
|
|
|
|
'pre_save_callback' => $deny_edit ? null : 'admin_account::addressbook_pre_save',
|
2014-03-17 16:28:20 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2014-03-18 16:10:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook called by addressbook prior to saving addressbook data
|
|
|
|
*
|
|
|
|
* @param array &$content
|
|
|
|
* @throws Exception for errors
|
|
|
|
* @return string Success message
|
|
|
|
*/
|
|
|
|
public static function addressbook_pre_save(&$content)
|
|
|
|
{
|
2018-08-03 11:49:40 +02:00
|
|
|
if (!isset($content['mustchangepassword']))
|
|
|
|
{
|
|
|
|
$content['mustchangepassword'] = true; // was readonly because already set
|
|
|
|
}
|
|
|
|
$content['account_firstname'] = $content['n_given'];
|
|
|
|
$content['account_lastname'] = $content['n_family'];
|
|
|
|
$content['account_email'] = $content['email'];
|
2018-11-13 23:57:20 +01:00
|
|
|
if($content['account_passwd'] && $content['account_passwd'] !== $content['account_passwd_2'])
|
|
|
|
{
|
|
|
|
throw new Api\Exception\WrongUserinput('Passwords are not the same');
|
|
|
|
}
|
2018-08-03 12:41:53 +02:00
|
|
|
if (!empty($content['old_account']))
|
|
|
|
{
|
|
|
|
$old = array_diff_assoc($content['old_account'], $content);
|
|
|
|
// array_diff_assoc compares everything as string (cast to string)
|
|
|
|
if ($content['old_account']['account_groups'] != $content['account_groups'])
|
|
|
|
{
|
|
|
|
$old['account_groups'] = $content['old_account']['account_groups'];
|
|
|
|
}
|
2018-11-13 23:57:20 +01:00
|
|
|
if($content['account_passwd'])
|
|
|
|
{
|
|
|
|
// Don't put password into history
|
|
|
|
$old['account_passwd'] = '';
|
|
|
|
}
|
2018-08-03 12:41:53 +02:00
|
|
|
}
|
2018-09-05 17:16:36 +02:00
|
|
|
if ($content['deny_edit'] || $old === array())
|
2014-03-28 18:58:17 +01:00
|
|
|
{
|
|
|
|
return ''; // no need to save account data, if nothing changed
|
|
|
|
}
|
2014-03-18 16:10:57 +01:00
|
|
|
//error_log(__METHOD__."(".array2string($content).")");
|
|
|
|
$account = array();
|
|
|
|
foreach(array(
|
|
|
|
// need to copy/rename some fields named different in account and contact
|
|
|
|
'n_given' => 'account_firstname',
|
|
|
|
'n_family' => 'account_lastname',
|
|
|
|
'email' => 'account_email',
|
2018-08-03 11:49:40 +02:00
|
|
|
'account_groups',
|
2014-03-18 16:10:57 +01:00
|
|
|
// copy following fields to account
|
2018-08-03 11:49:40 +02:00
|
|
|
'account_lid',
|
2014-03-18 16:10:57 +01:00
|
|
|
'changepassword', 'anonymous', 'mustchangepassword',
|
2016-04-29 13:45:01 +02:00
|
|
|
'account_passwd', 'account_passwd_2',
|
2014-03-18 16:10:57 +01:00
|
|
|
'account_primary_group',
|
2019-03-14 15:14:25 +01:00
|
|
|
'account_expires', 'account_status',
|
2014-10-21 10:58:08 +02:00
|
|
|
'homedirectory', 'loginshell',
|
2018-08-02 11:40:02 +02:00
|
|
|
'requested', 'requested_email', 'comment', // admin_cmd documentation (EPL)
|
2014-03-18 16:10:57 +01:00
|
|
|
) as $c_name => $a_name)
|
|
|
|
{
|
|
|
|
if (is_int($c_name)) $c_name = $a_name;
|
|
|
|
|
2018-08-03 11:49:40 +02:00
|
|
|
// only record real changes
|
|
|
|
if (isset($content['old_account']) &&
|
2019-01-30 17:22:12 +01:00
|
|
|
// currently LDAP (and probably also AD and UCS) can not skip unchanged fields!
|
|
|
|
get_class($GLOBALS['egw']->accounts->backend) === 'EGroupware\\Api\\Accounts\\Sql' &&
|
2018-08-03 11:49:40 +02:00
|
|
|
(!isset($content[$c_name]) && $c_name !== 'account_expires' || // account_expires is not set when empty!
|
|
|
|
$content['old_account'][$a_name] == $content[$c_name]))
|
|
|
|
{
|
|
|
|
continue; // no change --> no need to log setting it to identical value
|
|
|
|
}
|
|
|
|
|
2014-03-18 16:10:57 +01:00
|
|
|
switch($a_name)
|
|
|
|
{
|
|
|
|
case 'account_expires':
|
2019-03-14 15:14:25 +01:00
|
|
|
case 'account_status':
|
|
|
|
$account['account_expires'] = $content['account_expires'] ? $content['account_expires'] :
|
2014-06-04 22:02:01 +02:00
|
|
|
($content['account_status'] ? 'never' : 'already');
|
2014-03-18 16:10:57 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'changepassword': // boolean values: admin_cmd_edit_user understands '' as NOT set
|
|
|
|
case 'anonymous':
|
|
|
|
case 'mustchangepassword':
|
|
|
|
$account[$a_name] = (boolean)$content[$c_name];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$account[$a_name] = $content[$c_name];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-05-05 16:46:01 +02:00
|
|
|
// Make sure primary group is in account groups
|
2018-09-06 15:23:32 +02:00
|
|
|
if (isset($account['account_groups']) && $account['account_primary_group'] &&
|
|
|
|
!in_array($account['account_primary_group'], (array)$account['account_groups']))
|
2014-05-05 16:46:01 +02:00
|
|
|
{
|
|
|
|
$account['account_groups'][] = $account['account_primary_group'];
|
|
|
|
}
|
2014-03-18 16:10:57 +01:00
|
|
|
|
2018-08-03 15:38:34 +02:00
|
|
|
$cmd = new admin_cmd_edit_user(array(
|
|
|
|
'account' => (int)$content['account_id'],
|
|
|
|
'set' => $account,
|
|
|
|
'old' => $old,
|
|
|
|
)+(array)$content['admin_cmd']);
|
2014-03-18 16:10:57 +01:00
|
|
|
$cmd->run();
|
|
|
|
|
2016-04-27 21:12:20 +02:00
|
|
|
Api\Json\Response::get()->call('egw.refresh', '', 'admin', $cmd->account, $content['account_id'] ? 'edit' : 'add');
|
2014-03-18 19:31:52 +01:00
|
|
|
|
2016-04-27 21:12:20 +02:00
|
|
|
$addressbook_bo = new Api\Contacts();
|
|
|
|
if (!($content['id'] = Api\Accounts::id2name($cmd->account, 'person_id')) ||
|
2014-06-05 10:42:45 +02:00
|
|
|
!($contact = $addressbook_bo->read($content['id'])))
|
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
throw new Api\Exception\AssertionFailed("Can't find contact of just created account!");
|
2014-06-05 10:42:45 +02:00
|
|
|
}
|
2014-03-18 16:10:57 +01:00
|
|
|
// for a new account a new contact was created, need to merge that data with $content
|
|
|
|
if (!$content['account_id'])
|
|
|
|
{
|
|
|
|
$content['account_id'] = $cmd->account;
|
|
|
|
$content = array_merge($contact, $content);
|
|
|
|
}
|
2014-06-05 10:42:45 +02:00
|
|
|
else // for updated account, we need to refresh etag
|
|
|
|
{
|
|
|
|
$content['etag'] = $contact['etag'];
|
|
|
|
}
|
2014-03-18 16:10:57 +01:00
|
|
|
}
|
2014-03-19 14:20:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete an account
|
|
|
|
*
|
2014-10-17 15:51:28 +02:00
|
|
|
* @param array $content =null
|
2014-03-19 14:20:46 +01:00
|
|
|
*/
|
|
|
|
public static function delete(array $content=null)
|
|
|
|
{
|
|
|
|
if (!is_array($content))
|
|
|
|
{
|
|
|
|
if (isset($_GET['contact_id']) && ($account_id = $GLOBALS['egw']->accounts->name2id((int)$_GET['contact_id'], 'person_id')))
|
|
|
|
{
|
|
|
|
$content = array(
|
|
|
|
'account_id' => $account_id,
|
|
|
|
'contact_id' => (int)$_GET['contact_id'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$content = array('account_id' => (int)$_GET['account_id']);
|
|
|
|
}
|
2014-03-19 16:24:54 +01:00
|
|
|
//error_log(__METHOD__."() \$_GET[account_id]=$_GET[account_id], \$_GET[contact_id]=$_GET[contact_id] content=".array2string($content));
|
2014-03-19 14:20:46 +01:00
|
|
|
}
|
2018-08-23 12:40:18 +02:00
|
|
|
if ($GLOBALS['egw']->acl->check('account_access',32,'admin') ||
|
2014-03-19 14:20:46 +01:00
|
|
|
$GLOBALS['egw_info']['user']['account_id'] == $content['account_id'])
|
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
Framework::window_close(lang('Permission denied!!!'));
|
2014-03-19 14:20:46 +01:00
|
|
|
}
|
|
|
|
if ($content['delete'])
|
|
|
|
{
|
2019-07-19 22:31:27 +02:00
|
|
|
$cmd = new admin_cmd_delete_account(array(
|
|
|
|
'account' => $content['account_id'],
|
|
|
|
'new_user' => $content['new_owner'],
|
|
|
|
'is_user' => $content['account_id'] > 0,
|
|
|
|
'change_apps' => $content['delete_apps']
|
|
|
|
) + (array)$content['admin_cmd']);
|
2014-03-19 14:20:46 +01:00
|
|
|
$msg = $cmd->run();
|
|
|
|
if ($content['contact_id'])
|
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
Framework::refresh_opener($msg, 'addressbook', $content['contact_id'], 'delete');
|
2014-03-19 14:20:46 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
Framework::refresh_opener($msg, 'admin', $content['account_id'], 'delete');
|
2014-03-19 14:20:46 +01:00
|
|
|
}
|
2016-04-27 21:12:20 +02:00
|
|
|
Framework::window_close();
|
2014-03-19 14:20:46 +01:00
|
|
|
}
|
2019-07-19 22:31:27 +02:00
|
|
|
|
|
|
|
$sel_options = array();
|
|
|
|
$preserve = $content;
|
|
|
|
|
|
|
|
// Get a count of entries owned by the user
|
|
|
|
$counts = $GLOBALS['egw']->accounts->get_account_entry_counts($content['account_id']);
|
|
|
|
foreach($counts as $app => $counts)
|
|
|
|
{
|
|
|
|
$entry = Api\Link::get_registry($app, 'entries');
|
|
|
|
if(!$entry)
|
|
|
|
{
|
|
|
|
$entry = lang('Entries');
|
|
|
|
}
|
2019-07-22 19:49:57 +02:00
|
|
|
if($counts['total'] && Api\Hooks::exists('deleteaccount', $app))
|
2019-07-19 22:31:27 +02:00
|
|
|
{
|
|
|
|
$content['delete_apps'][] = $app;
|
|
|
|
$sel_options['delete_apps'][] = array(
|
|
|
|
'value' => $app,
|
|
|
|
'label' => lang($app) . ': ' . $counts['total'] . ' '.$entry
|
|
|
|
);
|
|
|
|
}
|
2019-07-22 19:49:57 +02:00
|
|
|
else if ($counts['total'])
|
|
|
|
{
|
|
|
|
// These ones don't support the needed hook
|
|
|
|
$content['counts'][] = array(
|
|
|
|
'app' => $app,
|
|
|
|
'count' => $counts['total'] . ' '.$entry
|
|
|
|
);
|
|
|
|
}
|
2019-07-19 22:31:27 +02:00
|
|
|
}
|
2019-11-06 17:49:33 +01:00
|
|
|
// Add filemanager home directory in as special case, hook is in the API
|
|
|
|
if(Api\Vfs::file_exists('/home/'.$GLOBALS['egw']->accounts->id2name($content['account_id'])))
|
|
|
|
{
|
|
|
|
$app = 'filemanager';
|
|
|
|
$sel_options['delete_apps'][] = array(
|
|
|
|
'value' => $app,
|
|
|
|
'label' => lang($app) . ': ' . lang('home directory')
|
|
|
|
);
|
|
|
|
$content['delete_apps'][] = $app;
|
|
|
|
}
|
2016-04-27 21:12:20 +02:00
|
|
|
$tpl = new Etemplate('admin.account.delete');
|
2019-07-19 22:31:27 +02:00
|
|
|
$tpl->exec('admin_account::delete', $content, $sel_options, array(), $preserve, 2);
|
2014-03-19 14:20:46 +01:00
|
|
|
}
|
2014-03-19 16:24:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a group via ajax
|
|
|
|
*
|
|
|
|
* @param int $account_id
|
2019-05-28 17:59:55 +02:00
|
|
|
* @param String[] $data Optional data
|
2014-03-19 16:24:54 +01:00
|
|
|
*/
|
2019-05-28 17:59:55 +02:00
|
|
|
public static function ajax_delete_group($account_id, $data)
|
2014-03-19 16:24:54 +01:00
|
|
|
{
|
2019-09-26 22:31:30 +02:00
|
|
|
$cmd = new admin_cmd_delete_account(Api\Accounts::id2name(Api\Accounts::id2name($account_id)), null, false, (array)$data['admin_cmd']);
|
2014-03-19 16:24:54 +01:00
|
|
|
$msg = $cmd->run();
|
|
|
|
|
2016-04-27 21:12:20 +02:00
|
|
|
Api\Json\Response::get()->call('egw.refresh', $msg, 'admin', $account_id, 'delete');
|
2014-03-19 16:24:54 +01:00
|
|
|
}
|
2014-03-28 17:56:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check entered data and return error-msg via json data or null
|
|
|
|
*
|
|
|
|
* @param array $data values for account_id and account_lid
|
2014-05-05 15:08:25 +02:00
|
|
|
* @param string $changed name of addressbook widget triggering change eg. "email", "n_given" or "n_family"
|
2014-03-28 17:56:35 +01:00
|
|
|
*/
|
2014-05-05 15:08:25 +02:00
|
|
|
public static function ajax_check(array $data, $changed)
|
2014-03-28 17:56:35 +01:00
|
|
|
{
|
2018-01-22 12:42:09 +01:00
|
|
|
// warn if anonymous user is renamed, as it breaks eg. sharing and Collabora
|
|
|
|
if ($changed == 'account_lid' && Api\Accounts::id2name($data['account_id']) === 'anonymous' && $data['account_lid'] !== 'anonymous')
|
|
|
|
{
|
|
|
|
Api\Json\Response::get()->data(lang("Renaming user 'anonymous' will break file sharing and Collabora Online Office!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-12 13:46:30 +02:00
|
|
|
// for 1. password field just check password complexity
|
|
|
|
if ($changed == 'account_passwd')
|
|
|
|
{
|
|
|
|
$data['account_fullname'] = $data['account_firstname'].' '.$data['account_lastname'];
|
|
|
|
if (($error = Api\Auth::crackcheck($data['account_passwd'], null, null, null, $data)))
|
|
|
|
{
|
|
|
|
$error .= "\n\n".lang('If you ignore that error as admin, you should check "%1"!', lang('Must change password upon next login'));
|
|
|
|
}
|
|
|
|
Api\Json\Response::get()->data($error);
|
|
|
|
return;
|
|
|
|
}
|
2016-04-27 21:12:20 +02:00
|
|
|
// generate default email address, but only for new Api\Accounts
|
2014-09-04 09:41:30 +02:00
|
|
|
if (!$data['account_id'] && in_array($changed, array('n_given', 'n_family', 'account_lid')))
|
2014-03-28 17:56:35 +01:00
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
$email = Api\Accounts::email($data['account_firstname'], $data['account_lastname'], $data['account_lid']);
|
2014-05-05 15:08:25 +02:00
|
|
|
if ($email && $email[0] != '@' && strpos($email, '@')) // only add valid email addresses
|
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
Api\Json\Response::get()->assign('addressbook-edit_email', 'value', $email);
|
2014-05-05 15:08:25 +02:00
|
|
|
}
|
2014-03-28 17:56:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$data['account_lid'] && !$data['account_id']) return; // makes no sense to check before
|
|
|
|
|
2016-04-27 21:12:20 +02:00
|
|
|
// set home-directory when account_lid is entered, but only for new Api\Accounts
|
2014-10-21 10:58:08 +02:00
|
|
|
if ($changed == 'account_lid' && !$data['account_id'] &&
|
|
|
|
$GLOBALS['egw_info']['server']['ldap_extra_attributes'] &&
|
|
|
|
$GLOBALS['egw_info']['server']['ldap_account_home'])
|
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
Api\Json\Response::get()->assign('addressbook-edit_homedirectory', 'value',
|
2014-10-21 10:58:08 +02:00
|
|
|
$GLOBALS['egw_info']['server']['ldap_account_home'].'/'.preg_replace('/[^a-z0-9_.-]/i', '',
|
2016-04-27 21:12:20 +02:00
|
|
|
Api\Translation::to_ascii($data['account_lid'])));
|
2014-10-21 10:58:08 +02:00
|
|
|
}
|
|
|
|
|
2014-03-28 17:56:35 +01:00
|
|
|
// set dummy membership to get no error about no members yet
|
|
|
|
$data['account_memberships'] = array($data['account_primary_user'] = $GLOBALS['egw_info']['user']['account_primary_group']);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$cmd = new admin_cmd_edit_user($data['account_id'], $data);
|
|
|
|
$cmd->run(null, false, false, true);
|
|
|
|
}
|
|
|
|
catch(Exception $e)
|
|
|
|
{
|
2016-04-27 21:12:20 +02:00
|
|
|
Api\Json\Response::get()->data($e->getMessage());
|
2014-03-28 17:56:35 +01:00
|
|
|
}
|
|
|
|
}
|
2014-03-17 16:28:20 +01:00
|
|
|
}
|