Beispiel #1
0
        public async Task <IHttpActionResult> ResetPassword(ResetPasswordDto resetPasswordDto)
        {
            _logger.Debug(string.Format("Begin. Code: [{0}], Id: [{1}]",
                                        resetPasswordDto.Code,
                                        resetPasswordDto.Id));
            if (!ModelState.IsValid)
            {
                _logger.Error(string.Format(
                                  "Model state is not valid. ModelState: [{0}]",
                                  string.Join(Environment.NewLine, ModelState.Select(x => string.Format("{0}: {1}", x.Key, x.Value)))));
                return(BadRequest(ModelState));
            }

            IdentityResult result = await NdUserManager.ResetPasswordAsync(resetPasswordDto.Id, resetPasswordDto.Code, resetPasswordDto.Password);

            if (result.Succeeded)
            {
                _logger.Debug(string.Format("Password reseted successfully. Id: [{0}]", resetPasswordDto.Id));

                try
                {
                    await NdUserManager.SendEmailAsync(resetPasswordDto.Id, "Password Reseted", NdEmailService.CreatePasswordResetedBody());
                }
                catch (Exception ex)
                {
                    _logger.Error(string.Format("Error sending PasswordReseted email. Id: [{0}]", resetPasswordDto.Id), ex);
                    return(InternalServerError(ex));
                }

                return(Ok());
            }
            else
            {
                _logger.Error(string.Format(
                                  "Reset password failed. Id: [{0}], Code: [{1}], Reason: [{2}]",
                                  resetPasswordDto.Id, resetPasswordDto.Code,
                                  string.Join(Environment.NewLine, result.Errors)));
                return(GetErrorResult(result));
            }
        }