public virtual async Task <IdentityUserDto> RegisterAsync(WeChatRegisterDto input)
        {
            await CheckSelfRegistrationAsync();

            var wehchatOpenId = await WeChatOpenIdFinder.FindAsync(input.Code);

            var user = await UserManager.FindByLoginAsync(AbpWeChatAuthorizationConsts.ProviderKey, wehchatOpenId.OpenId);

            if (user != null)
            {
                // 应该要抛出微信号已注册异常,而不是直接返回注册用户数据,否则造成用户信息泄露
                throw new UserFriendlyException(L["DuplicateWeChat"]);
            }
            var userName  = input.UserName ?? "wx-" + wehchatOpenId.OpenId;
            var userEmail = input.EmailAddress ?? $"{userName}@{CurrentTenant.Name ?? "default"}.io";//如果邮件地址不验证,随意写入一个

            user = new IdentityUser(GuidGenerator.Create(), userName, userEmail, CurrentTenant.Id)
            {
                Name = input.Name ?? userName
            };
            (await UserManager.CreateAsync(user, input.Password)).CheckErrors();

            (await UserManager.AddDefaultRolesAsync(user)).CheckErrors();

            var userLogin = new UserLoginInfo(AbpWeChatAuthorizationConsts.ProviderKey, wehchatOpenId.OpenId, AbpWeChatAuthorizationConsts.DisplayName);

            (await UserManager.AddLoginAsync(user, userLogin)).CheckErrors();

            return(ObjectMapper.Map <IdentityUser, IdentityUserDto>(user));
        }
示例#2
0
        public virtual async Task <IdentityUserDto> RegisterAsync(WeChatRegisterDto input)
        {
            await CheckSelfRegistrationAsync();

            var wehchatOpenId = await WeChatOpenIdFinder.FindAsync(input.Code);

            var user = await UserManager.FindByLoginAsync("WeChat", wehchatOpenId.OpenId);

            if (user != null)
            {
                // 应该要抛出微信号已注册异常,而不是直接返回注册用户数据,否则造成用户信息泄露
                throw new UserFriendlyException(L["DuplicateWeChat"]);
            }
            var userName  = input.UserName ?? wehchatOpenId.OpenId;
            var userEmail = input.EmailAddress ?? $"{userName}@{new Random().Next(1000, 99999)}.com";//如果邮件地址不验证,随意写入一个

            user = new IdentityUser(GuidGenerator.Create(), userName, userEmail, CurrentTenant.Id)
            {
                Name = input.Name ?? userName
            };
            (await UserManager.CreateAsync(user, input.Password)).CheckErrors();

            (await UserManager.AddDefaultRolesAsync(user)).CheckErrors();

            var userLogin = new UserLoginInfo("WeChat", wehchatOpenId.OpenId, "微信认证登录");

            (await UserManager.AddLoginAsync(user, userLogin)).CheckErrors();

            return(ObjectMapper.Map <IdentityUser, IdentityUserDto>(user));
        }
示例#3
0
        public virtual async Task RegisterAsync(WeChatRegisterDto input)
        {
            ThowIfInvalidEmailAddress(input.EmailAddress);

            await CheckSelfRegistrationAsync();

            await IdentityOptions.SetAsync();

            var options = await MiniProgramOptionsFactory.CreateAsync();

            var wehchatOpenId = await WeChatOpenIdFinder.FindAsync(input.Code, options.AppId, options.AppSecret);

            var user = await UserManager.FindByLoginAsync(AbpWeChatMiniProgramConsts.ProviderKey, wehchatOpenId.OpenId);

            if (user != null)
            {
                // 应该要抛出微信号已注册异常,而不是直接返回注册用户数据,否则造成用户信息泄露
                throw new UserFriendlyException(L["DuplicateWeChat"]);
            }
            var userName = input.UserName;

            if (userName.IsNullOrWhiteSpace())
            {
                userName = "******" + wehchatOpenId.OpenId.ToMd5().ToLower();
            }

            var userEmail = input.EmailAddress;//如果邮件地址不验证,随意写入一个

            if (userEmail.IsNullOrWhiteSpace())
            {
                userEmail = $"{userName}@{CurrentTenant.Name ?? "default"}.io";
            }

            user = new IdentityUser(GuidGenerator.Create(), userName, userEmail, CurrentTenant.Id);
            (await UserManager.CreateAsync(user, input.Password)).CheckErrors();

            (await UserManager.AddDefaultRolesAsync(user)).CheckErrors();

            var userLogin = new UserLoginInfo(AbpWeChatMiniProgramConsts.ProviderKey, wehchatOpenId.OpenId, AbpWeChatGlobalConsts.DisplayName);

            (await UserManager.AddLoginAsync(user, userLogin)).CheckErrors();

            await CurrentUnitOfWork.SaveChangesAsync();
        }
 public virtual async Task <IdentityUserDto> RegisterAsync(WeChatRegisterDto input)
 {
     return(await AccountAppService.RegisterAsync(input));
 }
示例#5
0
 public virtual async Task RegisterAsync(WeChatRegisterDto input)
 {
     await AccountAppService.RegisterAsync(input);
 }