implemented isAdmin from backend

This commit is contained in:
Ulf Gebhardt 2021-11-20 16:30:22 +01:00
parent e4f77407ee
commit dbfe882c14
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
4 changed files with 42 additions and 1 deletions

View File

@ -19,6 +19,7 @@ export class User {
this.pubkey = json.public_hex
this.language = json.language
this.publisherId = json.publisher_id
this.isAdmin = json.isAdmin
}
@Field(() => String)
@ -69,6 +70,9 @@ export class User {
@Field(() => Int, { nullable: true })
publisherId?: number
@Field(() => Boolean)
isAdmin: boolean
@Field(() => Boolean)
coinanimation: boolean

View File

@ -194,6 +194,36 @@ const SecretKeyCryptographyDecrypt = (encryptedMessage: Buffer, encryptionKey: B
@Resolver()
export class UserResolver {
/*
@Authorized()
@Query(() => User)
async verifyLogin(@Ctx() context: any): Promise<User> {
const loginUserRepository = getCustomRepository(LoginUserRepository)
loginUser = loginUserRepository.findByPubkeyHex()
const user = new User(result.data.user)
this.email = json.email
this.firstName = json.first_name
this.lastName = json.last_name
this.username = json.username
this.description = json.description
this.pubkey = json.public_hex
this.language = json.language
this.publisherId = json.publisher_id
this.isAdmin = json.isAdmin
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)
@UseMiddleware(klicktippNewsletterStateMiddleware)
async login(
@ -254,6 +284,7 @@ export class UserResolver {
throw new Error(error)
})
user.coinanimation = coinanimation
user.isAdmin = true // TODO implement
return user
}

View File

@ -15,6 +15,7 @@ export const login = gql`
}
hasElopage
publisherId
isAdmin
}
}
`

View File

@ -34,6 +34,9 @@ export const mutations = {
if (isNaN(pubId)) pubId = null
state.publisherId = pubId
},
isAdmin: (state, isAdmin) => {
state.isAdmin = !!isAdmin
},
community: (state, community) => {
state.community = community
},
@ -57,6 +60,7 @@ export const actions = {
commit('newsletterState', data.klickTipp.newsletterState)
commit('hasElopage', data.hasElopage)
commit('publisherId', data.publisherId)
commit('isAdmin', data.isAdmin)
},
logout: ({ commit, state }) => {
commit('token', null)
@ -69,6 +73,7 @@ export const actions = {
commit('newsletterState', null)
commit('hasElopage', false)
commit('publisherId', null)
commit('isAdmin', false)
localStorage.clear()
},
}
@ -87,7 +92,7 @@ export const store = new Vuex.Store({
username: '',
description: '',
token: null,
isAdmin: true, // TODO implement this properly
isAdmin: false,
coinanimation: true,
newsletterState: null,
community: {