Exemple #1
0
        public AuthenticatedUserDto AuthenticateUser(AuthenticateUserDto authenticateUser)
        {
            if (authenticateUser == null)
            {
                return(new AuthenticatedUserDto($"{nameof(authenticateUser)} not found."));
            }

            if (string.IsNullOrEmpty(authenticateUser.Email))
            {
                return(new AuthenticatedUserDto("Email is required."));
            }

            if (string.IsNullOrEmpty(authenticateUser.Password))
            {
                return(new AuthenticatedUserDto("Password is required."));
            }

            string passwordDecrypt = this.EncryptionService.Decrypt(authenticateUser.Password);

            UserSystemDto userSystem = this.UserService.Find(authenticateUser.Email, passwordDecrypt);

            if (userSystem == null)
            {
                return(new AuthenticatedUserDto("The email and/or password entered is invalid. Please try again."));
            }

            return(new AuthenticatedUserDto(userSystem));
        }
        public async Task <IActionResult> InsertUserSystem(UserSystemDto userSystem)
        {
            var _roles         = GlobalApp.RolesAuthirize;
            var _userSystem    = _mapper.Map <UserSystem>(userSystem);
            var _userSystemDto = _mapper.Map <UserSystemDto>(_userSystem);
            ApiResponse <UserSystemDto> response = new ApiResponse <UserSystemDto>(_userSystemDto);

            if (_roles != null)
            {
                _roles.Where(x => x == 1 || x == 2);

                if (_roles == null)
                {
                    var responseApi = new ApiResponse <UserSystemDto>(_userSystemDto)
                    {
                        msg = "Usuario no permitido"
                    };

                    return(Ok(responseApi));
                }

                if (!_userSystemService.ValidadUserSystemByEmail(userSystem.Email))
                {
                    await _userSystemService.InsertUserSystem(_userSystem);

                    var responseApi = new ApiResponse <UserSystemDto>(_userSystemDto)
                    {
                        msg = "Usuario guardado exitosamente"
                    };

                    response = responseApi;
                }
                else
                {
                    var responseApi = new ApiResponse <UserSystemDto>(_userSystemDto)
                    {
                        msg = "El Email ingresado ya existe"
                    };
                    response = responseApi;
                }
            }
            else
            {
                return(Ok("Debe de registrarse"));
            }

            return(Ok(response));
        }
        public async Task <IActionResult> Put(int id, UserSystemDto userSystemDto)
        {
            var _userSystemDto = _mapper.Map <UserSystem>(userSystemDto);

            userSystemDto.Id = id;
            var result = await _userSystemService.UpdateUserSystem(_userSystemDto);

            ApiResponse <UserSystemDto> response = new ApiResponse <UserSystemDto>(userSystemDto);

            if (result)
            {
                var responseApi = new ApiResponse <UserSystemDto>(userSystemDto)
                {
                    msg = "Se actualizo correctamente"
                };
                response = responseApi;
            }

            return(Ok(response));
        }
Exemple #4
0
 public AuthenticatedUserDto(UserSystemDto userSystem)
     : this()
 {
     this.Authenticated = true;
     this.UserSystem    = userSystem;
 }