|
|
@@ -1,5 +1,3 @@ |
|
|
|
import logging from './logging'; |
|
|
|
|
|
|
|
function checkStatus(response) { |
|
|
|
if (response.status >= 200 && response.status < 300) { |
|
|
|
return response; |
|
|
@@ -17,6 +15,7 @@ module.exports = { |
|
|
|
user: { |
|
|
|
authenticated: false, |
|
|
|
}, |
|
|
|
|
|
|
|
login(credential) { |
|
|
|
return fetch('/api/sessions/', { |
|
|
|
method: 'post', |
|
|
@@ -26,38 +25,12 @@ module.exports = { |
|
|
|
}, |
|
|
|
body: JSON.stringify(credential), |
|
|
|
}).then(checkStatus) |
|
|
|
.then(parseJSON); |
|
|
|
}, |
|
|
|
login2(context, credentials, callback) { |
|
|
|
const self = this; |
|
|
|
|
|
|
|
fetch('/users.html'); |
|
|
|
context.$http.post('/api/sessions/', credentials).then( |
|
|
|
response => { |
|
|
|
localStorage.setItem('token', response.data.token); |
|
|
|
self.user.authenticated = true; |
|
|
|
logging.success(this.$t('login.welcome')); |
|
|
|
if (callback) { |
|
|
|
callback(); |
|
|
|
} |
|
|
|
}, |
|
|
|
() => { |
|
|
|
logging.error(this.$t('login.credentials_invalids')); |
|
|
|
} |
|
|
|
); |
|
|
|
}, |
|
|
|
|
|
|
|
register(context, user, callback) { |
|
|
|
context.$http.post('/api/users/', user).then( |
|
|
|
() => { |
|
|
|
if (callback) { |
|
|
|
callback(); |
|
|
|
} |
|
|
|
}, |
|
|
|
() => { |
|
|
|
logging.warning(this.$t('register.beta')); |
|
|
|
} |
|
|
|
); |
|
|
|
.then(parseJSON) |
|
|
|
.then((data) => { |
|
|
|
localStorage.setItem('token', data.token); |
|
|
|
this.user.authenticated = true; |
|
|
|
return data; |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
logout(callback) { |
|
|
@@ -69,7 +42,9 @@ module.exports = { |
|
|
|
}, |
|
|
|
|
|
|
|
checkAuth() { |
|
|
|
console.log('check auth'); |
|
|
|
const jwt = localStorage.getItem('token'); |
|
|
|
console.log(jwt); |
|
|
|
this.user.authenticated = !!jwt; |
|
|
|
}, |
|
|
|
|
|
|
|