public ResponseDTO DefineResponseType(RequestDTO requestDto) { ResponseDTO responseDto = new ResponseDTO(); if (CheckRequestPath(requestDto.Path)) { responseDto = _fileResponseBuilder.CreateFileResponse(requestDto); } else if (requestDto.Path == "\\auth") { AuthenticationPageBuilder authenticationPage = new AuthenticationPageBuilder( _statusCodeResponse.GetResponseCode(StatusCode.OK)); responseDto = authenticationPage.CreateStaticResponse(); } else if (requestDto.Path == "\\auth\\challenge") { bool isValidUser = _userController.IsValidUser(requestDto.BodyValues); if (!isValidUser) { ErrorPageBuilder errorPage = new ErrorPageBuilder( _statusCodeResponse.GetResponseCode(StatusCode.UNAUTHORIZED)); responseDto = errorPage.CreateStaticResponse(); } else { AuthenticationResponsePageBuilder authenticationResponsePage = new AuthenticationResponsePageBuilder( _statusCodeResponse.GetResponseCode(StatusCode.OK)); responseDto = authenticationResponsePage.CreateStaticResponse(); responseDto.UserName = requestDto.BodyValues.FirstOrDefault(x => x.Key == "user").Value; responseDto.CookieValue = Guid.NewGuid().ToString(); } } else { ErrorPageBuilder errorPage = new ErrorPageBuilder( _statusCodeResponse.GetResponseCode(StatusCode.NOT_FOUND)); responseDto = errorPage.CreateStaticResponse(); } return(responseDto); }
public ResponseDTO CreateFileResponse(RequestDTO requestDto) { ResponseDTO responseDto = new ResponseDTO() { IsStreamResponse = true }; string physicalPath = _fileService.GetFilePath(requestDto.Path); if (_fileService.CheckIfExists(physicalPath)) { if (!requestDto.isAuthenticated) { ErrorPageBuilder errorPage = new ErrorPageBuilder( _statusCodeResponse.GetResponseCode(StatusCode.UNAUTHORIZED)); responseDto = errorPage.CreateStaticResponse(); } else { responseDto.IsStreamResponse = true; responseDto.FileStream = _fileService.ReadFile(physicalPath); responseDto.ContentType = _fileService.GetFileMimeType(requestDto.Path); responseDto.ContentLength = Convert.ToInt32(responseDto.FileStream.Length); responseDto.Code = _statusCodeResponse.GetResponseCode(StatusCode.OK); } } else { ErrorPageBuilder errorPage = new ErrorPageBuilder( _statusCodeResponse.GetResponseCode(StatusCode.NOT_FOUND)); responseDto = errorPage.CreateStaticResponse(); } return(responseDto); }