From 3e66dbf6e95819ad3015e620e3663e3f5178b6be Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 15 Mar 2019 14:49:22 -0700 Subject: [PATCH 1/7] Implement registerUser --- client/src/backendCalls/auth/registerUser.js | 50 ++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 client/src/backendCalls/auth/registerUser.js diff --git a/client/src/backendCalls/auth/registerUser.js b/client/src/backendCalls/auth/registerUser.js new file mode 100644 index 0000000..dc4b560 --- /dev/null +++ b/client/src/backendCalls/auth/registerUser.js @@ -0,0 +1,50 @@ +//import appConfig from '../../../../auth_server/src/configurations/app.ts'; + +/** + * Registers a user with the given email, password, first and last name. + * If either first_name or last_name are undefined, the user will be registered + * without a first or last name respectively. + */ +export async function registerUser(email, password, first_name, last_name) { + var details = { + "email": email, + "password": password, + "first_name": first_name, + "last_name": last_name + } + + var formBody = []; + for (var property in details) { + if (details[property] === undefined) { + continue; + } + var encodedKey = encodeURIComponent(property); + var encodedValue = encodeURIComponent(details[property]); + formBody.push(encodedKey + "=" + encodedValue); + } + formBody = formBody.join("&"); + + const response = await fetch("http://localhost:5050/user", { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: formBody, + }); + + const body = await response.json(); + + console.log(body); + if (response.status !== 201) { + if (body.error) { + return body.error; + } + else { + return JSON.stringify(body); + } + } else { + return 200; + } +} + +export default registerUser From 97d5e2adbe781a677d0a297834256d54e3f283b3 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 20 Mar 2019 15:35:16 -0700 Subject: [PATCH 2/7] Test using app --- client/src/App.js | 3 +- client/src/backendCalls/auth/registerUser.js | 3 ++ client/src/backendCalls/auth/userLogin.js | 46 ++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 client/src/backendCalls/auth/userLogin.js diff --git a/client/src/App.js b/client/src/App.js index 319bc59..fd5b6dc 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -6,7 +6,7 @@ import Footer from './views/Footer'; import FilterMenu from './components/FilterMenu'; import Routes from './config/Routes'; import { searchJobs } from './backendCalls/searchEndpoints.js'; - +import registerUser from './backendCalls/auth/registerUser.js' class App extends Component { constructor(props, context) { super(props, context); @@ -66,6 +66,7 @@ class App extends Component { } render() { + registerUser("asdf@asdf.asdfasdf", "Aasdf", undefined, undefined) return (
diff --git a/client/src/backendCalls/auth/registerUser.js b/client/src/backendCalls/auth/registerUser.js index dc4b560..e15c92e 100644 --- a/client/src/backendCalls/auth/registerUser.js +++ b/client/src/backendCalls/auth/registerUser.js @@ -5,6 +5,7 @@ * If either first_name or last_name are undefined, the user will be registered * without a first or last name respectively. */ + export async function registerUser(email, password, first_name, last_name) { var details = { "email": email, @@ -26,7 +27,9 @@ export async function registerUser(email, password, first_name, last_name) { const response = await fetch("http://localhost:5050/user", { method: 'POST', + mode: 'cors', headers: { + Accept: 'application/json', 'Content-Type': 'application/x-www-form-urlencoded', }, body: formBody, diff --git a/client/src/backendCalls/auth/userLogin.js b/client/src/backendCalls/auth/userLogin.js new file mode 100644 index 0000000..eb160de --- /dev/null +++ b/client/src/backendCalls/auth/userLogin.js @@ -0,0 +1,46 @@ +/** + * Registers a user with the given email, password, first and last name. + * If either first_name or last_name are undefined, the user will be registered + * without a first or last name respectively. + */ +export async function userLogin(email, password) { + var details = { + "email": email, + "password": password, + } + + var formBody = []; + for (var property in details) { + if (details[property] === undefined) { + continue; + } + var encodedKey = encodeURIComponent(property); + var encodedValue = encodeURIComponent(details[property]); + formBody.push(encodedKey + "=" + encodedValue); + } + formBody = formBody.join("&"); + + const response = await fetch("http://localhost:5050/user/login", { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: formBody, + }); + + const body = await response.json(); + + console.log(body); + if (response.status !== 201) { + if (body.error) { + return body.error; + } + else { + return JSON.stringify(body); + } + } else { + return 200; + } +} + +export default userLogin From 071ba3b53b06c8b9f8f912818ab8f409fc02adb8 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 23 Mar 2019 11:32:21 -0700 Subject: [PATCH 3/7] Changed to single quotes --- client/src/App.js | 2 +- client/src/App.js.orig | 148 +++++++++++++++++++ client/src/App_BACKUP_30193.js | 148 +++++++++++++++++++ client/src/App_BACKUP_30298.js | 148 +++++++++++++++++++ client/src/App_BASE_30193.js | 87 +++++++++++ client/src/App_BASE_30298.js | 87 +++++++++++ client/src/App_LOCAL_30193.js | 88 +++++++++++ client/src/App_LOCAL_30298.js | 88 +++++++++++ client/src/App_REMOTE_30193.js | 139 +++++++++++++++++ client/src/App_REMOTE_30298.js | 139 +++++++++++++++++ client/src/backendCalls/auth/registerUser.js | 18 +-- client/src/backendCalls/auth/userLogin.js | 17 +-- client/src/store.js | 3 +- 13 files changed, 1091 insertions(+), 21 deletions(-) create mode 100644 client/src/App.js.orig create mode 100644 client/src/App_BACKUP_30193.js create mode 100644 client/src/App_BACKUP_30298.js create mode 100644 client/src/App_BASE_30193.js create mode 100644 client/src/App_BASE_30298.js create mode 100644 client/src/App_LOCAL_30193.js create mode 100644 client/src/App_LOCAL_30298.js create mode 100644 client/src/App_REMOTE_30193.js create mode 100644 client/src/App_REMOTE_30298.js diff --git a/client/src/App.js b/client/src/App.js index fd5b6dc..d41c92e 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -66,7 +66,7 @@ class App extends Component { } render() { - registerUser("asdf@asdf.asdfasdf", "Aasdf", undefined, undefined) + registerUser("asdf@asd2f.asdfasdf", "Aasdf", undefined, undefined) return (
diff --git a/client/src/App.js.orig b/client/src/App.js.orig new file mode 100644 index 0000000..064c2b0 --- /dev/null +++ b/client/src/App.js.orig @@ -0,0 +1,148 @@ +import React, { Component } from 'react'; +import { withRouter } from 'react-router-dom'; +import Navbar from './views/Navbar'; +import Footer from './views/Footer'; +import Routes from './config/Routes'; +<<<<<<< HEAD +import { searchJobs } from './backendCalls/searchEndpoints.js'; +import registerUser from './backendCalls/auth/registerUser.js' +======= +import { searchJobs } from './backendCalls/searchEndpoints'; + +>>>>>>> develop +class App extends Component { + constructor(props, context) { + super(props, context); + + this.state = { + searchKeywords: '', + latitude: 0.0, + longitude: 0.0, + selectedCategories: [], + selectedIndustries: [], + minSalary: 0, + }; + } + + updateSearchKeywords = (event) => { + this.setState({ searchKeywords: event.target.value }); + }; + + handleAddCategory = (category) => () => { + this.setState((prevState) => ({ + selectedCategories: prevState.selectedCategories.includes(category) + ? [...prevState.selectedCategories] + : [...prevState.selectedCategories, category], + })); + }; + + handleAddIndustry = (industry) => () => { + this.setState((prevState) => ({ + selectedIndustries: prevState.selectedIndustries.includes(industry) + ? [...prevState.selectedIndustries] + : [...prevState.selectedIndustries, industry], + })); + }; + + handleRemoveCategory = (categoryToRemove) => () => { + this.setState((prevState) => ({ + selectedCategories: prevState.selectedCategories.filter((category) => category !== categoryToRemove), + })); + }; + + handleRemoveIndustry = (industryToRemove) => () => { + this.setState((prevState) => ({ + selectedIndustries: prevState.selectedIndustries.filter((industry) => industry !== industryToRemove), + })); + }; + + onChangeLocation = (newLatLng) => { + this.setState({ + latitude: newLatLng.lat, + longitude: newLatLng.lng, + }); + }; + + handleAddMinSalary = async (newSalary) => { + await this.setState({ + minSalary: newSalary, + }); + this.handleSearch(); + }; + + handleRemoveMinSalary = async () => { + await this.setState({ + minSalary: 0, + }); + this.handleSearch(); + }; + + handleClearFilters = async () => { + await this.setState({ + minSalary: 0, + selectedCategories: [], + selectedIndustries: [], + }); + this.handleSearch(); + }; + + // construct the JSON body of the search request + constructBody = (searchKeywords) => { + const body = { + keywords: searchKeywords, + }; + + if (this.state.minSalary) { + body.salaryMin = this.state.minSalary; + } + + if (this.state.latitude && this.state.longitude) { + body.latitude = this.state.latitude; + body.longitude = this.state.longitude; + // TODO: let user choose radius + body.radius = 50; + } + return JSON.stringify(body); + }; + + handleSearch = async () => { + const keywords = this.constructBody(this.state.searchKeywords); + await searchJobs(keywords); + this.props.history.push('/results'); + }; + + render() { +<<<<<<< HEAD + registerUser("asdf@asdf.asdfasdf", "Aasdf", undefined, undefined) +======= + const { + searchKeywords, selectedCategories, selectedIndustries, minSalary, + } = this.state; + +>>>>>>> develop + return ( +
+ + +
+
+ ); + } +} + +export default withRouter(App); diff --git a/client/src/App_BACKUP_30193.js b/client/src/App_BACKUP_30193.js new file mode 100644 index 0000000..064c2b0 --- /dev/null +++ b/client/src/App_BACKUP_30193.js @@ -0,0 +1,148 @@ +import React, { Component } from 'react'; +import { withRouter } from 'react-router-dom'; +import Navbar from './views/Navbar'; +import Footer from './views/Footer'; +import Routes from './config/Routes'; +<<<<<<< HEAD +import { searchJobs } from './backendCalls/searchEndpoints.js'; +import registerUser from './backendCalls/auth/registerUser.js' +======= +import { searchJobs } from './backendCalls/searchEndpoints'; + +>>>>>>> develop +class App extends Component { + constructor(props, context) { + super(props, context); + + this.state = { + searchKeywords: '', + latitude: 0.0, + longitude: 0.0, + selectedCategories: [], + selectedIndustries: [], + minSalary: 0, + }; + } + + updateSearchKeywords = (event) => { + this.setState({ searchKeywords: event.target.value }); + }; + + handleAddCategory = (category) => () => { + this.setState((prevState) => ({ + selectedCategories: prevState.selectedCategories.includes(category) + ? [...prevState.selectedCategories] + : [...prevState.selectedCategories, category], + })); + }; + + handleAddIndustry = (industry) => () => { + this.setState((prevState) => ({ + selectedIndustries: prevState.selectedIndustries.includes(industry) + ? [...prevState.selectedIndustries] + : [...prevState.selectedIndustries, industry], + })); + }; + + handleRemoveCategory = (categoryToRemove) => () => { + this.setState((prevState) => ({ + selectedCategories: prevState.selectedCategories.filter((category) => category !== categoryToRemove), + })); + }; + + handleRemoveIndustry = (industryToRemove) => () => { + this.setState((prevState) => ({ + selectedIndustries: prevState.selectedIndustries.filter((industry) => industry !== industryToRemove), + })); + }; + + onChangeLocation = (newLatLng) => { + this.setState({ + latitude: newLatLng.lat, + longitude: newLatLng.lng, + }); + }; + + handleAddMinSalary = async (newSalary) => { + await this.setState({ + minSalary: newSalary, + }); + this.handleSearch(); + }; + + handleRemoveMinSalary = async () => { + await this.setState({ + minSalary: 0, + }); + this.handleSearch(); + }; + + handleClearFilters = async () => { + await this.setState({ + minSalary: 0, + selectedCategories: [], + selectedIndustries: [], + }); + this.handleSearch(); + }; + + // construct the JSON body of the search request + constructBody = (searchKeywords) => { + const body = { + keywords: searchKeywords, + }; + + if (this.state.minSalary) { + body.salaryMin = this.state.minSalary; + } + + if (this.state.latitude && this.state.longitude) { + body.latitude = this.state.latitude; + body.longitude = this.state.longitude; + // TODO: let user choose radius + body.radius = 50; + } + return JSON.stringify(body); + }; + + handleSearch = async () => { + const keywords = this.constructBody(this.state.searchKeywords); + await searchJobs(keywords); + this.props.history.push('/results'); + }; + + render() { +<<<<<<< HEAD + registerUser("asdf@asdf.asdfasdf", "Aasdf", undefined, undefined) +======= + const { + searchKeywords, selectedCategories, selectedIndustries, minSalary, + } = this.state; + +>>>>>>> develop + return ( +
+ + +
+
+ ); + } +} + +export default withRouter(App); diff --git a/client/src/App_BACKUP_30298.js b/client/src/App_BACKUP_30298.js new file mode 100644 index 0000000..064c2b0 --- /dev/null +++ b/client/src/App_BACKUP_30298.js @@ -0,0 +1,148 @@ +import React, { Component } from 'react'; +import { withRouter } from 'react-router-dom'; +import Navbar from './views/Navbar'; +import Footer from './views/Footer'; +import Routes from './config/Routes'; +<<<<<<< HEAD +import { searchJobs } from './backendCalls/searchEndpoints.js'; +import registerUser from './backendCalls/auth/registerUser.js' +======= +import { searchJobs } from './backendCalls/searchEndpoints'; + +>>>>>>> develop +class App extends Component { + constructor(props, context) { + super(props, context); + + this.state = { + searchKeywords: '', + latitude: 0.0, + longitude: 0.0, + selectedCategories: [], + selectedIndustries: [], + minSalary: 0, + }; + } + + updateSearchKeywords = (event) => { + this.setState({ searchKeywords: event.target.value }); + }; + + handleAddCategory = (category) => () => { + this.setState((prevState) => ({ + selectedCategories: prevState.selectedCategories.includes(category) + ? [...prevState.selectedCategories] + : [...prevState.selectedCategories, category], + })); + }; + + handleAddIndustry = (industry) => () => { + this.setState((prevState) => ({ + selectedIndustries: prevState.selectedIndustries.includes(industry) + ? [...prevState.selectedIndustries] + : [...prevState.selectedIndustries, industry], + })); + }; + + handleRemoveCategory = (categoryToRemove) => () => { + this.setState((prevState) => ({ + selectedCategories: prevState.selectedCategories.filter((category) => category !== categoryToRemove), + })); + }; + + handleRemoveIndustry = (industryToRemove) => () => { + this.setState((prevState) => ({ + selectedIndustries: prevState.selectedIndustries.filter((industry) => industry !== industryToRemove), + })); + }; + + onChangeLocation = (newLatLng) => { + this.setState({ + latitude: newLatLng.lat, + longitude: newLatLng.lng, + }); + }; + + handleAddMinSalary = async (newSalary) => { + await this.setState({ + minSalary: newSalary, + }); + this.handleSearch(); + }; + + handleRemoveMinSalary = async () => { + await this.setState({ + minSalary: 0, + }); + this.handleSearch(); + }; + + handleClearFilters = async () => { + await this.setState({ + minSalary: 0, + selectedCategories: [], + selectedIndustries: [], + }); + this.handleSearch(); + }; + + // construct the JSON body of the search request + constructBody = (searchKeywords) => { + const body = { + keywords: searchKeywords, + }; + + if (this.state.minSalary) { + body.salaryMin = this.state.minSalary; + } + + if (this.state.latitude && this.state.longitude) { + body.latitude = this.state.latitude; + body.longitude = this.state.longitude; + // TODO: let user choose radius + body.radius = 50; + } + return JSON.stringify(body); + }; + + handleSearch = async () => { + const keywords = this.constructBody(this.state.searchKeywords); + await searchJobs(keywords); + this.props.history.push('/results'); + }; + + render() { +<<<<<<< HEAD + registerUser("asdf@asdf.asdfasdf", "Aasdf", undefined, undefined) +======= + const { + searchKeywords, selectedCategories, selectedIndustries, minSalary, + } = this.state; + +>>>>>>> develop + return ( +
+ + +
+
+ ); + } +} + +export default withRouter(App); diff --git a/client/src/App_BASE_30193.js b/client/src/App_BASE_30193.js new file mode 100644 index 0000000..319bc59 --- /dev/null +++ b/client/src/App_BASE_30193.js @@ -0,0 +1,87 @@ +import React, { Component } from 'react'; +import { withRouter } from 'react-router-dom'; +import './sass/ResultsTable.scss'; +import Navbar from './views/Navbar'; +import Footer from './views/Footer'; +import FilterMenu from './components/FilterMenu'; +import Routes from './config/Routes'; +import { searchJobs } from './backendCalls/searchEndpoints.js'; + +class App extends Component { + constructor(props, context) { + super(props, context); + + this.state = { + data: [], + isFilterMenuVisible: false, + latitude: 0.0, + longitude: 0.0, + categories: [], + industries: [], + salary: 0, + }; + } + + toggleFilterVisibility = () => { + this.setState(prevState => ({ + isFilterMenuVisible: !prevState.isFilterMenuVisible, + })); + }; + + onChangeLocation = (newLatLng) => { + this.setState({ + latitude: newLatLng.lat, + longitude: newLatLng.lng, + }); + } + + onChangeMinSalary = (newSalary) => { + this.setState({ + salary: newSalary, + }); + } + + // construct the JSON body of the search request + constructBody = (searchKeywords) => { + const body = { + keywords: searchKeywords, + }; + if (this.state.salary) { + body.salaryMin = this.state.salary; + } + + if (this.state.latitude && this.state.longitude) { + body.latitude = this.state.latitude; + body.longitude = this.state.longitude; + // TODO: let user choose radius + body.radius = 50; + } + return JSON.stringify(body); + } + + searchHandler = (searchKeywords) => async() => { + var keywords = this.constructBody(searchKeywords); + await searchJobs(keywords); + this.props.history.push('/results'); + } + + render() { + return ( +
+ + {this.state.isFilterMenuVisible ? + } + + +
+
+ ); + } +} + +export default withRouter(App); diff --git a/client/src/App_BASE_30298.js b/client/src/App_BASE_30298.js new file mode 100644 index 0000000..319bc59 --- /dev/null +++ b/client/src/App_BASE_30298.js @@ -0,0 +1,87 @@ +import React, { Component } from 'react'; +import { withRouter } from 'react-router-dom'; +import './sass/ResultsTable.scss'; +import Navbar from './views/Navbar'; +import Footer from './views/Footer'; +import FilterMenu from './components/FilterMenu'; +import Routes from './config/Routes'; +import { searchJobs } from './backendCalls/searchEndpoints.js'; + +class App extends Component { + constructor(props, context) { + super(props, context); + + this.state = { + data: [], + isFilterMenuVisible: false, + latitude: 0.0, + longitude: 0.0, + categories: [], + industries: [], + salary: 0, + }; + } + + toggleFilterVisibility = () => { + this.setState(prevState => ({ + isFilterMenuVisible: !prevState.isFilterMenuVisible, + })); + }; + + onChangeLocation = (newLatLng) => { + this.setState({ + latitude: newLatLng.lat, + longitude: newLatLng.lng, + }); + } + + onChangeMinSalary = (newSalary) => { + this.setState({ + salary: newSalary, + }); + } + + // construct the JSON body of the search request + constructBody = (searchKeywords) => { + const body = { + keywords: searchKeywords, + }; + if (this.state.salary) { + body.salaryMin = this.state.salary; + } + + if (this.state.latitude && this.state.longitude) { + body.latitude = this.state.latitude; + body.longitude = this.state.longitude; + // TODO: let user choose radius + body.radius = 50; + } + return JSON.stringify(body); + } + + searchHandler = (searchKeywords) => async() => { + var keywords = this.constructBody(searchKeywords); + await searchJobs(keywords); + this.props.history.push('/results'); + } + + render() { + return ( +
+ + {this.state.isFilterMenuVisible ? + } + + +
+
+ ); + } +} + +export default withRouter(App); diff --git a/client/src/App_LOCAL_30193.js b/client/src/App_LOCAL_30193.js new file mode 100644 index 0000000..fd5b6dc --- /dev/null +++ b/client/src/App_LOCAL_30193.js @@ -0,0 +1,88 @@ +import React, { Component } from 'react'; +import { withRouter } from 'react-router-dom'; +import './sass/ResultsTable.scss'; +import Navbar from './views/Navbar'; +import Footer from './views/Footer'; +import FilterMenu from './components/FilterMenu'; +import Routes from './config/Routes'; +import { searchJobs } from './backendCalls/searchEndpoints.js'; +import registerUser from './backendCalls/auth/registerUser.js' +class App extends Component { + constructor(props, context) { + super(props, context); + + this.state = { + data: [], + isFilterMenuVisible: false, + latitude: 0.0, + longitude: 0.0, + categories: [], + industries: [], + salary: 0, + }; + } + + toggleFilterVisibility = () => { + this.setState(prevState => ({ + isFilterMenuVisible: !prevState.isFilterMenuVisible, + })); + }; + + onChangeLocation = (newLatLng) => { + this.setState({ + latitude: newLatLng.lat, + longitude: newLatLng.lng, + }); + } + + onChangeMinSalary = (newSalary) => { + this.setState({ + salary: newSalary, + }); + } + + // construct the JSON body of the search request + constructBody = (searchKeywords) => { + const body = { + keywords: searchKeywords, + }; + if (this.state.salary) { + body.salaryMin = this.state.salary; + } + + if (this.state.latitude && this.state.longitude) { + body.latitude = this.state.latitude; + body.longitude = this.state.longitude; + // TODO: let user choose radius + body.radius = 50; + } + return JSON.stringify(body); + } + + searchHandler = (searchKeywords) => async() => { + var keywords = this.constructBody(searchKeywords); + await searchJobs(keywords); + this.props.history.push('/results'); + } + + render() { + registerUser("asdf@asdf.asdfasdf", "Aasdf", undefined, undefined) + return ( +
+ + {this.state.isFilterMenuVisible ? + } + + +
+
+ ); + } +} + +export default withRouter(App); diff --git a/client/src/App_LOCAL_30298.js b/client/src/App_LOCAL_30298.js new file mode 100644 index 0000000..fd5b6dc --- /dev/null +++ b/client/src/App_LOCAL_30298.js @@ -0,0 +1,88 @@ +import React, { Component } from 'react'; +import { withRouter } from 'react-router-dom'; +import './sass/ResultsTable.scss'; +import Navbar from './views/Navbar'; +import Footer from './views/Footer'; +import FilterMenu from './components/FilterMenu'; +import Routes from './config/Routes'; +import { searchJobs } from './backendCalls/searchEndpoints.js'; +import registerUser from './backendCalls/auth/registerUser.js' +class App extends Component { + constructor(props, context) { + super(props, context); + + this.state = { + data: [], + isFilterMenuVisible: false, + latitude: 0.0, + longitude: 0.0, + categories: [], + industries: [], + salary: 0, + }; + } + + toggleFilterVisibility = () => { + this.setState(prevState => ({ + isFilterMenuVisible: !prevState.isFilterMenuVisible, + })); + }; + + onChangeLocation = (newLatLng) => { + this.setState({ + latitude: newLatLng.lat, + longitude: newLatLng.lng, + }); + } + + onChangeMinSalary = (newSalary) => { + this.setState({ + salary: newSalary, + }); + } + + // construct the JSON body of the search request + constructBody = (searchKeywords) => { + const body = { + keywords: searchKeywords, + }; + if (this.state.salary) { + body.salaryMin = this.state.salary; + } + + if (this.state.latitude && this.state.longitude) { + body.latitude = this.state.latitude; + body.longitude = this.state.longitude; + // TODO: let user choose radius + body.radius = 50; + } + return JSON.stringify(body); + } + + searchHandler = (searchKeywords) => async() => { + var keywords = this.constructBody(searchKeywords); + await searchJobs(keywords); + this.props.history.push('/results'); + } + + render() { + registerUser("asdf@asdf.asdfasdf", "Aasdf", undefined, undefined) + return ( +
+ + {this.state.isFilterMenuVisible ? + } + + +
+
+ ); + } +} + +export default withRouter(App); diff --git a/client/src/App_REMOTE_30193.js b/client/src/App_REMOTE_30193.js new file mode 100644 index 0000000..ac477c9 --- /dev/null +++ b/client/src/App_REMOTE_30193.js @@ -0,0 +1,139 @@ +import React, { Component } from 'react'; +import { withRouter } from 'react-router-dom'; +import Navbar from './views/Navbar'; +import Footer from './views/Footer'; +import Routes from './config/Routes'; +import { searchJobs } from './backendCalls/searchEndpoints'; + +class App extends Component { + constructor(props, context) { + super(props, context); + + this.state = { + searchKeywords: '', + latitude: 0.0, + longitude: 0.0, + selectedCategories: [], + selectedIndustries: [], + minSalary: 0, + }; + } + + updateSearchKeywords = (event) => { + this.setState({ searchKeywords: event.target.value }); + }; + + handleAddCategory = (category) => () => { + this.setState((prevState) => ({ + selectedCategories: prevState.selectedCategories.includes(category) + ? [...prevState.selectedCategories] + : [...prevState.selectedCategories, category], + })); + }; + + handleAddIndustry = (industry) => () => { + this.setState((prevState) => ({ + selectedIndustries: prevState.selectedIndustries.includes(industry) + ? [...prevState.selectedIndustries] + : [...prevState.selectedIndustries, industry], + })); + }; + + handleRemoveCategory = (categoryToRemove) => () => { + this.setState((prevState) => ({ + selectedCategories: prevState.selectedCategories.filter((category) => category !== categoryToRemove), + })); + }; + + handleRemoveIndustry = (industryToRemove) => () => { + this.setState((prevState) => ({ + selectedIndustries: prevState.selectedIndustries.filter((industry) => industry !== industryToRemove), + })); + }; + + onChangeLocation = (newLatLng) => { + this.setState({ + latitude: newLatLng.lat, + longitude: newLatLng.lng, + }); + }; + + handleAddMinSalary = async (newSalary) => { + await this.setState({ + minSalary: newSalary, + }); + this.handleSearch(); + }; + + handleRemoveMinSalary = async () => { + await this.setState({ + minSalary: 0, + }); + this.handleSearch(); + }; + + handleClearFilters = async () => { + await this.setState({ + minSalary: 0, + selectedCategories: [], + selectedIndustries: [], + }); + this.handleSearch(); + }; + + // construct the JSON body of the search request + constructBody = (searchKeywords) => { + const body = { + keywords: searchKeywords, + }; + + if (this.state.minSalary) { + body.salaryMin = this.state.minSalary; + } + + if (this.state.latitude && this.state.longitude) { + body.latitude = this.state.latitude; + body.longitude = this.state.longitude; + // TODO: let user choose radius + body.radius = 50; + } + return JSON.stringify(body); + }; + + handleSearch = async () => { + const keywords = this.constructBody(this.state.searchKeywords); + await searchJobs(keywords); + this.props.history.push('/results'); + }; + + render() { + const { + searchKeywords, selectedCategories, selectedIndustries, minSalary, + } = this.state; + + return ( +
+ + +
+
+ ); + } +} + +export default withRouter(App); diff --git a/client/src/App_REMOTE_30298.js b/client/src/App_REMOTE_30298.js new file mode 100644 index 0000000..ac477c9 --- /dev/null +++ b/client/src/App_REMOTE_30298.js @@ -0,0 +1,139 @@ +import React, { Component } from 'react'; +import { withRouter } from 'react-router-dom'; +import Navbar from './views/Navbar'; +import Footer from './views/Footer'; +import Routes from './config/Routes'; +import { searchJobs } from './backendCalls/searchEndpoints'; + +class App extends Component { + constructor(props, context) { + super(props, context); + + this.state = { + searchKeywords: '', + latitude: 0.0, + longitude: 0.0, + selectedCategories: [], + selectedIndustries: [], + minSalary: 0, + }; + } + + updateSearchKeywords = (event) => { + this.setState({ searchKeywords: event.target.value }); + }; + + handleAddCategory = (category) => () => { + this.setState((prevState) => ({ + selectedCategories: prevState.selectedCategories.includes(category) + ? [...prevState.selectedCategories] + : [...prevState.selectedCategories, category], + })); + }; + + handleAddIndustry = (industry) => () => { + this.setState((prevState) => ({ + selectedIndustries: prevState.selectedIndustries.includes(industry) + ? [...prevState.selectedIndustries] + : [...prevState.selectedIndustries, industry], + })); + }; + + handleRemoveCategory = (categoryToRemove) => () => { + this.setState((prevState) => ({ + selectedCategories: prevState.selectedCategories.filter((category) => category !== categoryToRemove), + })); + }; + + handleRemoveIndustry = (industryToRemove) => () => { + this.setState((prevState) => ({ + selectedIndustries: prevState.selectedIndustries.filter((industry) => industry !== industryToRemove), + })); + }; + + onChangeLocation = (newLatLng) => { + this.setState({ + latitude: newLatLng.lat, + longitude: newLatLng.lng, + }); + }; + + handleAddMinSalary = async (newSalary) => { + await this.setState({ + minSalary: newSalary, + }); + this.handleSearch(); + }; + + handleRemoveMinSalary = async () => { + await this.setState({ + minSalary: 0, + }); + this.handleSearch(); + }; + + handleClearFilters = async () => { + await this.setState({ + minSalary: 0, + selectedCategories: [], + selectedIndustries: [], + }); + this.handleSearch(); + }; + + // construct the JSON body of the search request + constructBody = (searchKeywords) => { + const body = { + keywords: searchKeywords, + }; + + if (this.state.minSalary) { + body.salaryMin = this.state.minSalary; + } + + if (this.state.latitude && this.state.longitude) { + body.latitude = this.state.latitude; + body.longitude = this.state.longitude; + // TODO: let user choose radius + body.radius = 50; + } + return JSON.stringify(body); + }; + + handleSearch = async () => { + const keywords = this.constructBody(this.state.searchKeywords); + await searchJobs(keywords); + this.props.history.push('/results'); + }; + + render() { + const { + searchKeywords, selectedCategories, selectedIndustries, minSalary, + } = this.state; + + return ( +
+ + +
+
+ ); + } +} + +export default withRouter(App); diff --git a/client/src/backendCalls/auth/registerUser.js b/client/src/backendCalls/auth/registerUser.js index e15c92e..a1ace0e 100644 --- a/client/src/backendCalls/auth/registerUser.js +++ b/client/src/backendCalls/auth/registerUser.js @@ -1,17 +1,17 @@ -//import appConfig from '../../../../auth_server/src/configurations/app.ts'; - /** * Registers a user with the given email, password, first and last name. * If either first_name or last_name are undefined, the user will be registered * without a first or last name respectively. */ +import store from '../../store.js'; + export async function registerUser(email, password, first_name, last_name) { var details = { - "email": email, - "password": password, - "first_name": first_name, - "last_name": last_name + 'email': email, + 'password': password, + 'first_name': first_name, + 'last_name': last_name } var formBody = []; @@ -21,11 +21,11 @@ export async function registerUser(email, password, first_name, last_name) { } var encodedKey = encodeURIComponent(property); var encodedValue = encodeURIComponent(details[property]); - formBody.push(encodedKey + "=" + encodedValue); + formBody.push(encodedKey + '=' + encodedValue); } - formBody = formBody.join("&"); + formBody = formBody.join('&'); - const response = await fetch("http://localhost:5050/user", { + const response = await fetch(store.authApiBase + '/user', { method: 'POST', mode: 'cors', headers: { diff --git a/client/src/backendCalls/auth/userLogin.js b/client/src/backendCalls/auth/userLogin.js index eb160de..753084a 100644 --- a/client/src/backendCalls/auth/userLogin.js +++ b/client/src/backendCalls/auth/userLogin.js @@ -1,12 +1,9 @@ -/** - * Registers a user with the given email, password, first and last name. - * If either first_name or last_name are undefined, the user will be registered - * without a first or last name respectively. - */ +import store from '../../store.js'; + export async function userLogin(email, password) { var details = { - "email": email, - "password": password, + 'email': email, + 'password': password, } var formBody = []; @@ -16,11 +13,11 @@ export async function userLogin(email, password) { } var encodedKey = encodeURIComponent(property); var encodedValue = encodeURIComponent(details[property]); - formBody.push(encodedKey + "=" + encodedValue); + formBody.push(encodedKey + '=' + encodedValue); } - formBody = formBody.join("&"); + formBody = formBody.join('&'); - const response = await fetch("http://localhost:5050/user/login", { + const response = await fetch(store.authApiBase + '/user/login', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', diff --git a/client/src/store.js b/client/src/store.js index f155023..5b37dcb 100644 --- a/client/src/store.js +++ b/client/src/store.js @@ -1,5 +1,6 @@ const store = { searchResults: [], - apiBase: 'http://localhost:5000' + apiBase: 'http://localhost:5000', + authApiBase: 'http://localhost:5050' }; export default store; From 17ddf86976c6ac167264d2bc054d3ec74f14ac07 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 23 Mar 2019 13:16:12 -0700 Subject: [PATCH 4/7] Sign Up --- client/src/App.js | 5 +- client/src/views/Login.js | 4 +- client/src/views/SignUp.js | 126 +++++++++++++++++++++++++------------ 3 files changed, 93 insertions(+), 42 deletions(-) diff --git a/client/src/App.js b/client/src/App.js index d6331d3..ac477c9 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -107,7 +107,10 @@ class App extends Component { }; render() { - registerUser("asdf@asd2f.asdfasdf", "Aasdf", undefined, undefined) + const { + searchKeywords, selectedCategories, selectedIndustries, minSalary, + } = this.state; + return (
(
@@ -32,4 +32,4 @@ const LoginForm = () => (
) -export default LoginForm; \ No newline at end of file +export default LoginForm; diff --git a/client/src/views/SignUp.js b/client/src/views/SignUp.js index 6954a40..d94dd35 100644 --- a/client/src/views/SignUp.js +++ b/client/src/views/SignUp.js @@ -1,43 +1,91 @@ -import React from 'react'; +import React, {Component} from 'react'; import '../sass/LoginSignup.scss'; import { Button, Form, Grid, Header, Message, Segment } from 'semantic-ui-react'; +import registerUser from '../backendCalls/auth/registerUser.js'; -const SignUpForm = () => ( -
- - -
- Sign up -
-
- - - - - - - -
- - Already a member? Log in - -
-
-
-) +class SignUpForm extends Component { + constructor(props) { + super(props); + this.state = { + formData: new Map([ + ['username', ''], + ['email', ''], + ['password', ''], + ['repeatPassword', ''] + ]), + result: '' + }; + } -export default SignUpForm; \ No newline at end of file + handleDataChange = (e, item) => { + let newData = this.state.formData; + newData[item] = e.target.value; + this.setState({formData: newData}); + }; + + handleSubmit = async(e) => { + let data = this.state.formData; + if (data['password'] !== data['repeatPassword']) { + this.setState({result: Passwords do not match}) + + } else { + let response = await registerUser(data['email'], data['password'], data['username'], undefined); + let responseHTML = ''; + if (response == 200) { + responseHTML = 'Account successfully created'; + } else { + responseHTML = {response} ; + } + this.setState({result: responseHTML}); + } + }; + + render() { + return ( +
+ + +
+ Sign up +
+
+ + this.handleDataChange(e, 'username')}/> + this.handleDataChange(e, 'email')}/> + this.handleDataChange(e, 'password')} + /> + this.handleDataChange(e, 'repeatPassword')} + /> + + +
+

