Fix local login

This commit is contained in:
Christian Cueni 2020-02-18 16:01:20 +01:00
parent cd24073675
commit e067717d50
9 changed files with 29 additions and 25 deletions

View File

@ -12,7 +12,7 @@ describe('The Login Page', () => {
const username = ''; const username = '';
const password = 'test'; const password = 'test';
cy.visit('/'); cy.visit('/old-login');
cy.login(username, password); cy.login(username, password);
cy.get('[data-cy=email-local-errors]').contains('E-Mail ist ein Pflichtfeld'); cy.get('[data-cy=email-local-errors]').contains('E-Mail ist ein Pflichtfeld');
}); });
@ -21,7 +21,7 @@ describe('The Login Page', () => {
const username = 'test'; const username = 'test';
const password = ''; const password = '';
cy.visit('/'); cy.visit('/old-login');
cy.login(username, password); cy.login(username, password);
cy.get('[data-cy=password-local-errors]').contains('Passwort ist ein Pflichtfeld'); cy.get('[data-cy=password-local-errors]').contains('Passwort ist ein Pflichtfeld');
}); });
@ -30,18 +30,9 @@ describe('The Login Page', () => {
const username = 'test'; const username = 'test';
const password = '12345'; const password = '12345';
cy.visit('/'); cy.visit('/old-login');
cy.login(username, password); cy.login(username, password);
cy.get('[data-cy=login-error]').contains('Die E-Mail oder das Passwort ist falsch. Bitte versuchen Sie nochmals.'); cy.get('[data-cy=login-error]').contains('Die E-Mail oder das Passwort ist falsch. Bitte versuchen Sie nochmals.');
}); });
it('redirect after login', () => {
const username = 'test';
const password = 'test';
cy.visit('/book/topic/berufliche-grundbildung');
cy.login(username, password);
cy.get('body').contains('Berufliche Grundbildung');
});
}) })

View File

