mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
update frontend logic for humhub link
This commit is contained in:
parent
adaece0efe
commit
bf784616af
@ -1,3 +1,4 @@
|
||||
import { User } from '@entity/User'
|
||||
import { SignJWT } from 'jose'
|
||||
import { IRequestOptions, RestClient } from 'typed-rest-client'
|
||||
|
||||
@ -8,7 +9,6 @@ import { backendLogger as logger } from '@/server/logger'
|
||||
import { GetUser } from './model/GetUser'
|
||||
import { PostUser } from './model/PostUser'
|
||||
import { UsersResponse } from './model/UsersResponse'
|
||||
import { User } from '@entity/User'
|
||||
|
||||
/**
|
||||
* HumHubClient as singleton class
|
||||
@ -59,7 +59,7 @@ export class HumHubClient {
|
||||
return token
|
||||
}
|
||||
|
||||
public static async createAutoLoginUrl(user: User) {
|
||||
public async createAutoLoginUrl(user: User) {
|
||||
const secret = new TextEncoder().encode(CONFIG.HUMHUB_JWT_KEY)
|
||||
const username = user.alias ?? user.gradidoID
|
||||
logger.info(`user ${username} as username for humhub auto-login`)
|
||||
@ -68,7 +68,8 @@ export class HumHubClient {
|
||||
.setIssuedAt()
|
||||
.setExpirationTime('2m')
|
||||
.sign(secret)
|
||||
return `${CONFIG.HUMHUB_API_URL}user/auth/login?jwt=${token}`
|
||||
|
||||
return `${CONFIG.HUMHUB_API_URL}user/auth/external?authclient=jwt&jwt=${token}`
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,6 +104,21 @@ export class HumHubClient {
|
||||
return response.result
|
||||
}
|
||||
|
||||
/**
|
||||
* get user by username
|
||||
* https://marketplace.humhub.com/module/rest/docs/html/user.html#tag/User/paths/~1user~1get-by-username/get
|
||||
* @param username for user search
|
||||
* @returns user object if found
|
||||
*/
|
||||
public async userByUsername(username: string): Promise<GetUser | null> {
|
||||
const options = await this.createRequestOptions({ username })
|
||||
const response = await this.restClient.get<GetUser>('/api/v1/user/get-by-username', options)
|
||||
if (response.statusCode === 404) {
|
||||
return null
|
||||
}
|
||||
return response.result
|
||||
}
|
||||
|
||||
/**
|
||||
* create user
|
||||
* https://marketplace.humhub.com/module/rest/docs/html/user.html#tag/User/paths/~1user/post
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable camelcase */
|
||||
import { User } from '@entity/User'
|
||||
|
||||
import { convertGradidoLanguageToHumhub } from '@/apis/humhub/convertLanguage'
|
||||
|
||||
@ -709,7 +709,11 @@ export class UserResolver {
|
||||
async authenticateCirclesAutoLogin(@Ctx() context: Context): Promise<string> {
|
||||
logger.info(`authenticateCirclesAutoLogin()...`)
|
||||
const dbUser = getUser(context)
|
||||
return await HumHubClient.createAutoLoginUrl(dbUser)
|
||||
const humhubClient = HumHubClient.getInstance()
|
||||
if (!humhubClient) {
|
||||
throw new LogError('cannot create humhub client')
|
||||
}
|
||||
return await humhubClient.createAutoLoginUrl(dbUser)
|
||||
}
|
||||
|
||||
@Authorized([RIGHTS.SEARCH_ADMIN_USERS])
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
<b-button
|
||||
v-if="this.humhubAllowed"
|
||||
variant="gradido"
|
||||
:href="this.humhubUri"
|
||||
@click="authenticateCirclesAutoLogin"
|
||||
target="_blank"
|
||||
>
|
||||
{{ $t('circles.button') }}
|
||||
@ -36,7 +36,7 @@ export default {
|
||||
name: 'Circles',
|
||||
data() {
|
||||
return {
|
||||
humhubUri: 'not initialized',
|
||||
humhubUri: null,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -46,20 +46,19 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
async authenticateCirclesAutoLogin() {
|
||||
this.humhubUri = null
|
||||
this.$apollo
|
||||
.query({
|
||||
query: authenticateCirclesAutoLogin,
|
||||
fetchPolicy: 'network-only',
|
||||
})
|
||||
.then(async (result) => {
|
||||
this.humhubUri = result.data.authenticateCirclesAutoLogin
|
||||
window.open(result.data.authenticateCirclesAutoLogin, '_blank')
|
||||
})
|
||||
.catch(() => {
|
||||
this.toastError('authenticateCirclesAutoLogin failed!')
|
||||
})
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.authenticateCirclesAutoLogin()
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user