stash
This commit is contained in:
parent
71893f5258
commit
d853d0dcb2
2 changed files with 26 additions and 5 deletions
|
@ -93,3 +93,20 @@ class UserApiTest(TestCase):
|
||||||
content_type='application/json')
|
content_type='application/json')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertTrue('token' in response.json())
|
self.assertTrue('token' in response.json())
|
||||||
|
|
||||||
|
def test_legacy_user(self):
|
||||||
|
response = self.client.get('/api/2/users/1/')
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertEqual(response.json()['username'], settings.LEGACY_USER_NAME)
|
||||||
|
self.assertEqual(response.json()['email'], 'mail@' + settings.MAIL_DOMAIN)
|
||||||
|
self.assertEqual(response.json()['first_name'], '')
|
||||||
|
self.assertEqual(response.json()['last_name'], '')
|
||||||
|
self.assertEqual(response.json()['id'], 1)
|
||||||
|
|
||||||
|
def test_get_legacy_user_token(self):
|
||||||
|
anonymous = Client()
|
||||||
|
response = anonymous.post('/api/2/login/', {
|
||||||
|
'username': settings.LEGACY_USER_NAME, 'password': settings.LEGACY_USER_PASSWORD},
|
||||||
|
content_type='application/json')
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertTrue('token' in response.json())
|
||||||
|
|
|
@ -139,7 +139,7 @@ const store = new Vuex.Store({
|
||||||
async login({commit, dispatch, state}, {username, password, remember}) {
|
async login({commit, dispatch, state}, {username, password, remember}) {
|
||||||
commit('setRemember', remember);
|
commit('setRemember', remember);
|
||||||
try {
|
try {
|
||||||
const data = await fetch('/api/2/token/', {
|
const data = await fetch('/api/2/login/', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify({username: username, password: password}),
|
body: JSON.stringify({username: username, password: password}),
|
||||||
|
@ -148,6 +148,7 @@ const store = new Vuex.Store({
|
||||||
if (data.token && data.key) {
|
if (data.token && data.key) {
|
||||||
commit('setToken', data.token);
|
commit('setToken', data.token);
|
||||||
commit('setUser', username);
|
commit('setUser', username);
|
||||||
|
axios.defaults.headers.common['Authorization'] = `Token ${data.token}`;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -158,7 +159,7 @@ const store = new Vuex.Store({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async loadEvents({commit}) {
|
async loadEvents({commit}) {
|
||||||
const {data} = await axios.get('/1/events/');
|
const {data} = await axios.get('/2/events/');
|
||||||
commit('replaceEvents', data);
|
commit('replaceEvents', data);
|
||||||
},
|
},
|
||||||
changeEvent({dispatch, getters}, eventName) {
|
changeEvent({dispatch, getters}, eventName) {
|
||||||
|
@ -217,6 +218,9 @@ const store = new Vuex.Store({
|
||||||
export default store;
|
export default store;
|
||||||
|
|
||||||
store.dispatch('loadEvents').then(() => {
|
store.dispatch('loadEvents').then(() => {
|
||||||
|
if (store.getters.isLoggedIn) {
|
||||||
|
axios.defaults.headers.common['Authorization'] = `Token ${store.state.token}`;
|
||||||
store.dispatch('loadEventItems');
|
store.dispatch('loadEventItems');
|
||||||
store.dispatch('loadBoxes');
|
store.dispatch('loadBoxes');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue