update: login function and purchased item store
This commit is contained in:
@@ -12,16 +12,31 @@ export default class LoginComponent extends React.Component {
|
||||
super(props);
|
||||
this.props = props;
|
||||
this.state = {
|
||||
email: "",
|
||||
username: "",
|
||||
password: "",
|
||||
};
|
||||
this.defaultState = Object.assign({}, this.state);
|
||||
this.authStore = props.appstate.auth;
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
||||
}
|
||||
|
||||
login = () => {
|
||||
const username = this.state.username;
|
||||
const password = this.state.password;
|
||||
const data = {
|
||||
username: username,
|
||||
password: password,
|
||||
}
|
||||
this.authStore.login(data).then(res => {
|
||||
this.props.history.push(LINKS.DASHBOARD);
|
||||
}).catch(err => {
|
||||
alert(err.message);
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
|
||||
return (
|
||||
@@ -35,15 +50,17 @@ export default class LoginComponent extends React.Component {
|
||||
<input
|
||||
className={'usernameForm'}
|
||||
placeholder="Username"
|
||||
onChange={(e) => this.setState({username: e.target.value})}
|
||||
/>
|
||||
<input
|
||||
className={'passwordForm'}
|
||||
placeholder="Password"
|
||||
onChange={(e) => this.setState({password: e.target.value})}
|
||||
type="password"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button onClick={() => this.props.history.push(LINKS.DASHBOARD)} className={'buttonLogin'}>
|
||||
<button onClick={() => this.login()} className={'buttonLogin'}>
|
||||
Sign In
|
||||
</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user