Remove axios

This commit is contained in:
Christian Cueni 2021-05-06 11:30:41 +02:00
parent bfdd743afd
commit 04473ecad3
9 changed files with 93 additions and 128 deletions

View File

@ -36,7 +36,6 @@
"apollo-link-http": "^1.5.16",
"appolo": "^6.0.19",
"autoprefixer": "^7.1.2",
"axios": "^0.18.0",
"babel-eslint": "^8.2.1",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-loader": "^8.0.6",

View File

@ -1,18 +0,0 @@
import * as axios from 'axios';
const hepBaseUrl = process.env.HEP_URL;
export function register(registrationData) {
return axios.post('/api/proxy/registration/', registrationData);
}
export function login(username, password) {
return axios.post(`${hepBaseUrl}/rest/deutsch/V1/integration/customer/token`, {username, password});
}
export function emailExists(email) {
return axios.post(`${hepBaseUrl}/rest/deutsch/V1/customers/isEmailAvailable`, {
customerEmail: email,
websiteId: 1
});
}

View File

@ -72,13 +72,6 @@
class="button button--primary button--big actions__submit"
data-cy="login-button">Anmelden</button>
</div>
<div class="account-link">
<p class="account-link__text">Haben Sie noch kein Konto?</p>
<router-link
:to="{name: 'registration'}"
class="account-link__link text-link">Jetzt registrieren
</router-link>
</div>
</form>
</div>
</template>

View File

@ -9,7 +9,6 @@
<script>
import {emailExists} from '../hep-client/index';
import HELLO_EMAIL_MUTATION from '@/graphql/gql/local/mutations/helloEmail.gql';
import LoadingButton from '@/components/LoadingButton';
import pageTitleMixin from '@/mixins/page-title';
@ -34,26 +33,26 @@
this.submitted = true;
if (result) {
this.loading = true;
emailExists(this.email).then((response) => {
let redirectRouteName = 'login';
if (response.data) {
redirectRouteName = 'registration';
}
this.$apollo.mutate({
mutation: HELLO_EMAIL_MUTATION,
variables: {
helloEmail: this.email
}
}).then(() => {
this.$router.push({name: redirectRouteName, query: this.$route.query});
this.loading = false;
});
})
.catch(() => {
this.loading = false;
this.registrationError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie es nochmals.';
});
// emailExists(this.email).then((response) => {
// let redirectRouteName = 'login';
//
// if (response.data) {
// redirectRouteName = 'registration';
// }
// this.$apollo.mutate({
// mutation: HELLO_EMAIL_MUTATION,
// variables: {
// helloEmail: this.email
// }
// }).then(() => {
// this.$router.push({name: redirectRouteName, query: this.$route.query});
// this.loading = false;
// });
// })
// .catch(() => {
// this.loading = false;
// this.registrationError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie es nochmals.';
// });
}
});
},

View File

@ -59,7 +59,6 @@
import HELLO_EMAIL from '@/graphql/gql/local/helloEmail.gql';
import LOGIN_MUTATION from '@/graphql/gql/mutations/login.gql';
import {login} from '@/hep-client/index';
import LoadingButton from '@/components/LoadingButton';
export default {
@ -76,29 +75,29 @@
methods: {
validateBeforeSubmit() {
this.$validator.validate().then(result => {
this.submitted = true;
if (result) {
this.loading = true;
login(this.helloEmail.email, this.password)
.then((response) => {
this.loading = false;
if (response.status === 200) {
this.mySkillboxLogin(response.data);
} else {
this.passwordErrors = ['Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.'];
}
})
.catch((error) => {
this.loading = false;
if (error.response.data.message && error.response.data.message === 'Sie haben sich nicht korrekt eingeloggt oder Ihr Konto ist vor\u00fcbergehend deaktiviert.') {
this.passwordErrors = ['Die von Ihnen eingegebene E-Mail-Adresse und das Passwort passen nicht zusammen.'];
} else {
this.passwordErrors = ['Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.'];
}
});
}
});
// this.$validator.validate().then(result => {
// this.submitted = true;
// if (result) {
// this.loading = true;
// login(this.helloEmail.email, this.password)
// .then((response) => {
// this.loading = false;
// if (response.status === 200) {
// this.mySkillboxLogin(response.data);
// } else {
// this.passwordErrors = ['Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.'];
// }
// })
// .catch((error) => {
// this.loading = false;
// if (error.response.data.message && error.response.data.message === 'Sie haben sich nicht korrekt eingeloggt oder Ihr Konto ist vor\u00fcbergehend deaktiviert.') {
// this.passwordErrors = ['Die von Ihnen eingegebene E-Mail-Adresse und das Passwort passen nicht zusammen.'];
// } else {
// this.passwordErrors = ['Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.'];
// }
// });
// }
// });
},
mySkillboxLogin(token) {
const that = this;

View File

@ -264,7 +264,6 @@
<script>
import {register} from '../hep-client/index';
import HELLO_EMAIL from '@/graphql/gql/local/helloEmail.gql';
import Checkbox from '@/components/ui/Checkbox';
import LoadingButton from '@/components/LoadingButton';
@ -343,30 +342,30 @@
accepted_terms: this.acceptedTerms
};
register(registrationData).then((response) => {
this.loading = false;
if (response.data.id && response.data.id > 0) {
this.$router.push({name: 'checkEmail'});
}
})
.catch((error) => {
this.loading = false;
console.warn(error);
if (error.response.data.message) {
switch (error.response.data.message) {
case 'Ein Kunde mit der gleichen E-Mail-Adresse existiert bereits in einer zugeordneten Website.':
this.emailErrors = ['Die angegebene E-Mail ist bereits registriert.'];
break;
case 'Sie müssen hier zustimmen, damit Sie sich registrieren können.':
this.acceptedTermsError = ['Sie müssen hier zustimmen, damit Sie sich registrieren können.'];
break;
default:
this.registrationError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.';
}
} else {
this.registrationError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.';
}
});
// register(registrationData).then((response) => {
// this.loading = false;
// if (response.data.id && response.data.id > 0) {
// this.$router.push({name: 'checkEmail'});
// }
// })
// .catch((error) => {
// this.loading = false;
// console.warn(error);
// if (error.response.data.message) {
// switch (error.response.data.message) {
// case 'Ein Kunde mit der gleichen E-Mail-Adresse existiert bereits in einer zugeordneten Website.':
// this.emailErrors = ['Die angegebene E-Mail ist bereits registriert.'];
// break;
// case 'Sie müssen hier zustimmen, damit Sie sich registrieren können.':
// this.acceptedTermsError = ['Sie müssen hier zustimmen, damit Sie sich registrieren können.'];
// break;
// default:
// this.registrationError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.';
// }
// } else {
// this.registrationError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.';
// }
// });
}
});
},

