2017-12-25 17:45:28 +01:00
|
|
|
const apiUrl = `${process.env.REACT_APP_API_URL}`
|
|
|
|
|
|
|
|
|
|
|
|
export default class MpwoApi {
|
|
|
|
static login(email, password) {
|
|
|
|
const request = new Request(`${apiUrl}auth/login`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: new Headers({
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
}),
|
|
|
|
body: JSON.stringify({
|
|
|
|
email: email,
|
|
|
|
password: password,
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
return fetch(request)
|
|
|
|
.then(response => response.json())
|
|
|
|
.catch(error => error)
|
|
|
|
}
|
2018-01-01 11:10:39 +01:00
|
|
|
static register(username, email, password, passwordConf) {
|
2017-12-25 17:45:28 +01:00
|
|
|
const request = new Request(`${apiUrl}auth/register`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: new Headers({
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
}),
|
|
|
|
body: JSON.stringify({
|
|
|
|
username: username,
|
|
|
|
email: email,
|
|
|
|
password: password,
|
2018-01-01 11:10:39 +01:00
|
|
|
password_conf: passwordConf,
|
2017-12-25 17:45:28 +01:00
|
|
|
}),
|
|
|
|
})
|
|
|
|
return fetch(request)
|
|
|
|
.then(response => response.json())
|
|
|
|
.catch(error => error)
|
|
|
|
}
|
|
|
|
static getProfile() {
|
|
|
|
const request = new Request(`${apiUrl}auth/profile`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: new Headers({
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
Authorization: `Bearer ${window.localStorage.getItem('authToken')}`,
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
return fetch(request)
|
|
|
|
.then(response => response.json())
|
|
|
|
.catch(error => error)
|
|
|
|
}
|
|
|
|
}
|