diff --git a/extend.php b/extend.php index 4637afc..6445cf3 100644 --- a/extend.php +++ b/extend.php @@ -11,9 +11,12 @@ namespace FoF\OAuth; +use Flarum\Api\Serializer\CurrentUserSerializer; use Flarum\Api\Serializer\ForumSerializer; use Flarum\Extend; use Flarum\Frontend\Document; +use Flarum\User\User; +use FoF\Extend\Controllers\AbstractOAuthController; use FoF\Extend\Events\OAuthLoginSuccessful; return [ @@ -66,4 +69,12 @@ (new Extend\Event()) ->listen(OAuthLoginSuccessful::class, Listeners\UpdateEmailFromProvider::class), + + (new Extend\ApiSerializer(CurrentUserSerializer::class)) + ->attributes(function (CurrentUserSerializer $serializer, User $user, array $attributes) { + $session = $serializer->getRequest()->getAttribute('session'); + $attributes['loginProvider'] = $session->get(AbstractOAuthController::SESSION_OAUTH2PROVIDER); + + return $attributes; + }), ]; diff --git a/js/src/forum/components/ProviderInfo.tsx b/js/src/forum/components/ProviderInfo.tsx index 79adcb6..4d4c35a 100644 --- a/js/src/forum/components/ProviderInfo.tsx +++ b/js/src/forum/components/ProviderInfo.tsx @@ -18,7 +18,6 @@ export default class ProviderInfo extends Component {

{provider.name()}

{app.translator.trans('fof-oauth.forum.user.settings.linked-account.orphaned-account')}

{this.renderDates(provider)} - {/* Any other content for the orphaned state can be added here */} ); } @@ -32,11 +31,9 @@ export default class ProviderInfo extends Component { ); } - // Assuming not linked state means neither orphaned nor linked return (

{app.translator.trans(`fof-oauth.forum.providers.${provider.name()}`)}

- {/* Any content for the not linked state can be added here */}
); } diff --git a/js/src/forum/extend.ts b/js/src/forum/extend.ts new file mode 100644 index 0000000..4362a2f --- /dev/null +++ b/js/src/forum/extend.ts @@ -0,0 +1,11 @@ +import Extend from 'flarum/common/extenders'; +import User from 'flarum/common/models/User'; +import LinkedAccount from './models/LinkedAccount'; + +export default [ + new Extend.Model(User) // + .attribute('loginProvider'), + + new Extend.Store() // + .add('linked-accounts', LinkedAccount), +]; diff --git a/js/src/forum/extend/addLinkedAccountsToUserSecurityPage.tsx b/js/src/forum/extenders/addLinkedAccountsToUserSecurityPage.tsx similarity index 100% rename from js/src/forum/extend/addLinkedAccountsToUserSecurityPage.tsx rename to js/src/forum/extenders/addLinkedAccountsToUserSecurityPage.tsx diff --git a/js/src/forum/extend/extendLoginSignup.js b/js/src/forum/extenders/extendLoginSignup.js similarity index 100% rename from js/src/forum/extend/extendLoginSignup.js rename to js/src/forum/extenders/extendLoginSignup.js diff --git a/js/src/forum/index.js b/js/src/forum/index.js deleted file mode 100644 index 09b62e3..0000000 --- a/js/src/forum/index.js +++ /dev/null @@ -1,11 +0,0 @@ -import app from 'flarum/forum/app'; -import addLinkedAccountsToUserSecurityPage from './extend/addLinkedAccountsToUserSecurityPage'; -import extendLoginSignup from './extend/extendLoginSignup'; -import LinkedAccount from './models/LinkedAccount'; - -app.initializers.add('fof/oauth', () => { - app.store.models['linked-accounts'] = LinkedAccount; - - extendLoginSignup(); - addLinkedAccountsToUserSecurityPage(); -}); diff --git a/js/src/forum/index.ts b/js/src/forum/index.ts new file mode 100644 index 0000000..d49f3ea --- /dev/null +++ b/js/src/forum/index.ts @@ -0,0 +1,10 @@ +import app from 'flarum/forum/app'; +import addLinkedAccountsToUserSecurityPage from './extenders/addLinkedAccountsToUserSecurityPage'; +import extendLoginSignup from './extenders/extendLoginSignup'; + +export { default as extend } from './extend'; + +app.initializers.add('fof/oauth', () => { + extendLoginSignup(); + addLinkedAccountsToUserSecurityPage(); +});