Skip to content

Commit

Permalink
feat: add loginProvider to CurrentUserSerializer (#64)
Browse files Browse the repository at this point in the history
* add loginProvider to CurrentUserSeerializer

* Apply fixes from StyleCI

* remove unneccessary comments

---------

Co-authored-by: StyleCI Bot <[email protected]>
  • Loading branch information
imorland and StyleCIBot authored Oct 4, 2023
1 parent df8df7d commit 4f61917
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
11 changes: 11 additions & 0 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down Expand Up @@ -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;
}),
];
3 changes: 0 additions & 3 deletions js/src/forum/components/ProviderInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default class ProviderInfo extends Component<IProviderInfoAttrs> {
<p className="LinkedAccountsList-item-title">{provider.name()}</p>
<p className="helpText">{app.translator.trans('fof-oauth.forum.user.settings.linked-account.orphaned-account')}</p>
{this.renderDates(provider)}
{/* Any other content for the orphaned state can be added here */}
</div>
);
}
Expand All @@ -32,11 +31,9 @@ export default class ProviderInfo extends Component<IProviderInfoAttrs> {
);
}

// Assuming not linked state means neither orphaned nor linked
return (
<div>
<p className="LinkedAccountsList-item-title">{app.translator.trans(`fof-oauth.forum.providers.${provider.name()}`)}</p>
{/* Any content for the not linked state can be added here */}
</div>
);
}
Expand Down
11 changes: 11 additions & 0 deletions js/src/forum/extend.ts
Original file line number Diff line number Diff line change
@@ -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<string>('loginProvider'),

new Extend.Store() //
.add('linked-accounts', LinkedAccount),
];
File renamed without changes.
11 changes: 0 additions & 11 deletions js/src/forum/index.js

This file was deleted.

10 changes: 10 additions & 0 deletions js/src/forum/index.ts
Original file line number Diff line number Diff line change
@@ -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();
});

0 comments on commit 4f61917

Please sign in to comment.