View File

@ -2,7 +2,8 @@ import json
from datetime import datetime, timedelta
from django.test import TestCase
from core.hep_client import HepClient, MYSKILLBOX_LICENSES
from oauth.hep_client import HepClient
from users.licenses import MYSKILLBOX_LICENSES
ISBNS = list(MYSKILLBOX_LICENSES.keys())

View File

@ -12,7 +12,7 @@ NO_VALID_LICENSE = 'no_valid_license'
def handle_user_and_verify_products(user_data):
hep_client = HepClient()
user = User.objects.get_or_create_hep_user(user_data) # todo: test
user = User.objects.get_or_create_hep_user(user_data)
try:
if not hep_client.is_email_verified(user_data):
@ -20,8 +20,8 @@ def handle_user_and_verify_products(user_data):
except HepClientException:
return user, UNKNOWN_ERROR
# license = License.objects.get_active_license_for_user(user)
#
license = License.objects.get_active_license_for_user(user)
# if not license:
# license, error_msg = check_and_create_licenses(hep_client, user)
#
@ -30,28 +30,30 @@ def handle_user_and_verify_products(user_data):
#
# create_role_for_user(user, license.for_role.key)
#
# if not license.is_valid():
# return user, NO_VALID_LICENSE
if not license.is_valid():
return user, NO_VALID_LICENSE
return user, None
def check_and_create_licenses(hep_client, user):
try:
admin_token = AdminData.objects.get_admin_token()
product = hep_client.myskillbox_product_for_customer(admin_token, user.hep_id)
except HepClientException:
return None, UNKNOWN_ERROR
# try:
# admin_token = AdminData.objects.get_admin_token()
# product = hep_client.myskillbox_product_for_customer(admin_token, user.hep_id)
# except HepClientException:
# return None, UNKNOWN_ERROR
if product:
license = License.objects.create_license_for_role(user, product['activated'], product['raw'],
product['license']['edition'],
product['order_id'], product['isbn'])
# todo handle no license case
else:
return None, NO_VALID_LICENSE
# if product:
# license = License.objects.create_license_for_role(user, product['activated'], product['raw'],
# product['license']['edition'],
# product['order_id'], product['isbn'])
# # todo handle no license case
# else:
# return None, NO_VALID_LICENSE
return license, None
# return license, None
return None, None
def create_role_for_user(user, role_key):

View File

@ -1,19 +1,10 @@
from datetime import timedelta
from unittest.mock import patch
import requests
from django.conf import settings
from django.contrib.sessions.middleware import SessionMiddleware
from django.test import TestCase, RequestFactory
from django.utils import timezone
from graphene.test import Client
from api.schema_public import schema
from django.test import TestCase
from core.factories import UserFactory
from users.tests.mock_hep_data_factory import MockResponse, ME_DATA, VALID_STUDENT_ORDERS, VALID_TEACHERS_ORDERS, \
NOT_CONFIRMED_ME
from users.factories import LicenseFactory
from users.models import Role, User, SchoolClass, License, UserData
from users.tests.mock_hep_data_factory import ME_DATA
from users.models import User
TOKEN = 'abcd12345!'