예제 #1
0
        public UserAuthDto ValidateUser(UserLoginDto user)
        {
            UserAuthDto ret      = new UserAuthDto();
            Users       authUser = null;

            string Pass  = user.UserPassword;
            string ePass = Encrypt.GetSHA256(Pass);

            //se conecta a la base de datos para verificar las datos del usuario en cuestion
            using (var db = new CruzRojaContext())
                authUser = db.Users.Include(u => u.Persons)
                           .Include(u => u.Roles)
                           .Include(u => u.Estates)
                           .ThenInclude(u => u.LocationAddress)
                           .Include(u => u.Estates.EstatesTimes)
                           .ThenInclude(u => u.Times)
                           .ThenInclude(u => u.Schedules)
                           .Where(u => u.UserDni == user.UserDni &&
                                  u.UserPassword == ePass).FirstOrDefault();

            if (authUser != null)
            {
                ret = _mapper.Map <UserAuthDto>(authUser); //si los datos son correctos se crea el objeto del usuario autentificado
            }

            return(ret); //retornamos el valor de este objeto
        }
예제 #2
0
 public RepositoryBase(CruzRojaContext cruzRojaContext2)
 {
     CruzRojaContext2 = cruzRojaContext2;
 }
예제 #3
0
 public UsersDatamanager(CruzRojaContext context)
 {
     _context = context;
 }
예제 #4
0
 //ctor
 public EmployeesRepository(CruzRojaContext cruzRojaContext2)
     : base(cruzRojaContext2)
 {
 }
예제 #5
0
 public LoginController(IConfiguration config, CruzRojaContext context)
 {
     _configuration = config;
     _context       = context;
 }
예제 #6
0
        //[Authorize(Roles = "Coordinador General, Admin")]
        public IActionResult UpdatePartialUser(int employeeId, JsonPatchDocument <EmployeeForUpdateDto> patchDocument)
        {
            try
            {
                var employeeEntity = _repository.Employees.GetEmployeeById(employeeId);


                if (employeeEntity == null)
                {
                    _logger.LogError($"Employee with id: {employeeId}, hasn't been found in db.");
                    return(NotFound());
                }

                var employeeToPatch = _mapper.Map <EmployeeForUpdateDto>(employeeEntity);


                patchDocument.ApplyTo(employeeToPatch, ModelState);

                var userNewPass = employeeToPatch.Users.UserNewPassword;
                //employeeToPatch.Users.UserNewPassword = Encrypt.GetSHA256(userNewPass);


                if (!TryValidateModel(employeeToPatch))
                {
                    return(ValidationProblem(ModelState));
                }

                var userPass = employeeToPatch.Users.UserPassword;
                employeeToPatch.Users.UserPassword = Encrypt.GetSHA256(userPass);

                Users authUser = new Users();

                using (var db = new CruzRojaContext())
                    authUser = db.Users.Where(u => u.UserID == employeeEntity.Users.UserID &&
                                              u.UserPassword == employeeToPatch.Users.UserPassword).FirstOrDefault();

                if (authUser != null)
                {
                    var Pass = Encrypt.GetSHA256(userNewPass);

                    employeeToPatch.Users.UserNewPassword = Pass;
                    //Encrypt.GetSHA256(employeeEntity.Users.UserPassword);

                    var employeeResult = _mapper.Map(employeeToPatch, employeeEntity);

                    employeeResult.Users.UserPassword = employeeToPatch.Users.UserNewPassword;


                    _repository.Employees.Update(employeeResult);
                    _repository.Save();

                    return(NoContent());
                }

                return(BadRequest("Contraseña Incorrecta"));
            }

            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside UpdateEmployee action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
예제 #7
0
 public VoluntersRepository(CruzRojaContext cruzRojaContext2)
     : base(cruzRojaContext2)
 {
 }
예제 #8
0
 public UsersController(IUsersRepository <Users, UsersDTO> dataRepository, CruzRojaContext context)
 {
     _dataRepository = dataRepository;
     _context        = context;
 }
예제 #9
0
 public RepositoryWrapper(CruzRojaContext cruzRojaContext2)
 {
     _cruzRojaContext2 = cruzRojaContext2;
 }
예제 #10
0
 public VehiclesRepository(CruzRojaContext cruzRojaContext2)
     : base(cruzRojaContext2)
 {
 }