1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-12-01 13:24:10 +01:00

Contacts: Easier request parsing

This commit is contained in:
Thomas Tanghus 2013-03-26 12:34:37 +01:00
parent ebca7c662d
commit a82de8fad8

View File

@ -24,10 +24,8 @@ $this->create('contacts_index', '/')
- Check what it requires to be a RESTful API. I think maybe {user} - Check what it requires to be a RESTful API. I think maybe {user}
shouldn't be in the URI but be authenticated in headers or elsewhere. shouldn't be in the URI but be authenticated in headers or elsewhere.
- Do security checks: logged in, csrf - Do security checks: logged in, csrf
- Move the actual code to controllers.
*/ */
/*$this->create('core_lostpassword_send_email', 'contacts/contact/{id}')
->post()
->action('Utils\Properties', 'saveProperty');*/
$this->create('contacts_address_books_for_user', 'addressbooks/{user}/') $this->create('contacts_address_books_for_user', 'addressbooks/{user}/')
->get() ->get()
->action( ->action(
@ -138,14 +136,19 @@ $this->create('contacts_contact_delete_property', 'addressbook/{user}/{backend}/
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
$name = isset($_POST['name']) ? $_POST['name'] : null; $request = new Request($params);
$checksum = isset($_POST['checksum']) ? $_POST['checksum'] : null; $name = $request->post['name'];
$checksum = $request->post['checksum'];
debug('contacts_contact_delete_property, name: ' . print_r($name, true)); debug('contacts_contact_delete_property, name: ' . print_r($name, true));
debug('contacts_contact_delete_property, checksum: ' . print_r($checksum, true)); debug('contacts_contact_delete_property, checksum: ' . print_r($checksum, true));
$app = new App($params['user']); $app = new App($request->parameters['user']);
$contact = $app->getContact($params['backend'], $params['addressbookid'], $params['contactid']); $contact = $app->getContact(
$request->parameters['backend'],
$request->parameters['addressbookid'],
$request->parameters['contactid']
);
if(!$contact) { if(!$contact) {
bailOut(App::$l10n->t('Couldn\'t find contact.')); bailOut(App::$l10n->t('Couldn\'t find contact.'));
@ -170,9 +173,9 @@ $this->create('contacts_contact_delete_property', 'addressbook/{user}/{backend}/
} }
\OCP\JSON::success(array( \OCP\JSON::success(array(
'data' => array( 'data' => array(
'backend' => $params['backend'], 'backend' => $request->parameters['backend'],
'addressbookid' => $params['addressbookid'], 'addressbookid' => $request->parameters['addressbookid'],
'contactid' => $params['contactid'], 'contactid' => $request->parameters['contactid'],
'lastmodified' => $contact->lastModified(), 'lastmodified' => $contact->lastModified(),
) )
)); ));
@ -185,11 +188,12 @@ $this->create('contacts_contact_save_property', 'addressbook/{user}/{backend}/{a
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
$request = new Request($params);
// TODO: When value is empty unset the property and return a checksum of 'new' if multi_property // TODO: When value is empty unset the property and return a checksum of 'new' if multi_property
$name = isset($_POST['name']) ? $_POST['name'] : null; $name = $request->post['name'];
$value = isset($_POST['value']) ? $_POST['value'] : null; $value = $request->post['value'];
$parameters = isset($_POST['parameters']) ? $_POST['parameters'] : array(); $parameters = $request->post['parameters'];
$checksum = isset($_POST['checksum']) ? $_POST['checksum'] : null; $checksum = $request->post['checksum'];
debug('contacts_contact_save_property, name: ' . print_r($name, true)); debug('contacts_contact_save_property, name: ' . print_r($name, true));
debug('contacts_contact_save_property, value: ' . print_r($value, true)); debug('contacts_contact_save_property, value: ' . print_r($value, true));
@ -270,7 +274,8 @@ $this->create('contacts_categories_add', 'groups/{user}/add')
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
$name = isset($_POST['name']) ? trim(strip_tags($_POST['name'])) : null; $request = new Request($params);
$name = $request->post['name'];
if(is_null($name) || $name === "") { if(is_null($name) || $name === "") {
bailOut(App::$l10n->t('No group name given.')); bailOut(App::$l10n->t('No group name given.'));
@ -293,7 +298,8 @@ $this->create('contacts_categories_delete', 'groups/{user}/delete')
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
$name = isset($_POST['name']) ? trim(strip_tags($_POST['name'])) : null; $request = new Request($params);
$name = $request->post['name'];
if(is_null($name) || $name === "") { if(is_null($name) || $name === "") {
bailOut(App::$l10n->t('No group name given.')); bailOut(App::$l10n->t('No group name given.'));
@ -312,8 +318,9 @@ $this->create('contacts_setpreference', 'preference/{user}/set')
->action( ->action(
function($params) { function($params) {
session_write_close(); session_write_close();
$key = isset($_POST['key']) ? trim(strip_tags($_POST['key'])) : null; $request = new Request($params);
$value = isset($_POST['value']) ? trim(strip_tags($_POST['value'])) : null; $key = $request->post['key'];
$value = $request->post['value'];
if(is_null($key) || $key === "") { if(is_null($key) || $key === "") {
bailOut(App::$l10n->t('No key is given.')); bailOut(App::$l10n->t('No key is given.'));