This commit is contained in:
j3d1 2023-12-11 23:17:46 +01:00
parent 71893f5258
commit d853d0dcb2
2 changed files with 26 additions and 5 deletions

View file

@ -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())

View file

@ -139,7 +139,7 @@ const store = new Vuex.Store({
async login({commit, dispatch, state}, {username, password, remember}) {
commit('setRemember', remember);
try {
const data = await fetch('/api/2/token/', {
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(() => {
if (store.getters.isLoggedIn) {
axios.defaults.headers.common['Authorization'] = `Token ${store.state.token}`;
store.dispatch('loadEventItems');
store.dispatch('loadBoxes');
}
});