FitTrackee/mpwo_client/src/mwpoApi/user.js

99 lines
2.6 KiB
JavaScript
Raw Normal View History

2018-04-29 17:02:08 +02:00
import { apiUrl } from '../utils'
export default class MpwoApiUser {
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-04-29 17:02:08 +02:00
2018-01-01 11:10:39 +01:00
static register(username, email, password, passwordConf) {
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,
}),
})
return fetch(request)
.then(response => response.json())
.catch(error => error)
}
2018-04-29 17:02:08 +02:00
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)
}
2018-04-29 17:02:08 +02:00
2018-01-01 16:59:46 +01:00
static updateProfile(form) {
const request = new Request(`${apiUrl}auth/profile/edit`, {
method: 'POST',
headers: new Headers({
'Content-Type': 'application/json',
Authorization: `Bearer ${window.localStorage.getItem('authToken')}`,
}),
body: JSON.stringify({
first_name: form.firstName,
last_name: form.lastName,
bio: form.bio,
location: form.location,
2018-01-01 17:50:12 +01:00
birth_date: form.birthDate,
password: form.password,
password_conf: form.passwordConf,
2018-01-01 16:59:46 +01:00
}),
})
return fetch(request)
.then(response => response.json())
.catch(error => error)
}
2018-04-29 17:02:08 +02:00
2018-01-01 21:54:03 +01:00
static updatePicture(form) {
const request = new Request(`${apiUrl}auth/picture`, {
method: 'POST',
headers: new Headers({
Authorization: `Bearer ${window.localStorage.getItem('authToken')}`,
}),
body: form,
})
return fetch(request)
.then(response => response.json())
.catch(error => error)
}
2018-04-29 17:02:08 +02:00
2018-01-01 21:54:03 +01:00
static deletePicture() {
const request = new Request(`${apiUrl}auth/picture`, {
method: 'DELETE',
headers: new Headers({
Authorization: `Bearer ${window.localStorage.getItem('authToken')}`,
}),
})
return fetch(request)
.then(response => response.json())
.catch(error => error)
}
}