Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded Spring Boot to 2.4.x #43

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13,566 changes: 13,538 additions & 28 deletions react-social/package-lock.json

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions react-social/src/user/login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Login extends Component {
componentDidMount() {
// If the OAuth2 login encounters an error, the user is redirected to the /login page with an error.
// Here we display the error and then remove the error query parameter from the location.
if(this.props.location.state && this.props.location.state.error) {
if (this.props.location.state && this.props.location.state.error) {
setTimeout(() => {
Alert.error(this.props.location.state.error, {
timeout: 5000
Expand All @@ -24,14 +24,14 @@ class Login extends Component {
}, 100);
}
}

render() {
if(this.props.authenticated) {
if (this.props.authenticated) {
return <Redirect
to={{
pathname: "/",
state: { from: this.props.location }
}}/>;
pathname: "/",
state: { from: this.props.location }
}} />;
}

return (
Expand Down Expand Up @@ -70,7 +70,7 @@ class LoginForm extends Component {
constructor(props) {
super(props);
this.state = {
email: '',
userName: '',
password: ''
};
this.handleInputChange = this.handleInputChange.bind(this);
Expand All @@ -79,46 +79,46 @@ class LoginForm extends Component {

handleInputChange(event) {
const target = event.target;
const inputName = target.name;
const inputName = target.name;
const inputValue = target.value;

this.setState({
[inputName] : inputValue
});
[inputName]: inputValue
});
}

handleSubmit(event) {
event.preventDefault();
event.preventDefault();

const loginRequest = Object.assign({}, this.state);

login(loginRequest)
.then(response => {
localStorage.setItem(ACCESS_TOKEN, response.accessToken);
Alert.success("You're successfully logged in!");
this.props.history.push("/");
}).catch(error => {
Alert.error((error && error.message) || 'Oops! Something went wrong. Please try again!');
});
.then(response => {
localStorage.setItem(ACCESS_TOKEN, response.accessToken);
Alert.success("You're successfully logged in!");
this.props.history.push("/");
}).catch(error => {
Alert.error((error && error.message) || 'Oops! Something went wrong. Please try again!');
});
}

render() {
return (
<form onSubmit={this.handleSubmit}>
<div className="form-item">
<input type="email" name="email"
className="form-control" placeholder="Email"
value={this.state.email} onChange={this.handleInputChange} required/>
<input name="userName"
className="form-control" placeholder="User Name"
value={this.state.userName} onChange={this.handleInputChange} required />
</div>
<div className="form-item">
<input type="password" name="password"
<input type="password" name="password"
className="form-control" placeholder="Password"
value={this.state.password} onChange={this.handleInputChange} required/>
value={this.state.password} onChange={this.handleInputChange} required />
</div>
<div className="form-item">
<button type="submit" className="btn btn-block btn-primary">Login</button>
</div>
</form>
</form>
);
}
}
Expand Down
46 changes: 20 additions & 26 deletions react-social/src/user/signup/Signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import Alert from 'react-s-alert';

class Signup extends Component {
render() {
if(this.props.authenticated) {
if (this.props.authenticated) {
return <Redirect
to={{
pathname: "/",
state: { from: this.props.location }
}}/>;
pathname: "/",
state: { from: this.props.location }
}} />;
}

return (
Expand Down Expand Up @@ -54,8 +54,7 @@ class SignupForm extends Component {
constructor(props) {
super(props);
this.state = {
name: '',
email: '',
userName: '',
password: ''
}
this.handleInputChange = this.handleInputChange.bind(this);
Expand All @@ -64,50 +63,45 @@ class SignupForm extends Component {

handleInputChange(event) {
const target = event.target;
const inputName = target.name;
const inputName = target.name;
const inputValue = target.value;

this.setState({
[inputName] : inputValue
});
[inputName]: inputValue
});
}

handleSubmit(event) {
event.preventDefault();
event.preventDefault();

const signUpRequest = Object.assign({}, this.state);

signup(signUpRequest)
.then(response => {
Alert.success("You're successfully registered. Please login to continue!");
this.props.history.push("/login");
}).catch(error => {
Alert.error((error && error.message) || 'Oops! Something went wrong. Please try again!');
});
.then(response => {
Alert.success("You're successfully registered. Please login to continue!");
this.props.history.push("/login");
}).catch(error => {
Alert.error((error && error.message) || 'Oops! Something went wrong. Please try again!');
});
}

render() {
return (
<form onSubmit={this.handleSubmit}>
<div className="form-item">
<input type="text" name="name"
<input type="text" name="userName"
className="form-control" placeholder="Name"
value={this.state.name} onChange={this.handleInputChange} required/>
</div>
<div className="form-item">
<input type="email" name="email"
className="form-control" placeholder="Email"
value={this.state.email} onChange={this.handleInputChange} required/>
value={this.state.userName} onChange={this.handleInputChange} required />
</div>
<div className="form-item">
<input type="password" name="password"
<input type="password" name="password"
className="form-control" placeholder="Password"
value={this.state.password} onChange={this.handleInputChange} required/>
value={this.state.password} onChange={this.handleInputChange} required />
</div>
<div className="form-item">
<button type="submit" className="btn btn-block btn-primary" >Sign Up</button>
</div>
</form>
</form>

);
}
Expand Down
30 changes: 15 additions & 15 deletions react-social/src/util/APIUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,47 @@ const request = (options) => {
const headers = new Headers({
'Content-Type': 'application/json',
})
if(localStorage.getItem(ACCESS_TOKEN)) {

if (localStorage.getItem(ACCESS_TOKEN)) {
headers.append('Authorization', 'Bearer ' + localStorage.getItem(ACCESS_TOKEN))
}

const defaults = {headers: headers};
const defaults = { headers: headers };
options = Object.assign({}, defaults, options);

return fetch(options.url, options)
.then(response =>
response.json().then(json => {
if(!response.ok) {
return Promise.reject(json);
}
return json;
})
);
.then(response =>
response.json().then(json => {
if (!response.ok) {
return Promise.reject(json);
}
return json;
})
);
};

export function getCurrentUser() {
if(!localStorage.getItem(ACCESS_TOKEN)) {
if (!localStorage.getItem(ACCESS_TOKEN)) {
return Promise.reject("No access token set.");
}

return request({
url: API_BASE_URL + "/user/me",
url: API_BASE_URL + "/api/auth/me",
method: 'GET'
});
}

export function login(loginRequest) {
return request({
url: API_BASE_URL + "/auth/login",
url: API_BASE_URL + "/api/auth/login",
method: 'POST',
body: JSON.stringify(loginRequest)
});
}

export function signup(signupRequest) {
return request({
url: API_BASE_URL + "/auth/signup",
url: API_BASE_URL + "/api/auth/signup",
method: 'POST',
body: JSON.stringify(signupRequest)
});
Expand Down
Loading