Beispiel #1
0
        public async Task <ActionResult <UpdateUserViewModel> > Update(UpdateUserInputModel model)
        {
            var userId = this.userManger.GetUserId(this.User);
            var obj    = await this.usersService.UpdateUserOrderInfoAsync <UpdateUserViewModel>(userId, model);

            return(obj);
        }
Beispiel #2
0
        public void Update(UpdateUserInputModel inputModel)
        {
            var user = _dbContext.Users.SingleOrDefault(u => u.Id == inputModel.Id);

            user.Update(inputModel.FullName, inputModel.Email, inputModel.Active);
            _dbContext.SaveChanges();
        }
Beispiel #3
0
        public async Task <IActionResult> Update(UpdateUserInputModel input)
        {
            var request = new HttpRequestMessage(HttpMethod.Put, UsersRoot);

            List <UpdateResponse> result;

            try
            {
                result = await _httpSender.SendPutAsync <List <UpdateResponse>, UpdateUserInputModel>(input, UsersRoot);
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }

            foreach (var identityResult in result)
            {
                if (!identityResult.Succeeded)
                {
                    return(BadRequest(result));
                }
            }

            return(Ok(result));
        }
        public async Task <IdentityResult> UpdateUser([FromBody] UpdateUserInputModel userInputModel)
        {
            var user = await this._userManager.FindByIdAsync(userInputModel.Id);

            if (user is null)
            {
                return(null);
            }

            user.UserName ??= userInputModel.Username;

            user.Email ??= userInputModel.Email;
            user.EmailConfirmed = !(userInputModel.Email is null) ? false : user.EmailConfirmed;

            user.PhoneNumber ??= userInputModel.PhoneNumber;
            user.PhoneNumberConfirmed = !(userInputModel.PhoneNumber is null) ? false : user.PhoneNumberConfirmed;

            if (userInputModel.IsDeleted)
            {
                user.DeletedAt = System.DateTime.UtcNow;
            }
            else
            {
                user.DeletedAt = null;
            }

            if (!(userInputModel.Password is null))
            {
                var resetToken = await this._userManager.GeneratePasswordResetTokenAsync(user);

                await this._userManager.ResetPasswordAsync(user, resetToken, userInputModel.Password);
            }

            return(await this._userManager.UpdateAsync(user));
        }
Beispiel #5
0
        public async Task <IActionResult> Put([FromBody] UpdateUserInputModel inputModel, int id)
        {
            //_userService.Update(id, inputmodel);
            var command = new UpdateUserCommand(id, inputModel.Email);
            await _mediator.Send(command);

            return(NoContent());
        }
Beispiel #6
0
        public Response <AccountUpdateOutputModel> UpdateAccount(UpdateUserInputModel updateUserInput)
        {
            var response = this._sinukaWebAccountsEndpoints.UpdateUser(updateUserInput);

            return(new Response <AccountUpdateOutputModel>(new AccountUpdateOutputModel()
            {
                IsUpdated = response.Succeeded,
            }));
        }
Beispiel #7
0
        public async Task <IdentityResult> Update(UpdateUserInputModel model, string username)
        {
            var currentUser = await this.userManager.FindByNameAsync(username);

            currentUser.UserName    = model.UserName;
            currentUser.Email       = model.Email;
            currentUser.PhoneNumber = model.PhoneNumber;

            var result = await this.userManager.UpdateAsync(currentUser);

            return(result);
        }
        public async Task <IActionResult> Put(int id, [FromBody] UpdateUserInputModel updateUserInputModel)
        {
            var command = new UpdateUserCommand(id, updateUserInputModel.Name, updateUserInputModel.Email);
            var result  = await _mediator.Send(command);

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok());
        }
Beispiel #9
0
        public async Task ChangeUserInfo_ShouldThrow()
        {
            this.Initialize();
            this.SeedUser();

            var inputModel = new UpdateUserInputModel()
            {
                FullName    = TestFullName,
                PhoneNumber = TestPhone
            };

            await Assert.ThrowsAsync <UserNotFoundException>(() => this.service.UpdateUserOrderInfoAsync <UpdateUserViewModel>(TestId, inputModel));
        }
