public async Task <UserProfileOutput> UpdateProfileAsync(int userId, UserProfileInput model)
        {
            var entity = await Repository.FirstOrDefaultAsync(n => n.UserId == userId);

            if (entity == null)
            {
                return(null);
            }

            entity.InjectFrom <NullableInjection>(model);

            await Repository.UpdateAsync(entity, true);

            var result = await GetAsync(userId);

            await Task.Run(() =>
            {
                RaiseEvent(new UserProfileUpdatedEvent
                {
                    User   = entity,
                    Object = result,
                });
            });

            return(result);
        }
Exemple #2
0
        public async Task UpdateUserProfile(UserProfileInput input)
        {
            if (!input.Password.IsNullOrEmptyOrWhiteSpace())
            {
                if (!input.Password.Equals(input.PasswordConfirm))
                {
                    throw new UserFriendlyException("二次输入的密码不同");
                }
            }

            var currentUser = await _userRepository.FirstOrDefaultAsync(x => x.Id == CurrentUser.Id);

            if (currentUser == null)
            {
                throw new UserFriendlyException("当前登录用户不正确");
            }

            currentUser.SetUserName(input.UserName);
            currentUser.SetName(input.Name);
            currentUser.SetSurname(input.Surname);
            currentUser.SetPhone(input.PhoneNumber);
            currentUser.SetEmail(input.Email);
            currentUser.Nickname   = input.Name;
            currentUser.HeadImgUrl = input.HeadImgUrl;
        }
        public async Task <IActionResult> UpdateProfileAsync(UserProfileInput model)
        {
            var profile = await _userProfileService.UpdateProfileAsync(UserInfo.UserId, model);

            return(profile == null?
                   NotFound(UserAccountMessages.UserNotFound.GetDescription()) :
                       Ok(profile));
        }
Exemple #4
0
        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("绑定失败");
        }
Exemple #5
0
        public void ValidateWhenPasswordsMatchAndAreLongReturnsCorrectResult(
            string password)
        {
            // Fixture setup
            var sut = new UserProfileInput(
                "dummy", "dummy", password, password);
            // Exercise system
            var actual = sut.Validate();

            // Verify outcome
            Assert.Equal("", actual);
            // Teardown
        }
Exemple #6
0
        public void ValidateWhenPasswordsMatchButAreTooShortReturnsCorrectResult(
            string password)
        {
            // Fixture setup
            var sut = new UserProfileInput(
                "dummy", "dummy", password, password);
            // Exercise system
            var actual = sut.Validate();

            // Verify outcome
            Assert.Equal(
                "Password must be at least 8 characters in length" +
                Environment.NewLine,
                actual);
            // Teardown
        }
Exemple #7
0
        public void ValidateWhenPasswordsDoNotMatchReturnsCorrectResult(
            string password,
            string passwordRepeated)
        {
            // Fixture setup
            var sut = new UserProfileInput(
                "dummy", "dummy", password, passwordRepeated);
            // Exercise system
            string actual = sut.Validate();

            // Verify outcome
            Assert.Equal(
                "The passwords don't match" + Environment.NewLine,
                actual);
            // Teardown
        }
Exemple #8
0
        public async Task <IResult <IMessageOutput> > Handle(UserProfileInput input, CancellationToken cancellationToken)
        {
            var validationResult = Validator.Validate(input);

            if (validationResult.Errors.Count > 0)
            {
                return(new Result <IMessageOutput>(validationResult.Errors));
            }

            var user = UserService.CurrentUser;

            input.Adapt(user, MappingConfig);

            await UserService.UpdateAsync(user, cancellationToken);

            return(new Result <IMessageOutput>(new MessageOutput("User profile successfully updated.")));
        }
        public async Task <IActionResult> UpdateProfile([FromForm] UserProfileInput input)
        {
            var result = await UpdateProfileCommand.Value.ExecuteAsync(input);

            return(PresentResult(result));
        }
Exemple #10
0
        public async Task <IActionResult> UpdateProfile([FromForm] UserProfileInput input, CancellationToken cancellationToken)
        {
            var result = await Mediator.Value.Send(input, cancellationToken);

            return(PresentResult(result));
        }