@ -54,7 +54,7 @@ Cypress.Commands.add('apolloLogin', (username, password) => {
// todo: replace with apollo call // todo: replace with apollo call
Cypress.Commands.add("login", (username, password, visitLogin = false) => { Cypress.Commands.add("login", (username, password, visitLogin = false) => {
if (visitLogin) { if (visitLogin) {
cy.visit('/login-local'); cy.visit('/old-login');
} }
if (username != '') { if (username != '') {

View File

@ -7,7 +7,7 @@ fragment UserParts on UserNode {
firstName firstName
lastName lastName
avatarUrl avatarUrl
licenseExpiryDate expiryDate
lastModule { lastModule {
id id
slug slug

View File

@ -1,5 +1,5 @@
mutation Login($input: LoginInput!) { mutation LocalLogin($input: LocalLoginInput!) {
login(input: $input) { localLogin(input: $input) {
success success
message message
errors { errors {

View File

@ -137,7 +137,7 @@ function unauthorizedAccess(to) {
function redirectUsersWithoutValidLicense(to) { function redirectUsersWithoutValidLicense(to) {
return privateApolloClient.query({ return privateApolloClient.query({
query: ME_QUERY, query: ME_QUERY,
}).then(({data}) => data.me.licenseExpiryDate == null); }).then(({data}) => data.me.expiryDate == null);
} }
function redirectStudentsWithoutClass() { function redirectStudentsWithoutClass() {

View File

@ -71,7 +71,7 @@
</template> </template>
<script> <script>
import LOGIN_MUTATION from '@/graphql/gql/mutations/login.gql'; import LOGIN_LOCAL_MUTATION from '@/graphql/gql/mutations/loginLocal.gql';
export default { export default {
components: {}, components: {},
@ -84,7 +84,7 @@ export default {
if (result) { if (result) {
this.$apollo.mutate({ this.$apollo.mutate({
client: 'publicClient', client: 'publicClient',
mutation: LOGIN_MUTATION, mutation: LOGIN_LOCAL_MUTATION,
variables: { variables: {
input: { input: {
usernameInput: this.email, usernameInput: this.email,
@ -95,16 +95,16 @@ export default {
store, store,
{ {
data: { data: {
login localLogin
} }
} }
) { ) {
try { try {
if (login.success) { if (localLogin.success) {
const redirectUrl = that.$route.query.redirect ? that.$route.query.redirect : '/' const redirectUrl = that.$route.query.redirect ? that.$route.query.redirect : '/'
that.$router.push(redirectUrl); that.$router.push(redirectUrl);
} else { } else {
const firstError = login.errors[0]; const firstError = localLogin.errors[0];
switch (firstError.field) { switch (firstError.field) {
case 'invalid_credentials': case 'invalid_credentials':
that.loginError = 'Die E-Mail oder das Passwort ist falsch. Bitte versuchen Sie nochmals.'; that.loginError = 'Die E-Mail oder das Passwort ist falsch. Bitte versuchen Sie nochmals.';

View File

@ -64,8 +64,8 @@ const routes = [
} }
}, },
{ {
path: '/login-local', path: '/old-login',
name: 'loginLocal', name: 'oldLogin',
component: loginLocal, component: loginLocal,
meta: { meta: {
layout: 'public', layout: 'public',

View File

@ -28,6 +28,9 @@ def is_private_api_call_allowed(user, body):
body_unicode = body.decode('utf-8') body_unicode = body.decode('utf-8')
if not user.hep_id:
return True
if re.search(r"mutation\s*.*\s*logout\s*{", body_unicode) or re.search(r"query\s*.*\s*me\s*{", body_unicode)\ if re.search(r"mutation\s*.*\s*logout\s*{", body_unicode) or re.search(r"query\s*.*\s*me\s*{", body_unicode)\
or re.search(r"mutation\s*Coupon", body_unicode): or re.search(r"mutation\s*Coupon", body_unicode):
return True return True

View File

@ -1,7 +1,10 @@
from datetime import datetime
import graphene import graphene
from graphene import relay from graphene import relay
from graphene_django import DjangoObjectType from graphene_django import DjangoObjectType
from graphene_django.filter import DjangoFilterConnectionField from graphene_django.filter import DjangoFilterConnectionField
from django.utils.dateformat import format
from basicknowledge.models import BasicKnowledge from basicknowledge.models import BasicKnowledge
from basicknowledge.queries import InstrumentNode from basicknowledge.queries import InstrumentNode
@ -26,12 +29,13 @@ class UserNode(DjangoObjectType):
pk = graphene.Int() pk = graphene.Int()
permissions = graphene.List(graphene.String) permissions = graphene.List(graphene.String)
selected_class = graphene.Field(SchoolClassNode) selected_class = graphene.Field(SchoolClassNode)
expiry_date = graphene.List(graphene.String)
class Meta: class Meta:
model = User model = User
filter_fields = ['username', 'email'] filter_fields = ['username', 'email']
only_fields = ['username', 'email', 'first_name', 'last_name', 'school_classes', 'last_module', 'avatar_url', only_fields = ['username', 'email', 'first_name', 'last_name', 'school_classes', 'last_module', 'avatar_url',
'selected_class', 'license_expiry_date'] 'selected_class', 'expiry_date']
interfaces = (relay.Node,) interfaces = (relay.Node,)
def resolve_pk(self, info, **kwargs): def resolve_pk(self, info, **kwargs):
@ -43,6 +47,12 @@ class UserNode(DjangoObjectType):
def resolve_selected_class(self, info): def resolve_selected_class(self, info):
return self.selected_class() return self.selected_class()
def resolve_expiry_date(self, info):
if not self.hep_id: # concerns users that already have an (old) account
return format(datetime(2020, 7, 31), 'U') # just set some expiry date
else:
return self.license_expiry_date
class UsersQuery(object): class UsersQuery(object):
me = graphene.Field(UserNode) me = graphene.Field(UserNode)