Add logout functionality
Remove unused imports Add file header Check response remove file headers
This commit is contained in:
parent
867dc72abd
commit
93ad822457
|
|
@ -3,17 +3,28 @@
|
|||
<user-icon class="user-widget__avatar" :src="avatar"></user-icon>
|
||||
<span class="user-widget__name">{{firstName}} {{lastName}}</span>
|
||||
<span class="user-widget__date" v-if="date">{{date}}</span>
|
||||
<button class="user-widget__logout" @click="logout()">Logout</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import UserIcon from '@/components/icons/UserIcon';
|
||||
import LOGOUT_MUTATION from '@/graphql/gql/mutations/logoutUser.gql';
|
||||
|
||||
export default {
|
||||
props: ['firstName', 'lastName', 'avatar', 'date'],
|
||||
|
||||
components: {
|
||||
UserIcon
|
||||
},
|
||||
methods: {
|
||||
logout() {
|
||||
this.$apollo.mutate({
|
||||
mutation: LOGOUT_MUTATION,
|
||||
}).then(({data}) => {
|
||||
if (data.logout.success) { location.replace('/') }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
@ -36,6 +47,18 @@
|
|||
font-family: $sans-serif-font-family;
|
||||
}
|
||||
|
||||
&__logout {
|
||||
font-family: $sans-serif-font-family;
|
||||
line-height: 16px;
|
||||
margin: 0 15px 0 20px;
|
||||
background: none;
|
||||
color: inherit;
|
||||
border: none;
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
outline: inherit;
|
||||
}
|
||||
|
||||
&__avatar {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
mutation {
|
||||
logout {
|
||||
success
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ from assignments.schema.mutations import AssignmentMutations
|
|||
from assignments.schema.queries import AssignmentsQuery, StudentSubmissionQuery
|
||||
from books.schema.mutations.main import BookMutations
|
||||
from books.schema.queries import BookQuery
|
||||
from core.schema.mutations.main import CoreMutations
|
||||
from objectives.mutations import ObjectiveMutations
|
||||
from objectives.schema import ObjectivesQuery
|
||||
from rooms.mutations import RoomMutations
|
||||
|
|
@ -24,7 +25,8 @@ class Query(UsersQuery, RoomsQuery, ObjectivesQuery, BookQuery, AssignmentsQuery
|
|||
debug = graphene.Field(DjangoDebug, name='__debug')
|
||||
|
||||
|
||||
class Mutation(BookMutations, RoomMutations, AssignmentMutations, ObjectiveMutations, graphene.ObjectType):
|
||||
class Mutation(BookMutations, RoomMutations, AssignmentMutations, ObjectiveMutations, CoreMutations,
|
||||
graphene.ObjectType):
|
||||
if settings.DEBUG:
|
||||
debug = graphene.Field(DjangoDebug, name='__debug')
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# ITerativ GmbH
|
||||
# http://www.iterativ.ch/
|
||||
#
|
||||
# Copyright (c) 2018 ITerativ GmbH. All rights reserved.
|
||||
#
|
||||
# Created on 22.10.18
|
||||
# @author: chrigu <christian.cueni@iterativ.ch>
|
||||
|
||||
import graphene
|
||||
from django.contrib.auth import logout
|
||||
|
||||
|
||||
class Logout(graphene.Mutation):
|
||||
success = graphene.Boolean()
|
||||
|
||||
def mutate(self, info, **kwargs):
|
||||
try:
|
||||
logout(info.context)
|
||||
return Logout(success=True)
|
||||
except Exception:
|
||||
return Logout(success=False)
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# ITerativ GmbH
|
||||
# http://www.iterativ.ch/
|
||||
#
|
||||
# Copyright (c) 2018 ITerativ GmbH. All rights reserved.
|
||||
#
|
||||
# Created on 22.10.18
|
||||
# @author: chrigu <christian.cueni@iterativ.ch>
|
||||
from core.schema.mutations.logout import Logout
|
||||
|
||||
|
||||
class CoreMutations(object):
|
||||
logout = Logout.Field()
|
||||
Loading…
Reference in New Issue