summaryrefslogtreecommitdiffstats
path: root/apps/contacts
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-02-20 15:24:54 +0100
committerThomas Tanghus <thomas@tanghus.net>2012-02-20 15:24:54 +0100
commitffdfe8257bb89750352553e71e863843e2416925 (patch)
tree9ed69da6cea084c06db64087926220d52cbffbef /apps/contacts
parent456ada01fa44a5de3146f58ea5de60baffe31521 (diff)
downloadnextcloud-server-ffdfe8257bb89750352553e71e863843e2416925.tar.gz
nextcloud-server-ffdfe8257bb89750352553e71e863843e2416925.zip
Contacts: Fix adding/updating address book with empty name.
Diffstat (limited to 'apps/contacts')
-rw-r--r--apps/contacts/ajax/createaddressbook.php8
-rw-r--r--apps/contacts/ajax/updateaddressbook.php9
-rw-r--r--apps/contacts/js/contacts.js22
-rw-r--r--apps/contacts/js/interface.js8
4 files changed, 34 insertions, 13 deletions
diff --git a/apps/contacts/ajax/createaddressbook.php b/apps/contacts/ajax/createaddressbook.php
index fbd70bae583..28944fe864c 100644
--- a/apps/contacts/ajax/createaddressbook.php
+++ b/apps/contacts/ajax/createaddressbook.php
@@ -13,7 +13,13 @@ OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
$userid = OC_User::getUser();
-$bookid = OC_Contacts_Addressbook::add($userid, strip_tags($_POST['name']), null);
+$name = trim(strip_tags($_POST['name']));
+if(!$name) {
+ OC_JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Cannot add addressbook with an empty name.'))));
+ OC_Log::write('contacts','ajax/createaddressbook.php: Cannot add addressbook with an empty name: '.strip_tags($_POST['name']), OC_Log::ERROR);
+ exit();
+}
+$bookid = OC_Contacts_Addressbook::add($userid, $name, null);
if(!$bookid) {
OC_JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error adding addressbook.'))));
OC_Log::write('contacts','ajax/createaddressbook.php: Error adding addressbook: '.$_POST['name'], OC_Log::ERROR);
diff --git a/apps/contacts/ajax/updateaddressbook.php b/apps/contacts/ajax/updateaddressbook.php
index b43b5b93a32..211df84b1d1 100644
--- a/apps/contacts/ajax/updateaddressbook.php
+++ b/apps/contacts/ajax/updateaddressbook.php
@@ -15,7 +15,14 @@ OC_JSON::checkAppEnabled('contacts');
$bookid = $_POST['id'];
OC_Contacts_App::getAddressbook($bookid); // is owner access check
-if(!OC_Contacts_Addressbook::edit($bookid, $_POST['name'], null)) {
+$name = trim(strip_tags($_POST['name']));
+if(!$name) {
+ OC_JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Cannot update addressbook with an empty name.'))));
+ OC_Log::write('contacts','ajax/updateaddressbook.php: Cannot update addressbook with an empty name: '.strip_tags($_POST['name']), OC_Log::ERROR);
+ exit();
+}
+
+if(!OC_Contacts_Addressbook::edit($bookid, $name, null)) {
OC_JSON::error(array('data' => array('message' => $l->t('Error updating addressbook.'))));
OC_Log::write('contacts','ajax/updateaddressbook.php: Error adding addressbook: ', OC_Log::ERROR);
//exit();
diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js
index d33f983a429..0e06b650a18 100644
--- a/apps/contacts/js/contacts.js
+++ b/apps/contacts/js/contacts.js
@@ -1043,13 +1043,13 @@ Contacts={
return false;
}else{
$.post(OC.filePath('contacts', 'ajax', 'deletebook.php'), { id: bookid},
- function(data) {
- if (data.status == 'success'){
+ function(jsondata) {
+ if (jsondata.status == 'success'){
$('#chooseaddressbook_dialog').dialog('destroy').remove();
Contacts.UI.Contacts.update();
Contacts.UI.Addressbooks.overview();
} else {
- Contacts.UI.messageBox(t('contacts', 'Error'), data.message);
+ Contacts.UI.messageBox(t('contacts', 'Error'), jsondata.data.message);
//alert('Error: ' + data.message);
}
});
@@ -1059,10 +1059,14 @@ Contacts={
Contacts.UI.notImplemented();
},
submit:function(button, bookid){
- var displayname = $("#displayname_"+bookid).val();
+ var displayname = $("#displayname_"+bookid).val().trim();
var active = $("#edit_active_"+bookid+":checked").length;
var description = $("#description_"+bookid).val();
-
+
+ if(displayname.length == 0) {
+ Contacts.UI.messageBox(t('contacts', 'Error'), t('contacts', 'Displayname cannot be empty.'));
+ return false;
+ }
var url;
if (bookid == 'new'){
url = OC.filePath('contacts', 'ajax', 'createaddressbook.php');
@@ -1070,12 +1074,14 @@ Contacts={
url = OC.filePath('contacts', 'ajax', 'updateaddressbook.php');
}
$.post(url, { id: bookid, name: displayname, active: active, description: description },
- function(data){
- if(data.status == 'success'){
+ function(jsondata){
+ if(jsondata.status == 'success'){
$(button).closest('tr').prev().html(data.page).show().next().remove();
+ Contacts.UI.Contacts.update();
+ } else {
+ Contacts.UI.messageBox(t('contacts', 'Error'), jsondata.data.message);
}
});
- Contacts.UI.Contacts.update();
},
cancel:function(button, bookid){
$(button).closest('tr').prev().show().next().remove();
diff --git a/apps/contacts/js/interface.js b/apps/contacts/js/interface.js
index fe58a46d247..5908dd767a2 100644
--- a/apps/contacts/js/interface.js
+++ b/apps/contacts/js/interface.js
@@ -124,12 +124,14 @@ Contacts={
url = OC.filePath('contacts', 'ajax', 'updateaddressbook.php');
}
$.post(url, { id: bookid, name: displayname, active: active, description: description },
- function(data){
- if(data.status == 'success'){
+ function(jsondata){
+ if(jsondata.status == 'success'){
$(button).closest('tr').prev().html(data.page).show().next().remove();
+ Contacts.UI.Contacts.update();
+ } else {
+ Contacts.UI.messageBox(t('contacts', 'Error'), jsondata.data.message);
}
});
- Contacts.UI.Contacts.update();
},
cancel:function(button, bookid){
$(button).closest('tr').prev().show().next().remove();