From d853d0dcb2b6343e84d3a65133cd2edc6344877e Mon Sep 17 00:00:00 2001 From: jedi Date: Mon, 11 Dec 2023 23:17:46 +0100 Subject: [PATCH] stash --- core/authentication/tests/v2/test_users.py | 17 +++++++++++++++++ web/src/store/index.js | 14 +++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/core/authentication/tests/v2/test_users.py b/core/authentication/tests/v2/test_users.py index 29b21f7..d83d287 100644 --- a/core/authentication/tests/v2/test_users.py +++ b/core/authentication/tests/v2/test_users.py @@ -93,3 +93,20 @@ class UserApiTest(TestCase): content_type='application/json') self.assertEqual(response.status_code, 200) 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()) diff --git a/web/src/store/index.js b/web/src/store/index.js index d8eeeec..7e40b4e 100644 --- a/web/src/store/index.js +++ b/web/src/store/index.js @@ -138,8 +138,8 @@ const store = new Vuex.Store({ actions: { async login({commit, dispatch, state}, {username, password, remember}) { commit('setRemember', remember); - try{ - const data = await fetch('/api/2/token/', { + try { + const data = await fetch('/api/2/login/', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({username: username, password: password}), @@ -148,6 +148,7 @@ const store = new Vuex.Store({ if (data.token && data.key) { commit('setToken', data.token); commit('setUser', username); + axios.defaults.headers.common['Authorization'] = `Token ${data.token}`; return true; } else { return false; @@ -158,7 +159,7 @@ const store = new Vuex.Store({ } }, async loadEvents({commit}) { - const {data} = await axios.get('/1/events/'); + const {data} = await axios.get('/2/events/'); commit('replaceEvents', data); }, changeEvent({dispatch, getters}, eventName) { @@ -217,6 +218,9 @@ const store = new Vuex.Store({ export default store; store.dispatch('loadEvents').then(() => { - store.dispatch('loadEventItems'); - store.dispatch('loadBoxes'); + if (store.getters.isLoggedIn) { + axios.defaults.headers.common['Authorization'] = `Token ${store.state.token}`; + store.dispatch('loadEventItems'); + store.dispatch('loadBoxes'); + } });