shibboleth_authenticate_user: cleanup#38
Merged
michaelryanmcneill merged 2 commits intomichaelryanmcneill:masterfrom May 15, 2018
Merged
shibboleth_authenticate_user: cleanup#38michaelryanmcneill merged 2 commits intomichaelryanmcneill:masterfrom
michaelryanmcneill merged 2 commits intomichaelryanmcneill:masterfrom
Conversation
…der by-email combine checks to match by-username checks
Collaborator
Author
|
Here's an idea that I think makes the "account combine" code more clear that if shibboleth_account isn't set, we're either going to set it or throw a WP_Error. // look up existing account by username, with email as a fallback
$user_by = 'username';
$user = get_user_by( 'login', $username );
if ( ! $user ) {
$user_by = 'email';
$user = get_user_by( 'email', $email );
}
// if this account is not a Shibboleth account, then do account combine (if allowed)
if ( is_object( $user ) && $user->ID && ! get_user_meta( $user->ID, 'shibboleth_account' ) ) {
$do_account_combine = false;
if ( $user_by === 'username' && ( $auto_combine_accounts === 'allow' || $manually_combine_accounts === 'allow' ) ) {
$do_account_combine = true;
} elseif ( $auto_combine_accounts === 'bypass' || $manually_combine_accounts === 'bypass' ) {
$do_account_combine = true;
}
if ( $do_account_combine ) {
update_user_meta( $user->ID, 'shibboleth_account', true );
} elseif ( $user_by === 'username' ) {
return new WP_Error( 'invalid_username', __( 'An account already exists with this username.', 'shibboleth' ) );
} else {
return new WP_Error( 'invalid_email', __( 'An account already exists with this email.', 'shibboleth' ) );
}
}If you like this, I can add it to this PR. |
Owner
|
Yeah, I like that @jrchamp. Go ahead and add that to the PR and I'll get it merged in. |
Collaborator
Author
|
Ok, I've added the account combine unification commit to the PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A couple small cleanup items I noticed while working on the other issue: