diff --git a/backend/src/apis/humhub/HumHubClient.ts b/backend/src/apis/humhub/HumHubClient.ts index 6fe04e719..42fe598c2 100644 --- a/backend/src/apis/humhub/HumHubClient.ts +++ b/backend/src/apis/humhub/HumHubClient.ts @@ -1,4 +1,3 @@ -import { User } from '@entity/User' import { SignJWT } from 'jose' import { IRequestOptions, IRestResponse, RestClient } from 'typed-rest-client' @@ -6,6 +5,7 @@ import { CONFIG } from '@/config' import { LogError } from '@/server/LogError' import { backendLogger as logger } from '@/server/logger' +import { PostUserLoggingView } from './logging/PostUserLogging.view' import { GetUser } from './model/GetUser' import { PostUser } from './model/PostUser' import { UsersResponse } from './model/UsersResponse' @@ -59,9 +59,8 @@ export class HumHubClient { return token } - public async createAutoLoginUrl(user: User) { + public async createAutoLoginUrl(username: string) { 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`) const token = await new SignJWT({ username }) .setProtectedHeader({ alg: 'HS256' }) @@ -109,6 +108,11 @@ export class HumHubClient { return this.restClient.get('/api/v1/user/get-by-email', options) } + public async userByUsernameAsync(username: string): Promise> { + const options = await this.createRequestOptions({ username }) + return this.restClient.get('/api/v1/user/get-by-username', options) + } + /** * get user by username * https://marketplace.humhub.com/module/rest/docs/html/user.html#tag/User/paths/~1user~1get-by-username/get @@ -130,7 +134,7 @@ export class HumHubClient { * @param user for saving on humhub instance */ public async createUser(user: PostUser): Promise { - logger.info('create new humhub user', user) + logger.info('create new humhub user', new PostUserLoggingView(user)) const options = await this.createRequestOptions() try { const response = await this.restClient.create('/api/v1/user', user, options) @@ -153,7 +157,7 @@ export class HumHubClient { * @returns updated user object on success */ public async updateUser(user: PostUser, humhubUserId: number): Promise { - logger.info('update humhub user', user) + logger.info('update humhub user', new PostUserLoggingView(user)) const options = await this.createRequestOptions() const response = await this.restClient.update( `/api/v1/user/${humhubUserId}`, diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index a5309f3fd..056cf15c2 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -168,7 +168,7 @@ export class UserResolver { let humhubUserPromise: Promise> | undefined const klicktippStatePromise = getKlicktippState(dbUser.emailContact.email) if (CONFIG.HUMHUB_ACTIVE && dbUser.humhubAllowed) { - humhubUserPromise = HumHubClient.getInstance()?.userByEmailAsync(email) + humhubUserPromise = HumHubClient.getInstance()?.userByUsernameAsync(email) } if (dbUser.passwordEncryptionType !== PasswordEncryptionType.GRADIDO_ID) { @@ -726,7 +726,15 @@ export class UserResolver { if (!humhubClient) { throw new LogError('cannot create humhub client') } - return await humhubClient.createAutoLoginUrl(dbUser) + const username = dbUser.alias ?? dbUser.gradidoID + const humhubUser = await humhubClient.userByUsername(username) + if (!humhubUser) { + throw new LogError("user don't exist (any longer) on humhub") + } + if (humhubUser.account.status !== 1) { + throw new LogError('user status is not 1', humhubUser.account.status) + } + return await humhubClient.createAutoLoginUrl(username) } @Authorized([RIGHTS.SEARCH_ADMIN_USERS]) diff --git a/backend/src/graphql/resolver/util/syncHumhub.ts b/backend/src/graphql/resolver/util/syncHumhub.ts index 7a964331c..73ec755ee 100644 --- a/backend/src/graphql/resolver/util/syncHumhub.ts +++ b/backend/src/graphql/resolver/util/syncHumhub.ts @@ -28,7 +28,7 @@ export async function syncHumhub( return } logger.debug('retrieve user from humhub') - const humhubUser = await humhubClient.userByEmail(user.emailContact.email) + const humhubUser = await humhubClient.userByUsername(user.alias ?? user.gradidoID) const humhubUsers = new Map() if (humhubUser) { humhubUsers.set(user.emailContact.email, humhubUser) diff --git a/frontend/src/pages/Circles.vue b/frontend/src/pages/Circles.vue index 7e23c89c3..ab91b9fe2 100644 --- a/frontend/src/pages/Circles.vue +++ b/frontend/src/pages/Circles.vue @@ -59,8 +59,11 @@ export default { this.enableButton = true }) .catch(() => { - this.toastError('authenticateHumhubAutoLogin failed!') + // this.toastError('authenticateHumhubAutoLogin failed!') this.enableButton = true + // something went wrong with login link so we disable humhub + this.$store.commit('humhubAllowed', false) + this.$router.push('/settings/extern') }) }, }, diff --git a/frontend/src/pages/Settings.vue b/frontend/src/pages/Settings.vue index d517feb20..8a0a39f8d 100644 --- a/frontend/src/pages/Settings.vue +++ b/frontend/src/pages/Settings.vue @@ -80,9 +80,9 @@
- +
{{ $t('settings.allow-community-services') }}
-
+
{{ $t('Humhub.title') }}
@@ -113,7 +113,7 @@
-
+
{{ $t('GMS.title') }}
@@ -129,7 +129,7 @@ />
-
{{ $t('GMS.desc') }}
+
{{ $t('GMS.desc') }}
@@ -287,6 +287,9 @@ export default { }