Fix login & tests

This commit is contained in:
Christian Cueni 2020-02-18 10:05:07 +01:00
parent 36c43bf4e1
commit 677d8dbf44
7 changed files with 83 additions and 54 deletions

View File

@ -1,5 +1,6 @@
const schema = require('../fixtures/schema_public.json');
const isEmailAvailableUrl = 'https://stage.hep-verlag.ch/rest/deutsch/V1/customers/isEmailAvailable';
const checkPasswordUrl = 'https://stage.hep-verlag.ch/rest/deutsch/V1/customers';
const checkPasswordUrl = 'https://stage.hep-verlag.ch/rest/deutsch/V1/integration/customer/token';
describe('Login', () => {
beforeEach(() => {
@ -8,14 +9,37 @@ describe('Login', () => {
it('works with valid email and password', () => {
cy.viewport('macbook-15');
cy.route('POST', isEmailAvailableUrl, "false");
cy.route('POST', checkPasswordUrl, "token12345ABCD+");
cy.mockGraphql({
schema: schema,
operations: {
Login: variables => {
return {
login: {
errors: [],
message: "success",
success: true
}
}
},
}
});
cy.route('POST', isEmailAvailableUrl, 'false');
cy.route({
method: 'POST',
url: checkPasswordUrl,
response: 'token12345ABCD+',
});
cy.visit('/hello');
cy.checkEmailAvailable('feuz@aebi.ch');
cy.get('[data-cy="login-title"]').contains('Bitte geben Sie das passende Passwort ein');
cy.enterPassword('abcd1234');
// As we cannot set the cookie in the right manner, we just check for the absence of erros.
// In real world the user gets redirect to another page
cy.get('[data-cy="email-local-errors"]').should('not.exist');
});
it('displays error message if password is wrong', () => {

View File

@ -147,23 +147,21 @@ function networkErrorCallback(statusCode) {
}
router.beforeEach(async (to, from, next) => {
// handle logout
if (to.path === '/logout') {
privateApolloClient.resetStore();
next({name: 'login'});
return
return;
}
getCookieValue('loginStatus')
if (unauthorizedAccess(to)) {
const redirectUrl = `/login?redirect=${to.path}`;
next(redirectUrl);
return
return;
}
if ((to.name !== 'noClass' || to.name !== 'licenseActivation') && loginRequired(to) && await redirectStudentsWithoutClass()) {
if ((to.name !== 'noClass' && to.name !== 'licenseActivation') && loginRequired(to) && await redirectStudentsWithoutClass()) {
next({name: 'noClass'})
return
return;
}
next();

View File

@ -47,7 +47,6 @@ export default {
},
fetchPolicy: 'no-cache'
}).then(({data}) => {
this.loading = false;
if (data.registration.success) {
this.keyValid = true;

View File

@ -38,6 +38,7 @@
<script>
import HELLO_EMAIL from '@/graphql/gql/local/helloEmail.gql';
import LOGIN_MUTATION from '@/graphql/gql/mutations/login.gql';
import {login} from '../hep-client/index';
export default {
@ -51,54 +52,61 @@ export default {
if (result) {
login(this.helloEmail.email, this.password)
.then((response) => {
console.log(response)
if (response.status === 200) {
this.mySkillboxLogin(response.data);
} else {
this.passwordErrors = ['Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.'];
}
})
.catch((error) => {
console.log(error)
if (error.response.data.message && error.response.data.message === 'Sie haben sich nicht korrekt eingeloggt oder Ihr Konto ist vor\u00fcbergehend deaktiviert.') {
this.passwordErrors = ['Sie haben sich nicht korrekt eingeloggt oder Ihr Konto ist vorübergehend deaktiviert.'];
} else {
this.passwordErrors = ['Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.'];
}
});
// this.$apollo.mutate({
// client: 'publicClient',
// mutation: LOGIN_MUTATION,
// variables: {
// input: {
// usernameInput: this.email,
// passwordInput: this.password
// }
// },
// update(
// store,
// {
// data: {
// login
// }
// }
// ) {
// try {
// if (login.success) {
// const redirectUrl = that.$route.query.redirect ? that.$route.query.redirect : '/'
// that.$router.push(redirectUrl);
// } else {
// const firstError = login.errors[0];
// switch (firstError.field) {
// case 'invalid_credentials':
// that.loginError = 'Die E-Mail oder das Passwort ist falsch. Bitte versuchen Sie nochmals.';
// break;
// case 'license_inactive':
// that.loginError = 'Ihre Lizenz ist nicht mehr aktiv.';
// break;
// }
// }
// } catch (e) {
// console.warn(e);
// that.loginError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.';
// }
// }
// });
}
});
},
mySkillboxLogin(token) {
const that = this;
this.$apollo.mutate({
client: 'publicClient',
mutation: LOGIN_MUTATION,
variables: {
input: {
usernameInput: that.helloEmail,
passwordInput: token
}
},
update(
store,
{
data: {
login
}
}
) {
try {
if (login.success) {
const redirectUrl = that.$route.query.redirect ? that.$route.query.redirect : '/';
that.$router.push(redirectUrl);
} else {
const firstError = login.errors[0];
switch (firstError.field) {
case 'invalid_credentials':
that.loginError = 'Die E-Mail oder das Passwort ist falsch. Bitte versuchen Sie nochmals.';
break;
case 'no_valid_license':
this.$router.push({name: 'licenseActivation'})
break;
}
}
} catch (e) {
console.warn(e);
that.loginError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.';
}
}
});
},

View File

@ -151,12 +151,12 @@ export default {
};
register(registrationData).then((response) => {
console.log(response)
if (response.data.id && response.data.id > 0) {
this.$router.push({name: 'checkEmail'});
}
})
.catch((error) => {
console.warn(error);
if (error.response.data.message && error.response.data.message === 'Ein Kunde mit der gleichen E-Mail-Adresse existiert bereits in einer zugeordneten Website.') {
this.emailErrors = ['Die angegebene E-Mail ist bereits registriert.'];
} else {

View File

@ -370,7 +370,7 @@ TASKBASE_SUPERPASSWORD = os.environ.get("TASKBASE_SUPERPASSWORD")
TASKBASE_BASEURL = os.environ.get("TASKBASE_BASEURL")
USE_LOCAL_REGISTRATION = True
USE_LOCAL_REGISTRATION = False
# HEP

View File

@ -44,7 +44,7 @@ class Login(relay.ClientIDMutation):
else:
hep_client = HepClient()
token = kwargs.get('token')
token = kwargs.get('password_input')
try:
user_data = hep_client.customer_me(token)