public async Task <string> BindUserProfile(UserProfileInput input) { ValidationResult validationResult = _userProfileInputValidator.Validate(input); if (!validationResult.IsValid) { throw new LotteryDataException(validationResult.Errors.Select(p => p.ErrorMessage).ToList().ToString(";")); } var validIdentifyCodeOutput = _identifyCodeAppService.ValidIdentifyCode(input.Profile, input.Identifycode); if (validIdentifyCodeOutput.IsOvertime) { await SendCommandAsync(new InvalidIdentifyCodeCommand(validIdentifyCodeOutput.IdentifyCodeId, input.Profile, _lotterySession.UserId)); throw new LotteryDataException("验证码超时,请重新获取验证码"); } if (!validIdentifyCodeOutput.IsValid) { // await SendCommandAsync(new InvalidIdentifyCodeCommand(validIdentifyCodeOutput.IdentifyCodeId, user.Account, _lotterySession.UserId)); throw new LotteryDataException("您输入的验证码错误,请重新输入"); } await SendCommandAsync(new InvalidIdentifyCodeCommand(validIdentifyCodeOutput.IdentifyCodeId, input.Profile, _lotterySession.UserId)); var isReg = await _userManager.IsExistAccount(input.Profile); if (isReg) { throw new LotteryDataException("已经存在该账号,不允许被绑定"); } var validPwdResult = await _userManager.VerifyPassword(input.Password, input.Password); if (!validPwdResult) { throw new LotteryDataException("密码错误"); } AsyncTaskResult result = null; if (input.ProfileType == AccountRegistType.Email) { var bindUserEmailCommand = new BindUserEmailCommand(_lotterySession.UserId, input.Profile); result = await SendCommandAsync(bindUserEmailCommand); } else if (input.ProfileType == AccountRegistType.Phone) { var bindUserPhoneCommand = new BindUserPhoneCommand(_lotterySession.UserId, input.Profile); result = await SendCommandAsync(bindUserPhoneCommand); } Debug.Assert(result != null, "result != null"); if (result.Status == AsyncTaskStatus.Success) { return("用户信息绑定成功"); } throw new LotteryDataException("绑定失败"); }
public void BindUserProfile_Test() { var userProfile = "*****@*****.**"; var userId = "08b4c537-08aa-40f9-9d24-ab6ccd1b189c"; var userProfileCommand = new BindUserEmailCommand(userId, userProfile); var commandResult = ExecuteCommand(userProfileCommand); Assert.AreEqual(commandResult.Status, CommandStatus.Success); }
public void Handle(ICommandContext context, BindUserEmailCommand command) { context.Get <UserInfo>(command.AggregateRootId).BindUserEmail(command.Email); }