Esempio n. 1
0
        public IActionResult userResetPassword(userResetPasswordReq req)
        {
            try
            {
                //int domain_id = DAC.MeucciDAC.GetDimainId(req.DomainName);

                if (req.ResetUserCAIS == false)
                {
                    //Regla Si se intenta resetear por tercera o más veces un UW el mismo día,
                    var intentos = MeucciDAC.ValidarteIntentos(req.WindowsUser, req.dom_id, Common.resetear);
                    if (intentos > 2)
                    {
                        throw new Fwk.Exceptions.FunctionalException("No es posible resetear más de dos veces el Usuario Windows el mismo día. Por favor comuníquese con el CAIS.");
                    }
                }
                //Si el usuario pertenece al CAIS será obligatoria la carga del Nº de Ticket.
                if (req.ResetUserCAIS)
                {
                    if (string.IsNullOrEmpty(req.ticket))
                    {
                        throw new Fwk.Exceptions.FunctionalException("El Nº de Ticket es obligatorio .-");
                    }
                }
                req.newPassword = _LDAPService.GetRandomPassword();

                var fwk_domain_name = _LDAPService.Get_correct_DomainName(req.DomainName);

                ActiveDirectoryService.User_Reset_Password(req.WindowsUser, req.newPassword, fwk_domain_name);

                DAC.MeucciDAC.ReseteoWeb_Log(req.Emp_Id, req.WindowsUser, req.dom_id, req.ResetUserId, req.ticket, Common.resetear, req.host);
                DAC.MeucciDAC.ReseteoWeb_EnviosMails(req.Emp_Id, req.WindowsUser, req.dom_id, req.ResetUserId, Common.resetear, req.host);
                //return apiHelper.fromObject<String>("El reseteo se realizó exitosamente. La contraseña provisoria es " + req.newPassword);

                return(Ok("El reseteo se realizó exitosamente. La contraseña provisoria es " + req.newPassword));
            }
            catch (Exception ex)
            {
                //Acceso denegado. (Excepción de HRESULT: 0x80070005 (E_ACCESSDENIED))
                var msg = Fwk.Exceptions.ExceptionHelper.GetAllMessageException(ex, false);
                if (msg.ToLower().Contains("impersonali") || msg.ToLower().Contains("acceso"))
                {
                    TechnicalException t = new TechnicalException("No es posible desbloquear " + req.WindowsUser + " en el dominio " + req.DomainName
                                                                  + " deberá comunicarse  con el CAIS");
                    ex = t;
                }
                if (msg.Contains("E_ACCESSDENIED"))
                {
                    TechnicalException t = new TechnicalException("No es posible desbloquear " + req.WindowsUser + " en el dominio " + req.DomainName
                                                                  + " deberá comunicarse con el CAIS");
                    ex = t;
                }
                msg = apiHelper.getMessageException(ex);
                return(BadRequest(new ApiErrorResponse(HttpStatusCode.InternalServerError, msg)));
            }
        }