示例#1
0
        public async Task <string> CreateUser(UserInfoInput user)
        {
            ValidationResult validationResult = _userInfoInputValidator.Validate(user);

            if (!validationResult.IsValid)
            {
                throw new LotteryDataException(validationResult.Errors.Select(p => p.ErrorMessage).ToList().ToString(";"));
            }

            var validIdentifyCodeOutput = _identifyCodeAppService.ValidIdentifyCode(user.Account, user.IdentifyCode);

            if (validIdentifyCodeOutput.IsOvertime)
            {
                await SendCommandAsync(new InvalidIdentifyCodeCommand(validIdentifyCodeOutput.IdentifyCodeId, user.Account, "system"));

                throw new LotteryDataException("验证码超时,请重新获取验证码");
            }
            if (!validIdentifyCodeOutput.IsValid)
            {
                // await SendCommandAsync(new InvalidIdentifyCodeCommand(validIdentifyCodeOutput.IdentifyCodeId, user.Account, _lotterySession.UserId));
                throw new LotteryDataException("您输入的验证码错误,请重新输入");
            }

            var accountRegType = AccountHelper.JudgeAccountRegType(user.Account);
            var isReg          = await _userManager.IsExistAccount(user.Account);

            if (isReg)
            {
                await SendCommandAsync(new InvalidIdentifyCodeCommand(validIdentifyCodeOutput.IdentifyCodeId, user.Account, "system"));

                throw new LotteryDataException("该账号已经存在");
            }

            var userId = Guid.NewGuid().ToString();

            var userInfoCommand = new AddUserInfoCommand(userId, user.Account,
                                                         EncryptPassword(user.Account, user.Password, accountRegType),
                                                         user.ClientRegistType, accountRegType, 0);
            var commandResult = await SendCommandAsync(userInfoCommand);

            var signedPointInfo = _pointQueryService.GetPointInfoByType(PointType.Register);
            var sinedNotes      = $"{DateTime.Now.ToString("yyyy-MM-dd")}日,注册即送积分";

            await SendCommandAsync(new AddPointRecordCommand(Guid.NewGuid().ToString(), signedPointInfo.Point,
                                                             PointType.Signed, PointOperationType.Increase, sinedNotes, userId));

            if (commandResult.Status != AsyncTaskStatus.Success)
            {
                throw new LotteryDataException("创建用户失败");
            }
            await SendCommandAsync(new InvalidIdentifyCodeCommand(validIdentifyCodeOutput.IdentifyCodeId, user.Account,
                                                                  user.Account));

            return("注册用户成功");
        }
示例#2
0
        public async Task <string> IdentifyCode3(IdentifyCodeValidInput input)
        {
            if (input.Account.IsNullOrEmpty())
            {
                throw new LotteryException("账号不允许为空");
            }
            var accountType = AccountHelper.JudgeAccountRegType(input.Account);

            if (accountType == AccountRegistType.UserName)
            {
                throw new LotteryException("账号不正确");
            }
            if (input.IdentifyCode.IsNullOrEmpty())
            {
                throw new LotteryException("验证码不允许为空");
            }

            if (input.IsValidAccountExist && !(await _userManager.IsExistAccount(input.Account)))
            {
                throw new LotteryException($"不存在账号为的{input.Account}用户");
            }

            var validIdentifyCodeOutput = _identifyCodeAppService.ValidIdentifyCode(input.Account, input.IdentifyCode);

            if (validIdentifyCodeOutput.IsOvertime)
            {
                await SendCommandAsync(new InvalidIdentifyCodeCommand(validIdentifyCodeOutput.IdentifyCodeId, input.Account, input.Account));

                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.Account, input.Account));

            return("验证成功");
        }