public function transform(User $user) { $result = ['id' => $user->getId(), 'username' => $user->getUsername(), 'name' => $user->getName(), 'avatar_url' => $user->getAvatarUrl()]; return $result; }
/** * @param int $provider * @param User $user * * @return array */ private function oauthAuthorize($provider, User $user) { $userName = $user->getUsername(); /** * @var $userProvider UserProvider */ $userProvider = $this->app['users']; if (!($kanbanUser = $userProvider->loadUserByOauth($provider, $user->getId()))) { $userName .= '_' . $provider; $userProvider->registerUser(['_username' => $userName, '_email' => $user->getEmail(), '_password' => $user->getPrivateToken()], ['provider_id' => $provider, 'user_id' => $user->getId()]); $kanbanUser = $userProvider->loadUserByUsername($userName); } $token = $this->app['security']->getToken(); $token->setUser($kanbanUser); $response = ['success' => true, 'token' => $this->app['security.jwt.encoder']->encode(['name' => $kanbanUser->getUsername()])]; return $response; }