Beispiel #1
0
        public async Task <IActionResult> ChangePassword(ProfileChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await _userService.ChangePasswordAsync(_mapper.Map <ChangePasswordModel>(model));

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Error changing password.");
                    ModelState.AddModelError("", ex.Message);
                }
            }
            return(View(model));
        }
        public async Task <ActionResult> ChangePassword(ProfileChangePasswordModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("_ChangePassword", model: model));
            }

            model.Id = "0";

            var response = await _httpClientService.SendRequest("api/admin/password/update", HttpMethod.Put, model);

            if (response.IsSuccessStatusCode)
            {
                return(NotificationSuccessResult(Resource.PasswordResetSuccess, Url.RouteUrl(ProfileRoutes.Data)));
            }

            var errorMessage = await _commonService.CheckForValidationErrors(response, Resource.ApplicationErrorText);

            return(NotificationErrorResult(errorMessage));
        }
        public async Task <ActionResult> ChangePassword(ProfileChangePasswordModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            try
            {
                await UserManagementMicroService.ChangePasswordAsync(GetUserId(), model.OldPassword, model.NewPassword);

                AddFeedbackMessage(Feedback.FeedbackMessageTypes.Informational, "Password changed.");

                return(RedirectToAction("Index"));
            }
            catch (ServiceException ex)
            {
                AddModelErrors(ex);
                return(View());
            }
        }
Beispiel #4
0
        public void ChangePassword(ProfileChangePasswordModel model)
        {
            var token = _tokenProvider.GetToken();

            if (token == null || !token.IsValid())
            {
                throw new CustomAuthenticationException("User is not authenticated!");
            }

            // password to use
            var password = model?.Password ?? "";

            // validate model
            if (model == null)
            {
                throw new CustomInputException("Change Password model is empty!");
            }
            if (String.IsNullOrWhiteSpace(password))
            {
                throw new CustomInputException("Password is empty!");
            }
            if (!model.IsPasswordMatch())
            {
                throw new CustomInputException("Password Confirmation does not match!");
            }

            // security policy
            var securityPolicy = this.GetSecurityPolicy();

            if (!securityPolicy.CheckStrength(password))
            {
                throw new CustomInputException("Password does not match securuty policy!");
            }

            // get person
            var person = this.Persons
                         .Include(t => t.User)
                         .FirstOrDefault(t => t.User.ID == token.UserID);

            if (person == null || person.User == null)
            {
                throw new CustomInputException($"User not found!");
            }

            if (!securityPolicy.VerifyPassword(model.PasswordCurrent, person.User.Password))
            {
                throw new CustomInputException("Current Password does not match!");
            }

            // password Hash
            var passwordHash = securityPolicy.HashPassword(password);

            if (!String.IsNullOrWhiteSpace(person.User.Password) && !securityPolicy.CanReuse && passwordHash.Equals(person.User.Password, CommonService.StringComparison))
            {
                throw new CustomInputException("Password was used already!");
            }

            // change password
            person.User.ChangePassword(passwordHash);
            this.Persons.Update(person);
            _dbContext.SaveChanges();

            // raise event of password change to send email
            DomainDispatcher.RaiseEvent(new PasswordChangedDomainEvent()
            {
                Login     = person.User.Login,
                NameFirst = person.Name.First,
                NameLast  = person.Name.Last,
                Email     = person.Email,
                Password  = model.Password
            });
        }
Beispiel #5
0
 public void ChangePassword([FromBody] ProfileChangePasswordModel model)
 {
     _profileService.ChangePassword(model);
 }
        public ActionResult ChangePassword()
        {
            var model = new ProfileChangePasswordModel();

            return(View(model));
        }