Skip to content
This repository has been archived by the owner on Jul 12, 2019. It is now read-only.

Commit

Permalink
More cookies (#67)
Browse files Browse the repository at this point in the history
* Fixed issues with cookies being passed between components

* Fixed company authentication creation bug. Made cookies work for loading company specific dashboard
  • Loading branch information
lipovac authored and eigenfoo committed Apr 18, 2019
1 parent a7c3c54 commit ff258f3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
14 changes: 7 additions & 7 deletions euphoria-frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ class App extends Component {
<div>
<Switch>
<Route exact path="/" component={Splash} />
<Route path="/signin" render={(props) => (<Signin {...props} />)} />
<Route path="/signin" render={(props) => (<Signin cookies={this.props.cookies} {...props} />)} />
<Route path="/signup" component={Signup} />
<Route exact path="/postings" render={(props) => (<Postings {...props} />)} />
<Route path="/postings/apply/:postingId" render={(props) => (<Apply {...props} />)} />
<Route exact path="/dashboard" render={(props) => (<Dashboard {...props} />)} />
<Route exact path="/dashboard/post" render={(props) => (<Post {...props} />)} />
<Route path="/dashboard/post/edit/:postingId" render={(props) => (<Editpost {...props} />)} />
<Route path="/dashboard/applications/:postingId" render={(props) => (<Applications {...props} />)} />
<Route exact path="/postings" render={(props) => (<Postings cookies={this.props.cookies} {...props} />)} />
<Route path="/postings/apply/:postingId" render={(props) => (<Apply cookies={this.props.cookies} {...props} />)} />
<Route exact path="/dashboard" render={(props) => (<Dashboard cookies={this.props.cookies} {...props} />)} />
<Route exact path="/dashboard/post" render={(props) => (<Post cookies={this.props.cookies} {...props} />)} />
<Route path="/dashboard/post/edit/:postingId" render={(props) => (<Editpost cookies={this.props.cookies} {...props} />)} />
<Route path="/dashboard/applications/:postingId" render={(props) => (<Applications cookies={this.props.cookies} {...props} />)} />
<Route path="/404" component={NotFound} />
<Redirect to="/404" />
</Switch>
Expand Down
4 changes: 2 additions & 2 deletions euphoria-frontend/src/views/Apply.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Apply extends Component {

componentDidMount() {
let url = "http://localhost:8080/api/posting/" + this.props.match.params.postingId;
console.log(this.props);

this.handleGet(url);
}

Expand Down Expand Up @@ -110,7 +110,7 @@ class Apply extends Component {
<Image
src={require('../images/Logo.png')}
fluid
onClick={() => this.handleRedirect("/posting")}
onClick={() => this.handleRedirect("/postings")}
/>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion euphoria-frontend/src/views/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Dashboard extends Component {
constructor(props, context) {
super(props);

this.dashboardUrl = "http://localhost:8080/api/posting/company/" + this.props.cookies.get("id");
this.dashboardUrl = "http://localhost:8080/api/posting/company/" + this.props.cookies.get("id")

this.state = {
companyPostingsData: [],
Expand Down
14 changes: 7 additions & 7 deletions euphoria-frontend/src/views/Signin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ class Signin extends Component {
.then(data => {
const cookie = data[0];

if(cookie != null){
const cookies = this.props.cookies;
if(!(cookie == null)){
const cookiesProp = this.props.cookies;

cookies.set("username", username, { path: '/' });
cookies.set("id", cookies.id, { path: '/' });
cookies.set("isUser", cookies.isUser, { path: '/' });
cookies.set("authenticationHash", cookie.cookie, { path: '/' });
cookiesProp.set("username", username, { path: '/' });
cookiesProp.set("id", cookie.id, { path: '/' });
cookiesProp.set("isUser", cookie.isUser, { path: '/' });
cookiesProp.set("authenticationHash", cookie.cookie, { path: '/' });

if(cookies.isUser){
if(cookie.isUser){
this.handleRedirect("/postings")
}
else{
Expand Down
13 changes: 9 additions & 4 deletions euphoria-frontend/src/views/Signup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,24 @@ class Signup extends Component {
website,
description
};
console.log(userPayload)
}

fetch(userUrl, {
method: "POST",
body: JSON.stringify(userPayload)
}) //FIXME add check for is user exists
.then(response => response.json())
.then(data => this.createUserAuthentication(data[0].userId))
.then(data => {
this.createUserAuthentication((isUser) ? data[0].userId : data[0].companyId)
})
.catch(err => {
})

return;
}

createUserAuthentication(userId) {
createUserAuthentication(id) {
const {
isUser,
username,
Expand All @@ -118,12 +121,14 @@ class Signup extends Component {
const authenticationUrl = "http://localhost:8080/api/authentication";

let authenticationPayload = {
id: userId,
id: id,
username: username,
passwordHash: password,
isUser: isUser
};

console.log(authenticationPayload);

fetch(authenticationUrl, {
method: "POST",
body: JSON.stringify(authenticationPayload)
Expand Down Expand Up @@ -234,7 +239,7 @@ class Signup extends Component {
</Form.Group>

<Form.Group controlId="formGridWebsite">
<Form.Label>Email</Form.Label>
<Form.Label>Website</Form.Label>
<Form.Control
required
type="website"
Expand Down

0 comments on commit ff258f3

Please sign in to comment.