Beispiel #10
0
        public async Task ChangeUserInfo_ShouldChangeAndReturnViewModel()
        {
            this.Initialize();
            this.SeedUser();

            var inputModel = new UpdateUserInputModel()
            {
                FullName    = TestFullName,
                PhoneNumber = TestPhone
            };

            var viewModel = await this.service.UpdateUserOrderInfoAsync <UpdateUserViewModel>(UserId, inputModel);

            Assert.Equal(TestFullName, viewModel.FullName);
            Assert.Equal(TestPhone, viewModel.PhoneNumber);
        }
Beispiel #11
0
        public async Task <IActionResult> Update(UpdateUserInputModel input)
        {
            IEnumerable <IdentityResult> result = new List <IdentityResult>();

            result = await _userService.Update(input.CurrentUserName, input.NewUserName,
                                               input.CurrentPassword, input.CurrentPassword,
                                               input.CurrentEmail, input.NewEmail);

            foreach (var identityResult in result)
            {
                if (!identityResult.Succeeded)
                {
                    return(BadRequest(result));
                }
            }

            return(Ok(result));
        }
Beispiel #12
0
        public void Validate_Fails_Mismatched_Passwords()
        {
            // Arrange
            var model = new UpdateUserInputModel
            {
                UserId          = 1,
                Email           = "*****@*****.**",
                Password        = "******",
                ConfirmPassword = "******"
            };
            var validationDictionary = new ValidationDictionary();

            // Act

            var result = model.ValidateRequest(validationDictionary);

            // Assert
            Assert.IsFalse(result);
        }
Beispiel #13
0
        public void Validate_Successful_With_Valid_Information()
        {
            // Arrange
            var model = new UpdateUserInputModel
            {
                UserId          = 1,
                Email           = "*****@*****.**",
                Password        = "******",
                ConfirmPassword = "******"
            };
            var validationDictionary = new ValidationDictionary();

            // Act

            var result = model.ValidateRequest(validationDictionary);

            // Assert
            Assert.IsTrue(result);
        }
        /// <summary>
        /// Executes the command
        /// </summary>
        /// <returns>updated user</returns>
        public async Task <User> Execute(int id, UpdateUserInputModel model)
        {
            // Check access rights: Admin
            await accessRightChecker.CheckUserIsAdmin();

            // pretreatment of model
            model.CheckAndPrepare();

            // specific validation

            model.Email = model.Email.ToLower(); // making lowercase
            if (!EmailValidationUtility.CheckIsValidEmail(model.Email))
            {
                throw new BusinessException("Email specified not correctly");
            }

            if (await userRepository.AnyAsync(a => a.Id != id && a.Email == model.Email))
            {
                throw new BusinessException("User with specified email already exists");
            }

            // gets the user
            User user = await userRepository.GetById(id).FirstOrDefaultAsync();

            if (user is null)
            {
                throw new BusinessException("User does not exist");
            }

            // updates the user
            user.Email = model.Email;
            user.Name  = model.Name;
            user.AuthenticationTokenId = Guid.NewGuid(); // generating new token id

            // saves made changes
            await changesSaver.SaveChangesAsync();

            return(user);
        }
Beispiel #15
0
        public async Task <IActionResult> UpdateAsync([FromForm] UpdateUserInputModel model)
        {
            var service = Ioc.Get <IUserService>();
            var user    = await service.GetUserById(model.Id);

            if (user == null)
            {
                return(Ok(new StandardResult().Fail(StandardCode.ArgumentError, "用户不存在")));
            }
            user.RealName     = model.RealName;
            user.IdCard       = model.IdCard;
            user.Email        = model.Email;
            user.Birthday     = model.Birthday;
            user.Mobile       = model.Mobile;
            user.Gender       = model.Gender;
            user.Enabled      = model.Enabled;
            user.ModifiedBy   = CurrentUserId;
            user.ModifiedTime = DateTime.Now;
            await service.UpdateAsync(user);

            return(Ok(new StandardResult().Succeed("更新成功")));
        }
