示例#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 void CreateUser_Test()
        {
            var account         = "liuhl3";
            var pwd             = "123qwe";
            var accountRegType  = ReferAccountRegType(account);
            var userInfoCommand = new AddUserInfoCommand(Guid.NewGuid().ToString(), account, EncryptPassword(account, pwd, accountRegType),
                                                         ClientRegistType.Web, accountRegType, 0);

            var commandResult = ExecuteCommand(userInfoCommand);

            Assert.AreEqual(commandResult.Status, CommandStatus.Success);
        }