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", "apollo-link-http": "^1.5.16",
"appolo": "^6.0.19", "appolo": "^6.0.19",
"autoprefixer": "^7.1.2", "autoprefixer": "^7.1.2",
"axios": "^0.18.0",
"babel-eslint": "^8.2.1", "babel-eslint": "^8.2.1",
"babel-helper-vue-jsx-merge-props": "^2.0.3", "babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-loader": "^8.0.6", "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" class="button button--primary button--big actions__submit"
data-cy="login-button">Anmelden</button> data-cy="login-button">Anmelden</button>
</div> </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> </form>
</div> </div>
</template> </template>

View File

@ -9,7 +9,6 @@
<script> <script>
import {emailExists} from '../hep-client/index';
import HELLO_EMAIL_MUTATION from '@/graphql/gql/local/mutations/helloEmail.gql'; import HELLO_EMAIL_MUTATION from '@/graphql/gql/local/mutations/helloEmail.gql';
import LoadingButton from '@/components/LoadingButton'; import LoadingButton from '@/components/LoadingButton';
import pageTitleMixin from '@/mixins/page-title'; import pageTitleMixin from '@/mixins/page-title';
@ -34,26 +33,26 @@
this.submitted = true; this.submitted = true;
if (result) { if (result) {
this.loading = true; this.loading = true;
emailExists(this.email).then((response) => { // emailExists(this.email).then((response) => {
let redirectRouteName = 'login'; // let redirectRouteName = 'login';
//
if (response.data) { // if (response.data) {
redirectRouteName = 'registration'; // redirectRouteName = 'registration';
} // }
this.$apollo.mutate({ // this.$apollo.mutate({
mutation: HELLO_EMAIL_MUTATION, // mutation: HELLO_EMAIL_MUTATION,
variables: { // variables: {
helloEmail: this.email // helloEmail: this.email
} // }
}).then(() => { // }).then(() => {
this.$router.push({name: redirectRouteName, query: this.$route.query}); // this.$router.push({name: redirectRouteName, query: this.$route.query});
this.loading = false; // this.loading = false;
}); // });
}) // })
.catch(() => { // .catch(() => {
this.loading = false; // this.loading = false;
this.registrationError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie es nochmals.'; // 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 HELLO_EMAIL from '@/graphql/gql/local/helloEmail.gql';
import LOGIN_MUTATION from '@/graphql/gql/mutations/login.gql'; import LOGIN_MUTATION from '@/graphql/gql/mutations/login.gql';
import {login} from '@/hep-client/index';
import LoadingButton from '@/components/LoadingButton'; import LoadingButton from '@/components/LoadingButton';
export default { export default {
@ -76,29 +75,29 @@
methods: { methods: {
validateBeforeSubmit() { validateBeforeSubmit() {
this.$validator.validate().then(result => { // this.$validator.validate().then(result => {
this.submitted = true; // this.submitted = true;
if (result) { // if (result) {
this.loading = true; // this.loading = true;
login(this.helloEmail.email, this.password) // login(this.helloEmail.email, this.password)
.then((response) => { // .then((response) => {
this.loading = false; // this.loading = false;
if (response.status === 200) { // if (response.status === 200) {
this.mySkillboxLogin(response.data); // this.mySkillboxLogin(response.data);
} else { // } else {
this.passwordErrors = ['Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.']; // this.passwordErrors = ['Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.'];
} // }
}) // })
.catch((error) => { // .catch((error) => {
this.loading = false; // 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.') { // 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.']; // this.passwordErrors = ['Die von Ihnen eingegebene E-Mail-Adresse und das Passwort passen nicht zusammen.'];
} else { // } else {
this.passwordErrors = ['Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.']; // this.passwordErrors = ['Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.'];
} // }
}); // });
} // }
}); // });
}, },
mySkillboxLogin(token) { mySkillboxLogin(token) {
const that = this; const that = this;

View File

@ -264,7 +264,6 @@
<script> <script>
import {register} from '../hep-client/index';
import HELLO_EMAIL from '@/graphql/gql/local/helloEmail.gql'; import HELLO_EMAIL from '@/graphql/gql/local/helloEmail.gql';
import Checkbox from '@/components/ui/Checkbox'; import Checkbox from '@/components/ui/Checkbox';
import LoadingButton from '@/components/LoadingButton'; import LoadingButton from '@/components/LoadingButton';
@ -343,30 +342,30 @@
accepted_terms: this.acceptedTerms accepted_terms: this.acceptedTerms
}; };
register(registrationData).then((response) => { // register(registrationData).then((response) => {
this.loading = false; // this.loading = false;
if (response.data.id && response.data.id > 0) { // if (response.data.id && response.data.id > 0) {
this.$router.push({name: 'checkEmail'}); // this.$router.push({name: 'checkEmail'});
} // }
}) // })
.catch((error) => { // .catch((error) => {
this.loading = false; // this.loading = false;
console.warn(error); // console.warn(error);
if (error.response.data.message) { // if (error.response.data.message) {
switch (error.response.data.message) { // switch (error.response.data.message) {
case 'Ein Kunde mit der gleichen E-Mail-Adresse existiert bereits in einer zugeordneten Website.': // case 'Ein Kunde mit der gleichen E-Mail-Adresse existiert bereits in einer zugeordneten Website.':
this.emailErrors = ['Die angegebene E-Mail ist bereits registriert.']; // this.emailErrors = ['Die angegebene E-Mail ist bereits registriert.'];
break; // break;
case 'Sie müssen hier zustimmen, damit Sie sich registrieren können.': // 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.']; // this.acceptedTermsError = ['Sie müssen hier zustimmen, damit Sie sich registrieren können.'];
break; // break;
default: // default:
this.registrationError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.'; // this.registrationError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.';
} // }
} else { // } else {
this.registrationError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.'; // 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 datetime import datetime, timedelta
from django.test import TestCase 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()) 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): def handle_user_and_verify_products(user_data):
hep_client = HepClient() 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: try:
if not hep_client.is_email_verified(user_data): if not hep_client.is_email_verified(user_data):
@ -20,8 +20,8 @@ def handle_user_and_verify_products(user_data):
except HepClientException: except HepClientException:
return user, UNKNOWN_ERROR 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: # if not license:
# license, error_msg = check_and_create_licenses(hep_client, user) # 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) # create_role_for_user(user, license.for_role.key)
# #
# if not license.is_valid(): if not license.is_valid():
# return user, NO_VALID_LICENSE return user, NO_VALID_LICENSE
return user, None return user, None
def check_and_create_licenses(hep_client, user): def check_and_create_licenses(hep_client, user):
try: # try:
admin_token = AdminData.objects.get_admin_token() # admin_token = AdminData.objects.get_admin_token()
product = hep_client.myskillbox_product_for_customer(admin_token, user.hep_id) # product = hep_client.myskillbox_product_for_customer(admin_token, user.hep_id)
except HepClientException: # except HepClientException:
return None, UNKNOWN_ERROR # return None, UNKNOWN_ERROR
if product: # if product:
license = License.objects.create_license_for_role(user, product['activated'], product['raw'], # license = License.objects.create_license_for_role(user, product['activated'], product['raw'],
product['license']['edition'], # product['license']['edition'],
product['order_id'], product['isbn']) # product['order_id'], product['isbn'])
# todo handle no license case # # todo handle no license case
else: # else:
return None, NO_VALID_LICENSE # return None, NO_VALID_LICENSE
return license, None # return license, None
return None, None
def create_role_for_user(user, role_key): 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.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 core.factories import UserFactory
from users.tests.mock_hep_data_factory import MockResponse, ME_DATA, VALID_STUDENT_ORDERS, VALID_TEACHERS_ORDERS, \ from users.tests.mock_hep_data_factory import ME_DATA
NOT_CONFIRMED_ME from users.models import User
from users.factories import LicenseFactory
from users.models import Role, User, SchoolClass, License, UserData
TOKEN = 'abcd12345!' TOKEN = 'abcd12345!'