Skip to content
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
48 changes: 21 additions & 27 deletions src/components/Dashboard/LoginPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import loginBackgroundTreeOne from '../../img/login-background-tree-1.png';
import loginBackgroundTreeTwo from '../../img/login-background-tree-2.png';
import loginBackgroundTreeInvertOne from '../../img/login-background-tree-invert-1.png';
import loginBackgroundTreeInvertTwo from '../../img/login-background-tree-invert-2.png';
import axios from 'axios'
import {config} from '../../constants'
import { Redirect } from 'react-router-dom'
import {getToken} from '../../services/hackathon';

class LoginPage extends Component {
state = {
Expand Down Expand Up @@ -50,36 +48,32 @@ class LoginPage extends Component {

handleClick(event){



var apiBaseUrl = config.BASE_URL
const payload={
"email":this.state.username,
"password":this.state.password
}
getToken(payload).then((data) => {
//console.log('token:', data);

axios.post(apiBaseUrl+'/api/v1/account/login/', payload)
.then(function (response) {
console.log(response);

if(response.status === 200){
console.log("Login successfull");
return <Redirect to='/DashboardHome' />
/* page redirect or load profile */
if(data.status === 200){
console.log("Login successfull");
//return <Redirect to='/DashboardHome' />
/* page redirect or load profile */
// store token
localStorage.setItem("token", data.token);
}
else if(data.status === 204){
console.log("Username password do not match");
alert("username password do not match")
}
else{
console.log("Username does not exists");
alert("Username does not exist");
}

}
else if(response.status === 204){
console.log("Username password do not match");
alert("username password do not match")
}
else{
console.log("Username does not exists");
alert("Username does not exist");
}
})
.catch(function (error) {
console.log(error);
});
}).catch((err) => {
console.log(err);
});
}

render() {
Expand Down
21 changes: 20 additions & 1 deletion src/services/hackathon.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,23 @@ export const getAppStatus = payload => {
).catch((error) => {
throw error;
});
};
};

export const getToken = payload => {
return axios.post(config.BASE_URL+'/api/v1/account/login/', payload)
.then(function (response) {
//console.log(response);
if(response.status === 200){
return {status:response.status, token:response.data.token};
}
else if(response.status === 204){
return {status:response.status};
}
else{
return {status:404};
}
})
.catch(function (error) {
throw error;
});
}