|
|
@ -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, |
|
|
|