Exemple #1
0
 private void ComparePassword(UserPasswordUpdateModel criterias)
 {
     if (!criterias.NewPassword.Equals(criterias.ConfirmPassword))
     {
         throw new ArgumentException($"{nameof(criterias.NewPassword)} and {nameof(criterias.ConfirmPassword)} is not the same");
     }
 }
        public ActionResult UpdatePassword(UserPasswordUpdateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            var v = _db.ForumUser.SingleOrDefault(m => m.UserName.Equals(User.Identity.Name));

            if (v == null)
            {
                return(View());
            }
            var id = v.UserId;
            var checkOldPassword = _db.ForumUser.SingleOrDefault(m => m.UserId.Equals(id) && m.Password.Equals(model.OldPassword));

            if (checkOldPassword != null)
            {
                var u = _db.ForumUser.Find(id);
                u.Password         = model.NewPassword;
                _db.Entry(u).State = EntityState.Modified;
                _db.SaveChanges();
                ViewBag.successMs = 1;
            }
            else
            {
                ModelState.AddModelError("", "* Sorry,Your entered password do not match with your old password!");
            }

            return(View());
        }
        public async Task UpdateUserPasswordAsync(UserPasswordUpdateModel passwordUpdate)
        {
            var userId   = passwordUpdate.UserId;
            var password = PasswordHashing.GeneratePassword(passwordUpdate.Password);

            await _userRepository.UpdateUserPasswordAsync(userId, password);
        }
Exemple #4
0
        public async Task <ServiceResult> UpdatePassword(Guid id, [FromBody] UserPasswordUpdateModel apiEntity)
        {
            var result = await _userService.AuthenticateAsync(id, apiEntity.OldPassword);

            if (result.IsSuccess)
            {
                result = await _userService.UpdatePasswordAsync(id, apiEntity.NewPassword);

                if (result.TryCastModel(out AppUser user))
                {
                    result.ViewModel = UserViewModel.Map(user);
                }
            }

            return(result);
        }
Exemple #5
0
        public async Task <HttpResponseMessage> UpdateUserPassword([FromBody] UserPasswordUpdateModel user)
        {
            await _userService.UpdateUserPasswordAsync(user);

            return(new HttpResponseMessage(HttpStatusCode.NoContent));
        }
Exemple #6
0
 public async Task<UserTokenModel> UpdatePasswordAsync(ClaimsPrincipal claimsPrincipal, [Service] IAuthenticateResolver authenticateResolver, UserPasswordUpdateModel criterias)
 {
     return await authenticateResolver.UpdatePasswordAsync(claimsPrincipal, criterias);
 }
Exemple #7
0
        public async Task <UserTokenModel> UpdatePasswordAsync(ClaimsPrincipal claimsPrincipal, UserPasswordUpdateModel criterias)
        {
            try
            {
                ComparePassword(criterias);
                var currentUserId = GetCurrentUserId(claimsPrincipal);
                var currentUser   = await _userManager.FindByIdAsync(currentUserId);

                var result = await _userManager.ChangePasswordAsync(currentUser, criterias.CurrentPassword, criterias.NewPassword);

                if (!result.Succeeded)
                {
                    return(new UserTokenModel(false));
                }

                return(await RefreshTokenAsync());
            }
            catch (Exception)
            {
                return(new UserTokenModel(false));
            }
        }