+ {this.state.result} +

+ + Already a member? Log in + +
+
+
+ ) + } +} + +export default SignUpForm; From 378ada8f9e0ecc3c6c146b4d82af758453d137db Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 23 Mar 2019 15:00:16 -0700 Subject: [PATCH 5/7] Implement login --- client/src/backendCalls/auth/userLogin.js | 2 + client/src/views/Login.js | 106 ++++++++++++++++------ client/src/views/SignUp.js | 18 +++- 3 files changed, 94 insertions(+), 32 deletions(-) diff --git a/client/src/backendCalls/auth/userLogin.js b/client/src/backendCalls/auth/userLogin.js index 753084a..02fcfab 100644 --- a/client/src/backendCalls/auth/userLogin.js +++ b/client/src/backendCalls/auth/userLogin.js @@ -19,6 +19,7 @@ export async function userLogin(email, password) { const response = await fetch(store.authApiBase + '/user/login', { method: 'POST', + mode: 'cors', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, @@ -33,6 +34,7 @@ export async function userLogin(email, password) { return body.error; } else { + document.cookie = body.token; return JSON.stringify(body); } } else { diff --git a/client/src/views/Login.js b/client/src/views/Login.js index 87bc62c..e6f8991 100644 --- a/client/src/views/Login.js +++ b/client/src/views/Login.js @@ -1,35 +1,81 @@ -import React from 'react'; +import React, {Component} from 'react'; import '../sass/LoginSignup.scss'; import { Button, Form, Grid, Header, Message, Segment } from 'semantic-ui-react'; import userLogin from '../backendCalls/auth/userLogin.js'; -const LoginForm = () => ( -
- - -
- Log in -
-
- - - - - -
- - Don't have an Account? Sign Up - -
-
-
-) +class LoginForm extends Component { + constructor(props) { + super(props); + this.state = { + formData: new Map([ + ['email', ''], + ['password', ''], + ]), + result: '' + }; + } + + handleDataChange = (e, item) => { + let newData = this.state.formData; + newData[item] = e.target.value; + this.setState({formData: newData}); + }; + + handleSubmit = async(e) => { + let data = this.state.formData; + let response = await userLogin(data['email'], data['password']); + let responseHTML = ''; + try { + // If the login failed, the next line will fail to parse response + let JSONresponse = JSON.parse(response); + responseHTML = 'Logged in successfully'; + } catch { + // If the login failed, response will be a string describing the failure + responseHTML = {response} ; + } + this.setState({result: responseHTML}); + }; + + render() { + return ( +
+ + +
+ Log in +
+
+ + this.handleDataChange(e, 'email')} + /> + this.handleDataChange(e, 'password')} + /> + + +
+

+ {this.state.result} +

+ + Don't have an Account? Sign Up + +
+
+
+ ) + } +} export default LoginForm; diff --git a/client/src/views/SignUp.js b/client/src/views/SignUp.js index d94dd35..2b9fe27 100644 --- a/client/src/views/SignUp.js +++ b/client/src/views/SignUp.js @@ -50,8 +50,22 @@ class SignUpForm extends Component {
- this.handleDataChange(e, 'username')}/> - this.handleDataChange(e, 'email')}/> + this.handleDataChange(e, 'username')} + /> + this.handleDataChange(e, 'email')} + /> Date: Sat, 23 Mar 2019 15:09:02 -0700 Subject: [PATCH 6/7] Remove merge conflict files --- client/src/App.js.orig | 152 --------------------------------- client/src/App_BACKUP_30193.js | 148 -------------------------------- client/src/App_BACKUP_30298.js | 148 -------------------------------- client/src/App_BASE_30193.js | 87 ------------------- client/src/App_BASE_30298.js | 87 ------------------- client/src/App_LOCAL_30193.js | 88 ------------------- client/src/App_LOCAL_30298.js | 88 ------------------- client/src/App_REMOTE_30193.js | 139 ------------------------------ client/src/App_REMOTE_30298.js | 139 ------------------------------ client/src/store.js | 2 +- client/src/views/SignUp.js | 2 +- 11 files changed, 2 insertions(+), 1078 deletions(-) delete mode 100644 client/src/App.js.orig delete mode 100644 client/src/App_BACKUP_30193.js delete mode 100644 client/src/App_BACKUP_30298.js delete mode 100644 client/src/App_BASE_30193.js delete mode 100644 client/src/App_BASE_30298.js delete mode 100644 client/src/App_LOCAL_30193.js delete mode 100644 client/src/App_LOCAL_30298.js delete mode 100644 client/src/App_REMOTE_30193.js delete mode 100644 client/src/App_REMOTE_30298.js diff --git a/client/src/App.js.orig b/client/src/App.js.orig deleted file mode 100644 index 127ba6d..0000000 --- a/client/src/App.js.orig +++ /dev/null @@ -1,152 +0,0 @@ -import React, { Component } from 'react'; -import { withRouter } from 'react-router-dom'; -import Navbar from './views/Navbar'; -import Footer from './views/Footer'; -import Routes from './config/Routes'; -<<<<<<< HEAD -import { searchJobs } from './backendCalls/searchEndpoints.js'; -import registerUser from './backendCalls/auth/registerUser.js' -||||||| merged common ancestors -import { searchJobs } from './backendCalls/searchEndpoints.js'; - -======= -import { searchJobs } from './backendCalls/searchEndpoints'; - ->>>>>>> develop -class App extends Component { - constructor(props, context) { - super(props, context); - - this.state = { - searchKeywords: '', - latitude: 0.0, - longitude: 0.0, - selectedCategories: [], - selectedIndustries: [], - minSalary: 0, - }; - } - - updateSearchKeywords = (event) => { - this.setState({ searchKeywords: event.target.value }); - }; - - handleAddCategory = (category) => () => { - this.setState((prevState) => ({ - selectedCategories: prevState.selectedCategories.includes(category) - ? [...prevState.selectedCategories] - : [...prevState.selectedCategories, category], - })); - }; - - handleAddIndustry = (industry) => () => { - this.setState((prevState) => ({ - selectedIndustries: prevState.selectedIndustries.includes(industry) - ? [...prevState.selectedIndustries] - : [...prevState.selectedIndustries, industry], - })); - }; - - handleRemoveCategory = (categoryToRemove) => () => { - this.setState((prevState) => ({ - selectedCategories: prevState.selectedCategories.filter((category) => category !== categoryToRemove), - })); - }; - - handleRemoveIndustry = (industryToRemove) => () => { - this.setState((prevState) => ({ - selectedIndustries: prevState.selectedIndustries.filter((industry) => industry !== industryToRemove), - })); - }; - - onChangeLocation = (newLatLng) => { - this.setState({ - latitude: newLatLng.lat, - longitude: newLatLng.lng, - }); - }; - - handleAddMinSalary = async (newSalary) => { - await this.setState({ - minSalary: newSalary, - }); - this.handleSearch(); - }; - - handleRemoveMinSalary = async () => { - await this.setState({ - minSalary: 0, - }); - this.handleSearch(); - }; - - handleClearFilters = async () => { - await this.setState({ - minSalary: 0, - selectedCategories: [], - selectedIndustries: [], - }); - this.handleSearch(); - }; - - // construct the JSON body of the search request - constructBody = (searchKeywords) => { - const body = { - keywords: searchKeywords, - }; - - if (this.state.minSalary) { - body.salaryMin = this.state.minSalary; - } - - if (this.state.latitude && this.state.longitude) { - body.latitude = this.state.latitude; - body.longitude = this.state.longitude; - // TODO: let user choose radius - body.radius = 50; - } - return JSON.stringify(body); - }; - - handleSearch = async () => { - const keywords = this.constructBody(this.state.searchKeywords); - await searchJobs(keywords); - this.props.history.push('/results'); - }; - - render() { -<<<<<<< HEAD - registerUser("asdf@asd2f.asdfasdf", "Aasdf", undefined, undefined) -||||||| merged common ancestors -======= - const { - searchKeywords, selectedCategories, selectedIndustries, minSalary, - } = this.state; - ->>>>>>> develop - return ( -
- - -
-
- ); - } -} - -export default withRouter(App); diff --git a/client/src/App_BACKUP_30193.js b/client/src/App_BACKUP_30193.js deleted file mode 100644 index 064c2b0..0000000 --- a/client/src/App_BACKUP_30193.js +++ /dev/null @@ -1,148 +0,0 @@ -import React, { Component } from 'react'; -import { withRouter } from 'react-router-dom'; -import Navbar from './views/Navbar'; -import Footer from './views/Footer'; -import Routes from './config/Routes'; -<<<<<<< HEAD -import { searchJobs } from './backendCalls/searchEndpoints.js'; -import registerUser from './backendCalls/auth/registerUser.js' -======= -import { searchJobs } from './backendCalls/searchEndpoints'; - ->>>>>>> develop -class App extends Component { - constructor(props, context) { - super(props, context); - - this.state = { - searchKeywords: '', - latitude: 0.0, - longitude: 0.0, - selectedCategories: [], - selectedIndustries: [], - minSalary: 0, - }; - } - - updateSearchKeywords = (event) => { - this.setState({ searchKeywords: event.target.value }); - }; - - handleAddCategory = (category) => () => { - this.setState((prevState) => ({ - selectedCategories: prevState.selectedCategories.includes(category) - ? [...prevState.selectedCategories] - : [...prevState.selectedCategories, category], - })); - }; - - handleAddIndustry = (industry) => () => { - this.setState((prevState) => ({ - selectedIndustries: prevState.selectedIndustries.includes(industry) - ? [...prevState.selectedIndustries] - : [...prevState.selectedIndustries, industry], - })); - }; - - handleRemoveCategory = (categoryToRemove) => () => { - this.setState((prevState) => ({ - selectedCategories: prevState.selectedCategories.filter((category) => category !== categoryToRemove), - })); - }; - - handleRemoveIndustry = (industryToRemove) => () => { - this.setState((prevState) => ({ - selectedIndustries: prevState.selectedIndustries.filter((industry) => industry !== industryToRemove), - })); - }; - - onChangeLocation = (newLatLng) => { - this.setState({ - latitude: newLatLng.lat, - longitude: newLatLng.lng, - }); - }; - - handleAddMinSalary = async (newSalary) => { - await this.setState({ - minSalary: newSalary, - }); - this.handleSearch(); - }; - - handleRemoveMinSalary = async () => { - await this.setState({ - minSalary: 0, - }); - this.handleSearch(); - }; - - handleClearFilters = async () => { - await this.setState({ - minSalary: 0, - selectedCategories: [], - selectedIndustries: [], - }); - this.handleSearch(); - }; - - // construct the JSON body of the search request - constructBody = (searchKeywords) => { - const body = { - keywords: searchKeywords, - }; - - if (this.state.minSalary) { - body.salaryMin = this.state.minSalary; - } - - if (this.state.latitude && this.state.longitude) { - body.latitude = this.state.latitude; - body.longitude = this.state.longitude; - // TODO: let user choose radius - body.radius = 50; - } - return JSON.stringify(body); - }; - - handleSearch = async () => { - const keywords = this.constructBody(this.state.searchKeywords); - await searchJobs(keywords); - this.props.history.push('/results'); - }; - - render() { -<<<<<<< HEAD - registerUser("asdf@asdf.asdfasdf", "Aasdf", undefined, undefined) -======= - const { - searchKeywords, selectedCategories, selectedIndustries, minSalary, - } = this.state; - ->>>>>>> develop - return ( -
- - -
-
- ); - } -} - -export default withRouter(App); diff --git a/client/src/App_BACKUP_30298.js b/client/src/App_BACKUP_30298.js deleted file mode 100644 index 064c2b0..0000000 --- a/client/src/App_BACKUP_30298.js +++ /dev/null @@ -1,148 +0,0 @@ -import React, { Component } from 'react'; -import { withRouter } from 'react-router-dom'; -import Navbar from './views/Navbar'; -import Footer from './views/Footer'; -import Routes from './config/Routes'; -<<<<<<< HEAD -import { searchJobs } from './backendCalls/searchEndpoints.js'; -import registerUser from './backendCalls/auth/registerUser.js' -======= -import { searchJobs } from './backendCalls/searchEndpoints'; - ->>>>>>> develop -class App extends Component { - constructor(props, context) { - super(props, context); - - this.state = { - searchKeywords: '', - latitude: 0.0, - longitude: 0.0, - selectedCategories: [], - selectedIndustries: [], - minSalary: 0, - }; - } - - updateSearchKeywords = (event) => { - this.setState({ searchKeywords: event.target.value }); - }; - - handleAddCategory = (category) => () => { - this.setState((prevState) => ({ - selectedCategories: prevState.selectedCategories.includes(category) - ? [...prevState.selectedCategories] - : [...prevState.selectedCategories, category], - })); - }; - - handleAddIndustry = (industry) => () => { - this.setState((prevState) => ({ - selectedIndustries: prevState.selectedIndustries.includes(industry) - ? [...prevState.selectedIndustries] - : [...prevState.selectedIndustries, industry], - })); - }; - - handleRemoveCategory = (categoryToRemove) => () => { - this.setState((prevState) => ({ - selectedCategories: prevState.selectedCategories.filter((category) => category !== categoryToRemove), - })); - }; - - handleRemoveIndustry = (industryToRemove) => () => { - this.setState((prevState) => ({ - selectedIndustries: prevState.selectedIndustries.filter((industry) => industry !== industryToRemove), - })); - }; - - onChangeLocation = (newLatLng) => { - this.setState({ - latitude: newLatLng.lat, - longitude: newLatLng.lng, - }); - }; - - handleAddMinSalary = async (newSalary) => { - await this.setState({ - minSalary: newSalary, - }); - this.handleSearch(); - }; - - handleRemoveMinSalary = async () => { - await this.setState({ - minSalary: 0, - }); - this.handleSearch(); - }; - - handleClearFilters = async () => { - await this.setState({ - minSalary: 0, - selectedCategories: [], - selectedIndustries: [], - }); - this.handleSearch(); - }; - - // construct the JSON body of the search request - constructBody = (searchKeywords) => { - const body = { - keywords: searchKeywords, - }; - - if (this.state.minSalary) { - body.salaryMin = this.state.minSalary; - } - - if (this.state.latitude && this.state.longitude) { - body.latitude = this.state.latitude; - body.longitude = this.state.longitude; - // TODO: let user choose radius - body.radius = 50; - } - return JSON.stringify(body); - }; - - handleSearch = async () => { - const keywords = this.constructBody(this.state.searchKeywords); - await searchJobs(keywords); - this.props.history.push('/results'); - }; - - render() { -<<<<<<< HEAD - registerUser("asdf@asdf.asdfasdf", "Aasdf", undefined, undefined) -======= - const { - searchKeywords, selectedCategories, selectedIndustries, minSalary, - } = this.state; - ->>>>>>> develop - return ( -
- - -
-
- ); - } -} - -export default withRouter(App); diff --git a/client/src/App_BASE_30193.js b/client/src/App_BASE_30193.js deleted file mode 100644 index 319bc59..0000000 --- a/client/src/App_BASE_30193.js +++ /dev/null @@ -1,87 +0,0 @@ -import React, { Component } from 'react'; -import { withRouter } from 'react-router-dom'; -import './sass/ResultsTable.scss'; -import Navbar from './views/Navbar'; -import Footer from './views/Footer'; -import FilterMenu from './components/FilterMenu'; -import Routes from './config/Routes'; -import { searchJobs } from './backendCalls/searchEndpoints.js'; - -class App extends Component { - constructor(props, context) { - super(props, context); - - this.state = { - data: [], - isFilterMenuVisible: false, - latitude: 0.0, - longitude: 0.0, - categories: [], - industries: [], - salary: 0, - }; - } - - toggleFilterVisibility = () => { - this.setState(prevState => ({ - isFilterMenuVisible: !prevState.isFilterMenuVisible, - })); - }; - - onChangeLocation = (newLatLng) => { - this.setState({ - latitude: newLatLng.lat, - longitude: newLatLng.lng, - }); - } - - onChangeMinSalary = (newSalary) => { - this.setState({ - salary: newSalary, - }); - } - - // construct the JSON body of the search request - constructBody = (searchKeywords) => { - const body = { - keywords: searchKeywords, - }; - if (this.state.salary) { - body.salaryMin = this.state.salary; - } - - if (this.state.latitude && this.state.longitude) { - body.latitude = this.state.latitude; - body.longitude = this.state.longitude; - // TODO: let user choose radius - body.radius = 50; - } - return JSON.stringify(body); - } - - searchHandler = (searchKeywords) => async() => { - var keywords = this.constructBody(searchKeywords); - await searchJobs(keywords); - this.props.history.push('/results'); - } - - render() { - return ( -
- - {this.state.isFilterMenuVisible ? - } - - -
-
- ); - } -} - -export default withRouter(App); diff --git a/client/src/App_BASE_30298.js b/client/src/App_BASE_30298.js deleted file mode 100644 index 319bc59..0000000 --- a/client/src/App_BASE_30298.js +++ /dev/null @@ -1,87 +0,0 @@ -import React, { Component } from 'react'; -import { withRouter } from 'react-router-dom'; -import './sass/ResultsTable.scss'; -import Navbar from './views/Navbar'; -import Footer from './views/Footer'; -import FilterMenu from './components/FilterMenu'; -import Routes from './config/Routes'; -import { searchJobs } from './backendCalls/searchEndpoints.js'; - -class App extends Component { - constructor(props, context) { - super(props, context); - - this.state = { - data: [], - isFilterMenuVisible: false, - latitude: 0.0, - longitude: 0.0, - categories: [], - industries: [], - salary: 0, - }; - } - - toggleFilterVisibility = () => { - this.setState(prevState => ({ - isFilterMenuVisible: !prevState.isFilterMenuVisible, - })); - }; - - onChangeLocation = (newLatLng) => { - this.setState({ - latitude: newLatLng.lat, - longitude: newLatLng.lng, - }); - } - - onChangeMinSalary = (newSalary) => { - this.setState({ - salary: newSalary, - }); - } - - // construct the JSON body of the search request - constructBody = (searchKeywords) => { - const body = { - keywords: searchKeywords, - }; - if (this.state.salary) { - body.salaryMin = this.state.salary; - } - - if (this.state.latitude && this.state.longitude) { - body.latitude = this.state.latitude; - body.longitude = this.state.longitude; - // TODO: let user choose radius - body.radius = 50; - } - return JSON.stringify(body); - } - - searchHandler = (searchKeywords) => async() => { - var keywords = this.constructBody(searchKeywords); - await searchJobs(keywords); - this.props.history.push('/results'); - } - - render() { - return ( -
- - {this.state.isFilterMenuVisible ? - } - - -
-
- ); - } -} - -export default withRouter(App); diff --git a/client/src/App_LOCAL_30193.js b/client/src/App_LOCAL_30193.js deleted file mode 100644 index fd5b6dc..0000000 --- a/client/src/App_LOCAL_30193.js +++ /dev/null @@ -1,88 +0,0 @@ -import React, { Component } from 'react'; -import { withRouter } from 'react-router-dom'; -import './sass/ResultsTable.scss'; -import Navbar from './views/Navbar'; -import Footer from './views/Footer'; -import FilterMenu from './components/FilterMenu'; -import Routes from './config/Routes'; -import { searchJobs } from './backendCalls/searchEndpoints.js'; -import registerUser from './backendCalls/auth/registerUser.js' -class App extends Component { - constructor(props, context) { - super(props, context); - - this.state = { - data: [], - isFilterMenuVisible: false, - latitude: 0.0, - longitude: 0.0, - categories: [], - industries: [], - salary: 0, - }; - } - - toggleFilterVisibility = () => { - this.setState(prevState => ({ - isFilterMenuVisible: !prevState.isFilterMenuVisible, - })); - }; - - onChangeLocation = (newLatLng) => { - this.setState({ - latitude: newLatLng.lat, - longitude: newLatLng.lng, - }); - } - - onChangeMinSalary = (newSalary) => { - this.setState({ - salary: newSalary, - }); - } - - // construct the JSON body of the search request - constructBody = (searchKeywords) => { - const body = { - keywords: searchKeywords, - }; - if (this.state.salary) { - body.salaryMin = this.state.salary; - } - - if (this.state.latitude && this.state.longitude) { - body.latitude = this.state.latitude; - body.longitude = this.state.longitude; - // TODO: let user choose radius - body.radius = 50; - } - return JSON.stringify(body); - } - - searchHandler = (searchKeywords) => async() => { - var keywords = this.constructBody(searchKeywords); - await searchJobs(keywords); - this.props.history.push('/results'); - } - - render() { - registerUser("asdf@asdf.asdfasdf", "Aasdf", undefined, undefined) - return ( -
- - {this.state.isFilterMenuVisible ? - } - - -
-
- ); - } -} - -export default withRouter(App); diff --git a/client/src/App_LOCAL_30298.js b/client/src/App_LOCAL_30298.js deleted file mode 100644 index fd5b6dc..0000000 --- a/client/src/App_LOCAL_30298.js +++ /dev/null @@ -1,88 +0,0 @@ -import React, { Component } from 'react'; -import { withRouter } from 'react-router-dom'; -import './sass/ResultsTable.scss'; -import Navbar from './views/Navbar'; -import Footer from './views/Footer'; -import FilterMenu from './components/FilterMenu'; -import Routes from './config/Routes'; -import { searchJobs } from './backendCalls/searchEndpoints.js'; -import registerUser from './backendCalls/auth/registerUser.js' -class App extends Component { - constructor(props, context) { - super(props, context); - - this.state = { - data: [], - isFilterMenuVisible: false, - latitude: 0.0, - longitude: 0.0, - categories: [], - industries: [], - salary: 0, - }; - } - - toggleFilterVisibility = () => { - this.setState(prevState => ({ - isFilterMenuVisible: !prevState.isFilterMenuVisible, - })); - }; - - onChangeLocation = (newLatLng) => { - this.setState({ - latitude: newLatLng.lat, - longitude: newLatLng.lng, - }); - } - - onChangeMinSalary = (newSalary) => { - this.setState({ - salary: newSalary, - }); - } - - // construct the JSON body of the search request - constructBody = (searchKeywords) => { - const body = { - keywords: searchKeywords, - }; - if (this.state.salary) { - body.salaryMin = this.state.salary; - } - - if (this.state.latitude && this.state.longitude) { - body.latitude = this.state.latitude; - body.longitude = this.state.longitude; - // TODO: let user choose radius - body.radius = 50; - } - return JSON.stringify(body); - } - - searchHandler = (searchKeywords) => async() => { - var keywords = this.constructBody(searchKeywords); - await searchJobs(keywords); - this.props.history.push('/results'); - } - - render() { - registerUser("asdf@asdf.asdfasdf", "Aasdf", undefined, undefined) - return ( -
- - {this.state.isFilterMenuVisible ? - } - - -
-
- ); - } -} - -export default withRouter(App); diff --git a/client/src/App_REMOTE_30193.js b/client/src/App_REMOTE_30193.js deleted file mode 100644 index ac477c9..0000000 --- a/client/src/App_REMOTE_30193.js +++ /dev/null @@ -1,139 +0,0 @@ -import React, { Component } from 'react'; -import { withRouter } from 'react-router-dom'; -import Navbar from './views/Navbar'; -import Footer from './views/Footer'; -import Routes from './config/Routes'; -import { searchJobs } from './backendCalls/searchEndpoints'; - -class App extends Component { - constructor(props, context) { - super(props, context); - - this.state = { - searchKeywords: '', - latitude: 0.0, - longitude: 0.0, - selectedCategories: [], - selectedIndustries: [], - minSalary: 0, - }; - } - - updateSearchKeywords = (event) => { - this.setState({ searchKeywords: event.target.value }); - }; - - handleAddCategory = (category) => () => { - this.setState((prevState) => ({ - selectedCategories: prevState.selectedCategories.includes(category) - ? [...prevState.selectedCategories] - : [...prevState.selectedCategories, category], - })); - }; - - handleAddIndustry = (industry) => () => { - this.setState((prevState) => ({ - selectedIndustries: prevState.selectedIndustries.includes(industry) - ? [...prevState.selectedIndustries] - : [...prevState.selectedIndustries, industry], - })); - }; - - handleRemoveCategory = (categoryToRemove) => () => { - this.setState((prevState) => ({ - selectedCategories: prevState.selectedCategories.filter((category) => category !== categoryToRemove), - })); - }; - - handleRemoveIndustry = (industryToRemove) => () => { - this.setState((prevState) => ({ - selectedIndustries: prevState.selectedIndustries.filter((industry) => industry !== industryToRemove), - })); - }; - - onChangeLocation = (newLatLng) => { - this.setState({ - latitude: newLatLng.lat, - longitude: newLatLng.lng, - }); - }; - - handleAddMinSalary = async (newSalary) => { - await this.setState({ - minSalary: newSalary, - }); - this.handleSearch(); - }; - - handleRemoveMinSalary = async () => { - await this.setState({ - minSalary: 0, - }); - this.handleSearch(); - }; - - handleClearFilters = async () => { - await this.setState({ - minSalary: 0, - selectedCategories: [], - selectedIndustries: [], - }); - this.handleSearch(); - }; - - // construct the JSON body of the search request - constructBody = (searchKeywords) => { - const body = { - keywords: searchKeywords, - }; - - if (this.state.minSalary) { - body.salaryMin = this.state.minSalary; - } - - if (this.state.latitude && this.state.longitude) { - body.latitude = this.state.latitude; - body.longitude = this.state.longitude; - // TODO: let user choose radius - body.radius = 50; - } - return JSON.stringify(body); - }; - - handleSearch = async () => { - const keywords = this.constructBody(this.state.searchKeywords); - await searchJobs(keywords); - this.props.history.push('/results'); - }; - - render() { - const { - searchKeywords, selectedCategories, selectedIndustries, minSalary, - } = this.state; - - return ( -
- - -
-
- ); - } -} - -export default withRouter(App); diff --git a/client/src/App_REMOTE_30298.js b/client/src/App_REMOTE_30298.js deleted file mode 100644 index ac477c9..0000000 --- a/client/src/App_REMOTE_30298.js +++ /dev/null @@ -1,139 +0,0 @@ -import React, { Component } from 'react'; -import { withRouter } from 'react-router-dom'; -import Navbar from './views/Navbar'; -import Footer from './views/Footer'; -import Routes from './config/Routes'; -import { searchJobs } from './backendCalls/searchEndpoints'; - -class App extends Component { - constructor(props, context) { - super(props, context); - - this.state = { - searchKeywords: '', - latitude: 0.0, - longitude: 0.0, - selectedCategories: [], - selectedIndustries: [], - minSalary: 0, - }; - } - - updateSearchKeywords = (event) => { - this.setState({ searchKeywords: event.target.value }); - }; - - handleAddCategory = (category) => () => { - this.setState((prevState) => ({ - selectedCategories: prevState.selectedCategories.includes(category) - ? [...prevState.selectedCategories] - : [...prevState.selectedCategories, category], - })); - }; - - handleAddIndustry = (industry) => () => { - this.setState((prevState) => ({ - selectedIndustries: prevState.selectedIndustries.includes(industry) - ? [...prevState.selectedIndustries] - : [...prevState.selectedIndustries, industry], - })); - }; - - handleRemoveCategory = (categoryToRemove) => () => { - this.setState((prevState) => ({ - selectedCategories: prevState.selectedCategories.filter((category) => category !== categoryToRemove), - })); - }; - - handleRemoveIndustry = (industryToRemove) => () => { - this.setState((prevState) => ({ - selectedIndustries: prevState.selectedIndustries.filter((industry) => industry !== industryToRemove), - })); - }; - - onChangeLocation = (newLatLng) => { - this.setState({ - latitude: newLatLng.lat, - longitude: newLatLng.lng, - }); - }; - - handleAddMinSalary = async (newSalary) => { - await this.setState({ - minSalary: newSalary, - }); - this.handleSearch(); - }; - - handleRemoveMinSalary = async () => { - await this.setState({ - minSalary: 0, - }); - this.handleSearch(); - }; - - handleClearFilters = async () => { - await this.setState({ - minSalary: 0, - selectedCategories: [], - selectedIndustries: [], - }); - this.handleSearch(); - }; - - // construct the JSON body of the search request - constructBody = (searchKeywords) => { - const body = { - keywords: searchKeywords, - }; - - if (this.state.minSalary) { - body.salaryMin = this.state.minSalary; - } - - if (this.state.latitude && this.state.longitude) { - body.latitude = this.state.latitude; - body.longitude = this.state.longitude; - // TODO: let user choose radius - body.radius = 50; - } - return JSON.stringify(body); - }; - - handleSearch = async () => { - const keywords = this.constructBody(this.state.searchKeywords); - await searchJobs(keywords); - this.props.history.push('/results'); - }; - - render() { - const { - searchKeywords, selectedCategories, selectedIndustries, minSalary, - } = this.state; - - return ( -
- - -
-
- ); - } -} - -export default withRouter(App); diff --git a/client/src/store.js b/client/src/store.js index 5b37dcb..5c45318 100644 --- a/client/src/store.js +++ b/client/src/store.js @@ -1,6 +1,6 @@ const store = { searchResults: [], - apiBase: 'http://localhost:5000', + apiBase: 'https://internado.ubclaunchpad.com', authApiBase: 'http://localhost:5050' }; export default store; diff --git a/client/src/views/SignUp.js b/client/src/views/SignUp.js index 2b9fe27..f3273e9 100644 --- a/client/src/views/SignUp.js +++ b/client/src/views/SignUp.js @@ -31,7 +31,7 @@ class SignUpForm extends Component { } else { let response = await registerUser(data['email'], data['password'], data['username'], undefined); let responseHTML = ''; - if (response == 200) { + if (response === 200) { responseHTML = 'Account successfully created'; } else { responseHTML = {response} ; From 94ddc527d7a78de93a088ee6529748b8eedfcafd Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 30 Mar 2019 11:53:15 -0700 Subject: [PATCH 7/7] Remove unused variable --- client/src/views/Login.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/views/Login.js b/client/src/views/Login.js index e6f8991..abed97c 100644 --- a/client/src/views/Login.js +++ b/client/src/views/Login.js @@ -26,7 +26,7 @@ class LoginForm extends Component { let responseHTML = ''; try { // If the login failed, the next line will fail to parse response - let JSONresponse = JSON.parse(response); + JSON.parse(response); responseHTML = 'Logged in successfully'; } catch { // If the login failed, response will be a string describing the failure