diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Localization/Resources/en.json b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Localization/Resources/en.json index 38ad3e9b9..50a34dac3 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Localization/Resources/en.json +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Localization/Resources/en.json @@ -58,6 +58,10 @@ "PhoneNumberLogin": "Login with phone", "ScanQrCodeLogin": "Login with scan", "DisplayName:Abp.Account.EnablePhoneNumberLogin": "Authenticate with a phone number", - "Description:Abp.Account.EnablePhoneNumberLogin": "Indicates whether the server allows users to use mobile phone verification codes." + "Description:Abp.Account.EnablePhoneNumberLogin": "Indicates whether the server allows users to use mobile phone verification codes.", + "Bind": "Bind", + "UnBind": "Unbound", + "CancelBind": "Cancel Bind", + "CancelBindWarningMessage": "After unbinding, you will not be able to use an external identity. If you log in through this method, your session will be logged out!" } } \ No newline at end of file diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Localization/Resources/zh-Hans.json b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Localization/Resources/zh-Hans.json index 896e15146..47dac10e9 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Localization/Resources/zh-Hans.json +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Localization/Resources/zh-Hans.json @@ -58,6 +58,10 @@ "PhoneNumberLogin": "验证码登录", "ScanQrCodeLogin": "扫码登录", "DisplayName:Abp.Account.EnablePhoneNumberLogin": "使用手机验证码进行身份验证", - "Description:Abp.Account.EnablePhoneNumberLogin": "表示服务器是否允许用户使用手机验证码进行身份验证。" + "Description:Abp.Account.EnablePhoneNumberLogin": "表示服务器是否允许用户使用手机验证码进行身份验证。", + "Bind": "绑定", + "UnBind": "未绑定", + "CancelBind": "解除绑定", + "CancelBindWarningMessage": "解除绑定后将无法使用外部身份,如果你通过此方式登录,你的会话将被注销!" } } \ No newline at end of file diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OAuth/Areas/Account/Controllers/OAuthAccountController.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OAuth/Areas/Account/Controllers/OAuthAccountController.cs new file mode 100644 index 000000000..c159376c7 --- /dev/null +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OAuth/Areas/Account/Controllers/OAuthAccountController.cs @@ -0,0 +1,47 @@ +using AspNet.Security.OAuth.WorkWeixin; +using LINGYUN.Abp.WeChat.Work.Authorize; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Account; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.Identity; +using Volo.Abp.Identity.AspNetCore; +using Volo.Abp.Users; + +namespace LINGYUN.Abp.Account.Web.OAuth.Areas.Account.Controllers; + +[Controller] +[Area(AccountRemoteServiceConsts.ModuleName)] +[Route($"api/{AccountRemoteServiceConsts.ModuleName}/oauth")] +[RemoteService(Name = AccountRemoteServiceConsts.RemoteServiceName)] +public class OAuthAccountController : AbpController +{ + protected IWeChatWorkUserFinder WeChatWorkUserFinder => LazyServiceProvider.LazyGetRequiredService(); + protected AbpSignInManager SignInManager => LazyServiceProvider.LazyGetRequiredService(); + protected IdentityUserManager UserManager => LazyServiceProvider.LazyGetRequiredService(); + + [HttpPost] + [Authorize] + [Route("work-weixin/bind")] + public virtual async Task WorkWeixinLoginBindAsync(string code) + { + var workWeixinUser = await WeChatWorkUserFinder.GetUserInfoAsync(code); + var currentUser = await UserManager.GetByIdAsync(CurrentUser.GetId()); + var userLogins = await UserManager.GetLoginsAsync(currentUser); + var workWexinLogin = userLogins.FirstOrDefault(x => x.LoginProvider == WorkWeixinAuthenticationDefaults.AuthenticationScheme); + if (workWexinLogin != null) + { + (await UserManager.RemoveLoginAsync(currentUser, workWexinLogin.LoginProvider, workWexinLogin.ProviderKey)).CheckErrors(); + } + (await UserManager.AddLoginAsync( + currentUser, + new UserLoginInfo( + WorkWeixinAuthenticationDefaults.AuthenticationScheme, + workWeixinUser.UserId, + WorkWeixinAuthenticationDefaults.DisplayName))).CheckErrors(); + } +} diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs index 316d6c489..a53e5e7c1 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs @@ -83,7 +83,7 @@ public class AccountController : AbpController await SignInManager.SignOutAsync(); } } - + [HttpGet] [Authorize] [Route("external-logins/bind")]