added several checks for account editing in addressbook: doublicate account name, passwords match, set email for new accounts according to policy

This commit is contained in:
Ralf Becker 2014-03-28 16:56:35 +00:00
parent 13ad291696
commit 8cfef6746d
8 changed files with 94 additions and 19 deletions

View File

@ -113,8 +113,8 @@ app.classes.addressbook = AppJS.extend(
var list = etemplate2.getById(
$j(this.et2.getInstanceManager().DOMContainer).nextAll('.et2_container').attr('id')
);
var nm = null;
if(list != null && (nm = list.widgetContainer.getWidgetById('nm')))
var nm = list ? list.widgetContainer.getWidgetById('nm') : null;
if(nm)
{
// Update the link filter to new contact
var filter = {col_filter:{}};
@ -379,6 +379,12 @@ app.classes.addressbook = AppJS.extend(
*/
check_value: function(widget, own_id)
{
// if we edit an account, call account_change to let it do it's stuff too
if (this.et2.getWidgetById('account_lid'))
{
this.account_change(null, widget);
}
var values = this.et2._inst.getValues(this.et2);
if (widget.id.match(/n_/))
@ -653,6 +659,44 @@ app.classes.addressbook = AppJS.extend(
return false;
}
return this._super.apply(this, arguments);
}
},
/**
* Field changed, call server validation
*
* @param {jQuery.Event} _ev
* @param {et2_button} _widget
*/
account_change: function(_ev, _widget)
{
switch(_widget.id)
{
case 'account_lid':
case 'n_family':
case 'n_given':
case 'email':
case 'account_passwd_2':
var values = this.et2._inst.getValues(this.et2);
var data = {
account_id: this.et2.getArrayMgr('content').data.account_id,
account_lid: values.account_lid,
account_firstname: values.n_given,
account_lastname: values.n_family,
account_email: values.email,
account_passwd: values.account_passwd,
account_passwd_2: values.account_passwd_2
};
this.egw.message('');
this.egw.json('admin_account::ajax_check', [data], function(_msg)
{
if (_msg && typeof _msg == 'string')
{
egw(window).message(_msg, 'error'); // context get's lost :(
_widget.getDOMNode().focus();
}
}, this).sendRequest();
break;
}
}
});

View File

@ -48,7 +48,7 @@
</row>
<row>
<description/>
<button label="Ok" id="button[ok]" class="button_ok" onclick="jQuery('table.editname').css('display','none'); if(document.getElementById(form::name('title'))){document.getElementById(form::name('title')).focus();} return false;" image="check" background_image="1"/>
<button label="Ok" id="button[ok]" class="button_ok" onclick="jQuery('table.editname').css('display','none'); jQuery('#'+form::name('org_name')).focus(); return false;" image="check" background_image="1"/>
</row>
</rows>
</grid>

View File

@ -223,4 +223,33 @@ class admin_account
egw_json_response::get()->call('egw.refresh', $msg, 'admin', $account_id, 'delete');
}
/**
* Check entered data and return error-msg via json data or null
*
* @param array $data values for account_id and account_lid
*/
public static function ajax_check(array $data)
{
// generate default email address
if (empty($data['account_email']) || !$data['account_id'])
{
$email = common::email_address($data['account_firstname'], $data['account_lastname'], $data['account_lid']);
if ($email) egw_json_response::get()->assign('addressbook-edit_email', 'value', $email);
}
if (!$data['account_lid'] && !$data['account_id']) return; // makes no sense to check before
// 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)
{
egw_json_response::get()->data($e->getMessage());
}
}
}

View File

@ -81,7 +81,7 @@ class admin_cmd_edit_group extends admin_cmd
}
if ($check_only) return true;
if ($this->account)
if (($update = $this->account))
{
// invalidate account, before reading it, to code with changed to DB or LDAP outside EGw
accounts::cache_invalidate($data['account_id']);
@ -102,15 +102,18 @@ class admin_cmd_edit_group extends admin_cmd
}
$GLOBALS['hook_values'] =& $data;
$GLOBALS['egw']->hooks->process($GLOBALS['hook_values']+array(
'location' => $this->account ? 'editgroup' : 'addgroup'
'location' => $update ? 'editgroup' : 'addgroup'
),False,True); // called for every app now, not only enabled ones)
if ($data['account_members'])
{
admin_cmd::$accounts->set_members($data['account_members'],$data['account_id']);
}
return lang("Account %1 %2",$this->account ? $this->account : $data['account_lid'],
$this->account ? lang('updated') : lang("created with id #%1",$data['account_id']));
// make new account_id available to caller
$this->account = $data['account_id'];
return lang("Account %1 %2", $data['account_lid'] ? $data['account_lid'] : accounts::id2name($this->account),
$update ? lang('updated') : lang("created with id #%1", $this->account));
}
/**

View File

@ -144,6 +144,7 @@ class admin_cmd_edit_user extends admin_cmd_change_pw
throw new egw_exception_db(lang("Error saving account!"),11);
}
// make new account_id available to caller
$update = (boolean)$this->account;
if (!$this->account) $this->account = $data['account_id'];
if ($data['account_groups'])
@ -184,11 +185,11 @@ class admin_cmd_edit_user extends admin_cmd_change_pw
$data['account_passwd'] = $this->password;
$GLOBALS['hook_values'] =& $data;
$GLOBALS['egw']->hooks->process($GLOBALS['hook_values']+array(
'location' => $this->account && $this->run_addaccount_hook !== true ? 'editaccount' : 'addaccount'
'location' => $update && $this->run_addaccount_hook !== true ? 'editaccount' : 'addaccount'
),False,True); // called for every app now, not only enabled ones)
return lang("Account %1 %2",$this->account ? $this->account : $data['account_lid'],
$this->account ? lang('updated') : lang("created with id #%1",$data['account_id']));
return lang("Account %1 %2", $data['account_lid'] ? $data['account_lid'] : accounts::id2name($this->account),
$update ? lang('updated') : lang("created with id #%1", $this->account));
}
/**

View File

@ -5,7 +5,7 @@
* @link http://www.egroupware.org
* @author Ralf Becker <rb@stylite.de>
* @package admin
* @copyright (c) 2013 by Ralf Becker <rb@stylite.de>
* @copyright (c) 2013-14 by Ralf Becker <rb@stylite.de>
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/

View File

@ -4,7 +4,7 @@
* @link http://www.egroupware.org
* @package filemanager
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @copyright (c) 2013 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @copyright (c) 2013-14 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
@ -122,9 +122,7 @@ app.classes.admin = AppJS.extend(
tree.deleteItem('/groups/'+_id, false);
break;
case 'edit':
case 'update':
case 'add':
default: // add, update, edit, null
tree.refreshItem('/groups');
break;
}

View File

@ -15,7 +15,7 @@
<rows>
<row>
<description value="Login ID" for="account_lid"/>
<textbox id="account_lid" class="et2_fullWidth"/>
<textbox id="account_lid" class="et2_fullWidth" onchange="app.addressbook.account_change" needed="true"/>
<description/>
<description value="Expires" for="account_expires"/>
<hbox>
@ -28,8 +28,8 @@
<description value="Password" for="account_passwd"/>
<passwd id="account_passwd" class="et2_fullWidth"/>
<description/>
<description value="Re-enter password" for="account_passwd2"/>
<passwd id="account_passwd2" class="et2_fullWidth"/>
<description value="Re-enter password" for="account_passwd_2"/>
<passwd id="account_passwd_2" class="et2_fullWidth" onchange="app.addressbook.account_change"/>
<description/>
</row>
<row valign="top">