Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api/oauth: also activate user after successful oauth authentication #4779

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/src/Security/OAuth/GoogleAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public function authenticate(Request $request): Passport {
$profile->surname = $googleUser->getLastName();
$user = new User();
$user->profile = $profile;
}

if (in_array($user->state, [null, User::STATE_NONREGISTERED, User::STATE_REGISTERED])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very clean now. But you have an early return above, so if $existingProfile is true, you will never get here.

I think the best is if you extract the logic above into a separate function (e.g. findOrCreateUser) and then you could keep the cleanliness of this last state-check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An existing Profile has to have run through the If below in a previous request, else it cannot be an existing Profile.
As long as we don't reset the state, this should be good enough

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, get it. Thanks for clarifying.

$user->state = User::STATE_ACTIVATED;
}

Expand Down
3 changes: 3 additions & 0 deletions api/src/Security/OAuth/HitobitoAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public function authenticate(Request $request): Passport {
$profile->nickname = $hitobitoUser->getNickName();
$user = new User();
$user->profile = $profile;
}

if (in_array($user->state, [null, User::STATE_NONREGISTERED, User::STATE_REGISTERED])) {
$user->state = User::STATE_ACTIVATED;
}

Expand Down
Loading