forked from OrchardCMS/OrchardCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Users): added default services to retrieve user to link to login…
… data feat(Users): changed account controller code to use new services feat(Users): load all services in reversed enum to ret last registered services feat(Users): updated view code resolve OrchardCMS#16026
- Loading branch information
Showing
4 changed files
with
73 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
42 changes: 42 additions & 0 deletions
42
src/OrchardCore.Modules/OrchardCore.Users/Services/DefaultExternalLoginUserToRelateFinder.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
using System.Runtime.CompilerServices; | ||
using System.Security.Claims; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Identity; | ||
using OrchardCore.Users.Abstractions; | ||
|
||
namespace OrchardCore.Users.Services; | ||
|
||
public class DefaultExternalLoginUserToRelateFinder : IExternalLoginUserToRelateFinder | ||
{ | ||
private readonly UserManager<IUser> _userManager; | ||
|
||
public DefaultExternalLoginUserToRelateFinder(UserManager<IUser> userManager) | ||
{ | ||
_userManager = userManager; | ||
} | ||
|
||
public bool CanManageThis(string extLoginKind) | ||
{ | ||
return true; | ||
} | ||
|
||
public async Task<IUser> FindUserToRelateAsync(ExternalLoginInfo info) | ||
{ | ||
//the default behavior previously used in OrchardCore | ||
var email = info.Principal.FindFirstValue(ClaimTypes.Email) ?? info.Principal.FindFirstValue("email"); | ||
|
||
IUser iUser = null; | ||
if (!string.IsNullOrWhiteSpace(email)) | ||
{ | ||
iUser = await _userManager.FindByEmailAsync(email); | ||
} | ||
|
||
return iUser; | ||
} | ||
|
||
public string GetValueThatLinkAccount(ExternalLoginInfo info) | ||
{ | ||
return info.Principal.FindFirstValue(ClaimTypes.Email) ?? info.Principal.FindFirstValue("email"); | ||
} | ||
} |
This file contains 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
14 changes: 14 additions & 0 deletions
14
src/OrchardCore/OrchardCore.Users.Abstractions/Services/IExternalLoginUserToRelateFinder.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Identity; | ||
|
||
namespace OrchardCore.Users.Abstractions; | ||
|
||
public interface IExternalLoginUserToRelateFinder | ||
{ | ||
bool CanManageThis(string extLoginKind); | ||
|
||
Task<IUser> FindUserToRelateAsync(ExternalLoginInfo info); | ||
|
||
string GetValueThatLinkAccount(ExternalLoginInfo info); | ||
} |