fix validation of email in account creation to allow to manually enter an email and never automatic add an invalid one

This commit is contained in:
Ralf Becker 2014-05-05 13:08:25 +00:00
parent 6f98614b15
commit 9e4a03c59c
2 changed files with 8 additions and 4 deletions

View File

@ -688,7 +688,7 @@ app.classes.addressbook = AppJS.extend(
};
this.egw.message('');
this.egw.json('admin_account::ajax_check', [data], function(_msg)
this.egw.json('admin_account::ajax_check', [data, _widget.id], function(_msg)
{
if (_msg && typeof _msg == 'string')
{

View File

@ -236,14 +236,18 @@ class admin_account
* Check entered data and return error-msg via json data or null
*
* @param array $data values for account_id and account_lid
* @param string $changed name of addressbook widget triggering change eg. "email", "n_given" or "n_family"
*/
public static function ajax_check(array $data)
public static function ajax_check(array $data, $changed)
{
// generate default email address
if (empty($data['account_email']) || !$data['account_id'])
if (empty($data['account_email']) || !$data['account_id'] && in_array($changed, array('n_given', 'n_family')))
{
$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 ($email && $email[0] != '@' && strpos($email, '@')) // only add valid email addresses
{
egw_json_response::get()->assign('addressbook-edit_email', 'value', $email);
}
}
if (!$data['account_lid'] && !$data['account_id']) return; // makes no sense to check before