Browse Source

feat(account): Add a third-party binding interface

pull/1320/head
colin 5 months ago
parent
commit
75ce722d22
  1. 6
      aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Localization/Resources/en.json
  2. 6
      aspnet-core/modules/account/LINGYUN.Abp.Account.Application.Contracts/LINGYUN/Abp/Account/Localization/Resources/zh-Hans.json
  3. 47
      aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OAuth/Areas/Account/Controllers/OAuthAccountController.cs
  4. 2
      aspnet-core/modules/account/LINGYUN.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs

6
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!"
}
}

6
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": "解除绑定后将无法使用外部身份,如果你通过此方式登录,你的会话将被注销!"
}
}

47
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<IWeChatWorkUserFinder>();
protected AbpSignInManager SignInManager => LazyServiceProvider.LazyGetRequiredService<AbpSignInManager>();
protected IdentityUserManager UserManager => LazyServiceProvider.LazyGetRequiredService<IdentityUserManager>();
[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();
}
}

2
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")]

Loading…
Cancel
Save