Skip to content

Commit

Permalink
Merge branch 'main' into user2
Browse files Browse the repository at this point in the history
  • Loading branch information
wiegmank committed Apr 23, 2024
2 parents f7b7d07 + ac9ec2a commit e6830ba
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 26 deletions.
1 change: 0 additions & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 98 additions & 4 deletions ReactFrontEnd/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ReactFrontEnd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
"dependencies": {
"@tanstack/react-query": "^5.29.0",
"axios": "^1.6.8",
"context": "^3.0.29",
"dotenv": "^16.4.5",
"flowbite": "^2.3.0",
"flowbite-react": "^0.7.5",
"global": "^4.4.0",
"localforage": "^1.10.0",
"match-sorter": "^6.3.4",
"react": "^18.2.0",
"react-cookie": "^7.1.4",
"react-datepicker": "^6.6.0",
"react-dom": "^18.2.0",
"react-icons": "^5.0.1",
Expand Down
6 changes: 4 additions & 2 deletions ReactFrontEnd/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import CreateReview from './Components/CreateReview'
import SearchList from './Components/SearchList'
import ParkDetails from './Components/ParkDetails'
import Register from './Components/Register'
import Login from './Components/Login'
import Footer from './Components/Footer'


Expand All @@ -33,8 +34,9 @@ function App() {
<Route path="/itinerary" element={<Itinerary />} />
<Route path="/register" element={<Register />} />
<Route path = "/parksearch" element = {<ParkSearch />} >
<Route path = "search" element = {<SearchList />} />
</Route>
<Route path = "search" element = {<SearchList />} />
</ Route>
<Route path ="/login" element ={<Login />} />
<Route path="/parksearch/search/:parkcode" element={<ParkDetails/>} />
</Routes>
</BrowserRouter>
Expand Down
1 change: 1 addition & 0 deletions ReactFrontEnd/src/Components/HeaderItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function HeaderItem({name,Icon,path}) {
return (
<>
<Link to={path}>

<div className="text-nps-green-200 flex items-center gap-3
text-[18px] font-semibold cursor-pointer hover:underline underline-offset-8">
<Icon/>
Expand Down
32 changes: 23 additions & 9 deletions ReactFrontEnd/src/Components/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,37 @@ import { Link } from 'react-router-dom'
import Slideshow from './Slideshow'
import Header from './Header'
import axios from 'axios';
import LoginService from '../Services/LoginService';
const SERVER_API_BASE_URL = "http://localhost:8080/";
const axiosInstance = axios.create({
withCredentials: true,
baseURL: SERVER_API_BASE_URL,
headers: {
"Cache-Control": "no-cache",
"Accept-Language": "en",
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "http://localhost:5173",
"Access-Control-Allow-Methods": "POST",
"Access-Control-Allow-Headers": "Content-Type, Authorization, X-Requested-With",
"Authorization": null,

}});

function Login() {
const [user, setUser] = useState({username: "",password: ""})
const [userLogin, setUser] = useState({username: "",password: ""})

const handleSubmit = (event) => {
event.preventDefault();
axios.get("http://localhost:8080/login", user).then((response) => {
console.log(response.status, response.data)
})
LoginService.login(userLogin, axiosInstance);
};

};


const handleChange = (event) => {
const { name, value } = event.target;
setUser(prevUser => ({ ...prevUser, [name]: value }));
setUser(prevUserLogin => ({ ...prevUserLogin, [name]: value }));
};

return (<>
<Header />
<Slideshow />
Expand All @@ -28,14 +42,14 @@ function Login() {
<input
type="text"
name="username"
value={user.username}
value={userLogin.username}
onChange={handleChange}
placeholder="Username"
/>
<input
type="password"
name="password"
value={user.password}
value={userLogin.password}
onChange={handleChange}
placeholder="Enter a Password"
/>
Expand Down
22 changes: 22 additions & 0 deletions ReactFrontEnd/src/Interceptors/AxiosInterceptor.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Axios } from "axios";



class AxiosInterceptor {

updatePostHeader = (credentials, instance) => instance.interceptors.request.use(
(config) => {
const hash = window.btoa(credentials.username+":"+credentials.password);
const csrfToken = localStorage.getItem("X-XRSF-TOKEN");
if (hash) {
instance.defaults.headers["Authorization"] = hash;
}
if(csrfToken) {
instance.defaults.headers["X-XRSF-TOKEN"] = csrfToken;
}
return config
}

)
}
export default AxiosInterceptor;
35 changes: 35 additions & 0 deletions ReactFrontEnd/src/Services/LoginService.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from "react";
import axios from "axios";






class LoginService {


login(user, instance) {
if (user.username && user.password) {
instance.interceptors.request.use((config) => {
const hash = window.btoa(user.username+":"+user.password);
if (hash) {
let authHeader = "Basic "+hash;
instance.defaults.headers["Authorization"] = authHeader;
window.localStorage.setItem("Auth", authHeader);
}

return config
});
};

instance.post("/user",user)
.then((response) => {
console.log(response);
})


}
};
export default new LoginService();

1 change: 1 addition & 0 deletions ReactFrontEnd/src/Services/ReviewServices.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import axios from 'axios'
import { getItem } from 'localforage';

const REVIEW_API_BASE_URL = "http://localhost:8080/api/v1/review";

Expand Down

0 comments on commit e6830ba

Please sign in to comment.