diff --git a/apps/api/src/app/auth/auth.module.ts b/apps/api/src/app/auth/auth.module.ts index b25e4c18b..cb5441838 100644 --- a/apps/api/src/app/auth/auth.module.ts +++ b/apps/api/src/app/auth/auth.module.ts @@ -3,6 +3,7 @@ import { WebAuthService } from '@ghostfolio/api/app/auth/web-auth.service'; import { SubscriptionModule } from '@ghostfolio/api/app/subscription/subscription.module'; import { UserModule } from '@ghostfolio/api/app/user/user.module'; import { ConfigurationModule } from '@ghostfolio/api/services/configuration.module'; +import { PropertyModule } from '@ghostfolio/api/services/property/property.module'; import { PrismaModule } from '@ghostfolio/api/services/prisma.module'; import { Module } from '@nestjs/common'; import { JwtModule } from '@nestjs/jwt'; @@ -22,7 +23,8 @@ import { JwtStrategy } from './jwt.strategy'; }), PrismaModule, SubscriptionModule, - UserModule + UserModule, + PropertyModule ], providers: [ AuthDeviceService, diff --git a/apps/api/src/app/auth/auth.service.ts b/apps/api/src/app/auth/auth.service.ts index 3178ce9ac..79481ebfd 100644 --- a/apps/api/src/app/auth/auth.service.ts +++ b/apps/api/src/app/auth/auth.service.ts @@ -1,15 +1,18 @@ import { UserService } from '@ghostfolio/api/app/user/user.service'; import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; +import { PropertyService } from '@ghostfolio/api/services/property/property.service'; import { Injectable, InternalServerErrorException } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import { Provider } from '@prisma/client'; import { ValidateOAuthLoginParams } from './interfaces/interfaces'; +import { PROPERTY_DISABLE_USER_SIGNUP } from '@ghostfolio/common/config'; @Injectable() export class AuthService { public constructor( private readonly configurationService: ConfigurationService, + private readonly propertyService: PropertyService, private readonly jwtService: JwtService, private readonly userService: UserService ) {} @@ -50,6 +53,19 @@ export class AuthService { }); if (!user) { + // Guard new user registration based on config property + if (this.configurationService.get('ENABLE_FEATURE_USER_SIGNUP_CONTROL')) { + const isUserSignupDisabled = (await this.propertyService.getByKey( + PROPERTY_DISABLE_USER_SIGNUP + )) as boolean; + + if(isUserSignupDisabled){ + throw new InternalServerErrorException( + 'validateInternetIdentityLogin', + 'Not Allowed' + ); + } + } // Create new user if not found user = await this.userService.createUser({ provider, @@ -78,6 +94,19 @@ export class AuthService { }); if (!user) { + // Guard new user registration based on config property + if (this.configurationService.get('ENABLE_FEATURE_USER_SIGNUP_CONTROL')) { + const isUserSignupDisabled = (await this.propertyService.getByKey( + PROPERTY_DISABLE_USER_SIGNUP + )) as boolean; + + if(isUserSignupDisabled){ + throw new InternalServerErrorException( + 'validateInternetIdentityLogin', + 'Not Allowed' + ); + } + } // Create new user if not found user = await this.userService.createUser({ provider, diff --git a/apps/api/src/app/user/user.service.ts b/apps/api/src/app/user/user.service.ts index 8b7a7dedd..7ca22630a 100644 --- a/apps/api/src/app/user/user.service.ts +++ b/apps/api/src/app/user/user.service.ts @@ -165,6 +165,12 @@ export class UserService { currentPermissions.push(permissions.reportDataGlitch); } + if (this.configurationService.get('ENABLE_FEATURE_USER_SIGNUP_CONTROL')) { + if (hasRole(user, Role.ADMIN)) { + currentPermissions.push(permissions.toggleUserSignupMode); + } + } + if (this.configurationService.get('ENABLE_FEATURE_READ_ONLY_MODE')) { if (hasRole(user, Role.ADMIN)) { currentPermissions.push(permissions.toggleReadOnlyMode); @@ -185,12 +191,6 @@ export class UserService { } } - if (this.configurationService.get('ENABLE_FEATURE_USER_SIGNUP_CONTROL')) { - if (hasRole(user, Role.ADMIN)) { - currentPermissions.push(permissions.toggleUserSignupMode); - } - } - user.Account = sortBy(user.Account, (account) => { return account.name; }); @@ -224,6 +224,7 @@ export class UserService { } public async createUser(data: Prisma.UserCreateInput): Promise { + if (!data?.provider) { data.provider = 'ANONYMOUS'; } diff --git a/apps/client/src/app/components/header/header.component.html b/apps/client/src/app/components/header/header.component.html index 336bc6d24..3398b99d9 100644 --- a/apps/client/src/app/components/header/header.component.html +++ b/apps/client/src/app/components/header/header.component.html @@ -289,7 +289,8 @@ Sign in
-