/** * Endpoint for user's settings. */ public function settingsEndpoint() { $this->verifyCheckSum(); $response = array(); try { $this->checkChatOpen(); $this->checkUserAuthentication(); $this->checkUserAuthorization(); $this->checkUserWriteAuthorization(); $this->checkPostParams(array('property', 'value')); $property = $this->getPostParam('property'); $value = $this->getPostParam('value'); switch ($property) { case 'userName': $this->checkPostParams(array('channelId')); $channel = $this->channelsDAO->get($this->getPostParam('channelId')); $this->checkChannel($channel); $this->checkChannelAuthorization($channel); $response['value'] = $this->userService->changeUserName($value); break; case 'textColor': $this->userService->setUserTextColor($value); break; default: $this->userSettingsDAO->setSetting($property, $value); } } catch (WiseChatUnauthorizedAccessException $exception) { $response['error'] = $exception->getMessage(); $this->sendUnauthorizedStatus(); } catch (Exception $exception) { $response['error'] = $exception->getMessage(); $this->sendBadRequestStatus(); } echo json_encode($response); die; }