public function alterarDadosCadastrais() { try { $nome = trim($_POST['nome']); $email = trim($_POST['email']); $senhaAtual = trim($_POST['senhaAtual']); $novaSenha = trim($_POST['novaSenha']); $confirmarNovaSenha = trim($_POST['confirmarNovaSenha']); if (empty($nome)) { throw new \Exception("O nome é obrigatório."); } if (empty($email)) { throw new \Exception("O email é obrigatório."); } $usuarioLogado = $this->getUsuarioLogado(); $usuarioLogado->nome = $nome; $usuarioLogado->email = $email; if (!empty($senhaAtual)) { if ($senhaAtual != $usuarioLogado->senha) { throw new \Exception("Senha atual não confere."); } if (empty($novaSenha)) { throw new \Exception("Informe a nova senha."); } if (empty($confirmarNovaSenha)) { throw new \Exception("Confirme a nova senha."); } if ($novaSenha != $confirmarNovaSenha) { throw new \Exception("Confirme a nova senha corretamente."); } $usuarioLogado->senha = $novaSenha; } $usuarioLogado = $this->fachada->alterarDadosCadastrais($usuarioLogado); $_SESSION['usuario'] = serialize($usuarioLogado); echo new JSONResponse(true, self::MSG_OPERACAO_SUCESSO); } catch (\Exception $ex) { echo new JSONResponse(false, $ex->getMessage()); } }