Beispiel #16
0
        public async Task <IdentityResult> UpdateUser(UpdateUserInputModel user, string username)
        {
            var result = await this.userService.Update(user, username);

            return(result);
        }
Beispiel #17
0
 public IdentityResult UpdateUser(UpdateUserInputModel userInputModel)
 {
     return(this._sinukaWebAccountsEndpoint.UpdateUser(userInputModel));
 }
        public async Task <ActionResult> Update(string userId, UpdateUserInputModel input)
        {
            await this.usersService.UpdateAsync(userId, input.Username, input.Password);

            return(this.Ok());
        }
Beispiel #19
0
 public async Task Update([FromBody] UpdateUserInputModel model, int id)
 {
     model.Id = id;
     await _unitOfWork.SaveChangesAsync(_userWriterService.Save(model));
 }
Beispiel #20
0
        public BaseResponseModel Update(UpdateUserInputModel inputModel)
        {
            var vm = new BaseResponseModel();

            // Validate request
            var validationState = new ValidationDictionary();

            inputModel.ValidateRequest(validationState);

            // Get existing user
            var user = UserService.GetUserById(inputModel.UserId);

            if (user == null)
            {
                throw new HttpException(404, "User not found.");
            }

            // Do not allow editing of users other than yourself if you
            // don't have permissions
            if (!CurrentUser.HasPermission(Permission.EditUsers) &&
                user.Id != CurrentUser.Id)
            {
                throw new HttpException(401, "You do not have permissions to complete this action.");
            }

            // Copy properties
            bool emailChanged = user.Email != inputModel.Email;

            user.Email = inputModel.Email;
            string newPass = String.IsNullOrWhiteSpace(inputModel.Password)
                ? null : inputModel.Password;

            // Additional properties for admin users
            if (CurrentUser.HasPermission(Permission.EditUsers))
            {
                if (inputModel.Role.HasValue)
                {
                    user.Role = inputModel.Role.Value;
                }
            }

            if (UserService.ValidateUser(user, validationState))
            {
                UserService.UpdateUser(user, newPass);
                if (emailChanged)
                {
                    ReAuthorizeUser(inputModel.Email);
                }

                LogService.CreateLog(new Log
                {
                    Category  = LogCategory.Application,
                    IpAddress = GetClientIp(ControllerContext.Request),
                    Level     = LogLevel.Info,
                    Message   = "User " + inputModel.Email + " (ID #" + user.Id + ") was updated.",
                    User      = CurrentUser
                });

                vm.Success = true;
            }

            vm.Errors = validationState.Errors;
            return(vm);
        }
Beispiel #21
0
        public async Task <TViewModel> UpdateUserOrderInfoAsync <TViewModel>(string id, UpdateUserInputModel model)
        {
            var user = await this.context
                       .Users
                       .SingleOrDefaultAsync(x => x.Id == id);

            if (user == null)
            {
                throw new UserNotFoundException(string.Format(ExceptionMessages.UserLookupFailed, id));
            }

            if (user.FullName != model.FullName || user.PhoneNumber != model.PhoneNumber)
            {
                user.FullName    = model.FullName;
                user.PhoneNumber = model.PhoneNumber;
                await this.context.SaveChangesAsync();
            }

            var viewModel = this.mapper.Map <TViewModel>(user);

            return(viewModel);
        }
Beispiel #22
0
 public IdentityResult UpdateUser(UpdateUserInputModel userInputModel)
 {
     return(this._sinukaWebAccountsEndpoint.UpdateUser(userInputModel, LoginAndFetchToken()));
 }
 public async Task Update(int id, [FromBody] UpdateUserInputModel model) => await updateUserCommand.Execute(id, model);