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

Contacts: Move code to SettingsController

This commit is contained in:
Thomas Tanghus 2013-04-25 04:19:41 +02:00
parent a573aa16a5
commit 1c0c8097f2
2 changed files with 27 additions and 26 deletions

View File

@ -199,30 +199,7 @@ $this->create('contacts_setpreference', 'preference/{user}/set')
->action(
function($params) {
session_write_close();
$request = Request::getRequest($params);
$key = $request->post['key'];
$value = $request->post['value'];
if(is_null($key) || $key === "") {
bailOut(App::$l10n->t('No key is given.'));
}
if(is_null($value) || $value === "") {
bailOut(App::$l10n->t('No value is given.'));
}
if(\OCP\Config::setUserValue($params['user'], 'contacts', $key, $value)) {
\OCP\JSON::success(array(
'data' => array(
'key' => $key,
'value' => $value)
)
);
} else {
bailOut(App::$l10n->t(
'Could not set preference: ' . $key . ':' . $value)
);
}
Main::main('SettingsController', 'set', $params, new DIContainer());
}
)
->requirements(array('user'))

View File

@ -25,7 +25,31 @@ class SettingsController extends BaseController {
* @IsSubAdminExemption
* @Ajax
*/
public function getGroups() {
$params = $this->request->urlParams;
public function set() {
$request = $this->request;
$key = $request->post['key'];
$value = $request->post['value'];
$response = new JSONResponse();
if(is_null($key) || $key === "") {
$response->bailOut(App::$l10n->t('No key is given.'));
}
if(is_null($value) || $value === "") {
$response->bailOut(App::$l10n->t('No value is given.'));
}
if(\OCP\Config::setUserValue($this->api->getUserId(), 'contacts', $key, $value)) {
$response->setParams(array(
'key' => $key,
'value' => $value)
);
return $response;
} else {
$response->bailOut(App::$l10n->t(
'Could not set preference: ' . $key . ':' . $value)
);
}
}
}