+
+ public function updateAction($facebookId)
+ {
+ if(!$user = $this->_userSession->getCurrentUser()) $this->_statusReporter->error('You must be authenticated update your account.');
+ $userUpdateData = $this->userFromJson($this->_request->getBody());
+
+ try
+ {
+ if(isset($userUpdateData->displayName)) $user->setDisplayName($userUpdateData->displayName);
+ //TODO: Direct instantiation bad?
+ if(isset($userUpdateData->country)) $user->setCountry(new Country($userUpdateData->country));
+ $this->_userRepository->save($user);
+ } catch (Exception $e) {
+ if(strpos($e->getMessage(), 'Duplicate entry') !== false)
+ {
+ $this->_statusReporter->error('Sorry, that display name is already in use.');
+ }
+
+ if($e instanceof InvalidCountryException)
+ {
+ $this->_statusReporter->error($userUpdateData->country . ' is not a valid country.');
+ }
+ }
+
+ $this->_statusReporter->success();
+ }
+
+ private function userFromJson($json)
+ {
+ $user = json_decode($json);
+ if(json_last_error() !== JSON_ERROR_NONE || !$user) $this->_statusReporter->error ('Malformed or missing JSON');
+
+ return $user;
+ }