{"size": 2427, "ext": "js", "max_stars_repo_path": "public/js/Admin/changePasswordAcount.js", "max_stars_repo_name": "jogs78/acumedic", "max_stars_repo_stars_event_min_datetime": "2020-10-27T05:17:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:34:29.000Z", "max_issues_repo_path": "public/js/Admin/changePasswordAcount.js", "max_issues_repo_name": "jogs78/acumedic", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "public/js/Admin/changePasswordAcount.js", "max_forks_repo_name": "jogs78/acumedic", "max_forks_repo_forks_event_min_datetime": "2020-10-03T20:19:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-21T22:21:01.000Z"}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 36.223880597, "max_line_length": 105, "alphanum_fraction": 0.5508858673}
$('#modal').on('click', function(e){
    e.preventDefault();
    limpiarErrores();
    limpiarCampos();
    $('#contraseniaUsuario').modal('show')
});

$('.enviar').on('click',function(event){
    $( "#buttonAdd" ).prop( "disabled", true );
    limpiarErrores();
    let passwordActual = $("#passwordActual").val();
    let password = $("#password").val();
    let password_confirmation = $("#password_confirmation").val();
    let idUsuario = $("#idUsuario").val();
    let token = $("input[name=_token]").val();
    var route = "/mi-cuenta/changePassword";
    console.log(password,password_confirmation,idUsuario, passwordActual)
    $.ajax({
        url:route,
        headers:{'X-CSRF-TOKEN':token},
        type: "put",
        datatype: "json",
        data: {
            passwordActual: passwordActual,
            password: password,
            password_confirmation : password_confirmation,
            idUsuario: idUsuario,
        },
        success: function(data){
            $('#contraseniaUsuario').modal('hide')
            $("#buttonAdd").prop( "disabled", false );
            limpiarCampos();
            $('#alerta').html(`<div class="alert alert-success alert-dismissible fade show" role="alert">
                    Se ha cambiado la contraseña del usuario
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>`)
                setTimeout(function() {
                    $(".alert").fadeOut(1500);
                },3000);
        },
        error: function(data){
            $("#buttonAdd").prop( "disabled", false );
            console.log(data.responseJSON.errors);
            if(data.responseJSON.errors.passwordActual){
                $("#errorpasswordActual").html(data.responseJSON.errors.passwordActual[0]);
            }
            $("#errorPassword").html(data.responseJSON.errors.password[0]);
            $("#errorPasswordconfirmation").html(data.responseJSON.errors.password_confirmation[0]);
            
            
        }
    })
});

function limpiarErrores(){
    $("#errorpasswordActual").html('');
    $("#errorPassword").html('');
    $("#errorPasswordconfirmation").html('');
}

function limpiarCampos(){
    $('#passwordActual').val('');
    $('#password').val('');
    $('#password_confirmation').val('');
}