/**
  * Sets a new name for current user.
  *
  * @param string $userName A new username to set
  *
  * @return string New username
  * @throws Exception On validation error
  */
 public function changeUserName($userName)
 {
     if (!$this->options->isOptionEnabled('allow_change_user_name') || $this->usersDAO->getCurrentWpUser() !== null || !$this->authentication->isAuthenticated()) {
         throw new Exception('Unsupported operation');
     }
     $userName = $this->authentication->validateUserName($userName);
     $user = $this->authentication->getUser();
     // set new username and refresh it:
     $user->setName($userName);
     $this->usersDAO->save($user);
     $this->refreshNewUserName($user);
     $this->authentication->setOriginalUserName($userName);
     return $userName;
 }