Merge branch 'login_admin_interface' of github.com:gradido/gradido into login_admin_interface

This commit is contained in:
Moriz Wahl 2021-11-24 18:26:38 +01:00
commit b0ac9b6632
5 changed files with 64 additions and 4 deletions

View File

@ -47,7 +47,7 @@ export class User {
@Field(() => number) @Field(() => number)
created: number created: number
@Field(() => Boolean) @Field(() =>>> Boolean)
emailChecked: boolean emailChecked: boolean
@Field(() => Boolean) @Field(() => Boolean)

View File

@ -224,6 +224,39 @@ export class UserResolver {
} }
*/ */
@Authorized()
@Query(() => User)
@UseMiddleware(klicktippNewsletterStateMiddleware)
async verifyLogin(@Ctx() context: any): Promise<User> {
// TODO refactor and do not have duplicate code with login(see below)
const userRepository = getCustomRepository(UserRepository)
const userEntity = await userRepository.findByPubkeyHex(context.pubKey)
const loginUserRepository = getCustomRepository(LoginUserRepository)
const loginUser = await loginUserRepository.findByEmail(userEntity.email)
const user = new User()
user.email = userEntity.email
user.firstName = userEntity.firstName
user.lastName = userEntity.lastName
user.username = userEntity.username
user.description = loginUser.description
user.pubkey = userEntity.pubkey.toString('hex')
user.language = loginUser.language
// Elopage Status & Stored PublisherId
user.hasElopage = await this.hasElopage(context)
// coinAnimation
const userSettingRepository = getCustomRepository(UserSettingRepository)
const coinanimation = await userSettingRepository
.readBoolean(userEntity.id, Setting.COIN_ANIMATION)
.catch((error) => {
throw new Error(error)
})
user.coinanimation = coinanimation
user.isAdmin = true // TODO implement
return user
}
@Query(() => User) @Query(() => User)
@UseMiddleware(klicktippNewsletterStateMiddleware) @UseMiddleware(klicktippNewsletterStateMiddleware)
async login( async login(

View File

@ -20,6 +20,26 @@ export const login = gql`
} }
` `
export const verifyLogin = gql`
query {
verifyLogin {
email
username
firstName
lastName
language
description
coinanimation
klickTipp {
newsletterState
}
hasElopage
publisherId
isAdmin
}
}
`
export const logout = gql` export const logout = gql`
query { query {
logout logout

View File

@ -51,7 +51,7 @@ Vue.config.productionTip = false
loadAllRules(i18n) loadAllRules(i18n)
addNavigationGuards(router, store) addNavigationGuards(router, store, apolloProvider.defaultClient)
/* eslint-disable no-new */ /* eslint-disable no-new */
new Vue({ new Vue({

View File

@ -1,4 +1,6 @@
const addNavigationGuards = (router, store) => { import { verifyLogin } from '../graphql/queries'
const addNavigationGuards = (router, store, apollo) => {
// handle publisherId // handle publisherId
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
const publisherId = to.query.pid const publisherId = to.query.pid
@ -10,10 +12,15 @@ const addNavigationGuards = (router, store) => {
}) })
// store token on authenticate // store token on authenticate
router.beforeEach((to, from, next) => { router.beforeEach(async (to, from, next) => {
if (to.path === '/authenticate' && to.query.token) { if (to.path === '/authenticate' && to.query.token) {
// TODO verify user in order to get user data // TODO verify user in order to get user data
store.commit('token', to.query.token) store.commit('token', to.query.token)
const result = await apollo.query({
query: verifyLogin,
fetchPolicy: 'network-only',
})
store.dispatch('login', result.data.verifyLogin)
next({ path: '/overview' }) next({ path: '/overview' })
} else { } else {
next() next()