Add app agreement acceptance check and validation

This commit is contained in:
faris Aljohari
2025-01-22 00:34:47 -06:00
parent 41da528963
commit 6dd6c79d87
3 changed files with 34 additions and 4 deletions

View File

@ -48,7 +48,9 @@ export class AuthService {
if (!user.isActive) { if (!user.isActive) {
throw new BadRequestException('User is not active'); throw new BadRequestException('User is not active');
} }
if (!user.hasAcceptedAppAgreement) {
throw new BadRequestException('User has not accepted app agreement');
}
const passwordMatch = await this.helperHashService.bcryptCompare( const passwordMatch = await this.helperHashService.bcryptCompare(
pass, pass,
user.password, user.password,
@ -92,6 +94,8 @@ export class AuthService {
sessionId: user.sessionId, sessionId: user.sessionId,
role: user?.role, role: user?.role,
googleCode: user.googleCode, googleCode: user.googleCode,
hasAcceptedWebAgreement: user.hasAcceptedWebAgreement,
hasAcceptedAppAgreement: user.hasAcceptedAppAgreement,
}; };
if (payload.googleCode) { if (payload.googleCode) {
const profile = await this.getProfile(payload.googleCode); const profile = await this.getProfile(payload.googleCode);

View File

@ -1,5 +1,11 @@
import { ApiProperty } from '@nestjs/swagger'; import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsNotEmpty, IsOptional, IsString } from 'class-validator'; import {
IsBoolean,
IsEmail,
IsNotEmpty,
IsOptional,
IsString,
} from 'class-validator';
import { IsPasswordStrong } from 'src/validators/password.validator'; import { IsPasswordStrong } from 'src/validators/password.validator';
export class UserSignUpDto { export class UserSignUpDto {
@ -39,7 +45,19 @@ export class UserSignUpDto {
@IsNotEmpty() @IsNotEmpty()
public lastName: string; public lastName: string;
@ApiProperty({
description: 'regionUuid',
required: false,
})
@IsString() @IsString()
@IsOptional() @IsOptional()
public regionUuid?: string; public regionUuid?: string;
@ApiProperty({
description: 'hasAcceptedAppAgreement',
required: true,
})
@IsBoolean()
@IsNotEmpty()
public hasAcceptedAppAgreement: boolean;
} }

View File

@ -46,12 +46,17 @@ export class UserAuthService {
); );
try { try {
const { regionUuid, ...rest } = userSignUpDto; const { regionUuid, hasAcceptedAppAgreement, ...rest } = userSignUpDto;
if (!hasAcceptedAppAgreement) {
throw new BadRequestException('Please accept the terms and conditions');
}
const spaceMemberRole = await this.roleService.findRoleByType( const spaceMemberRole = await this.roleService.findRoleByType(
RoleType.SPACE_MEMBER, RoleType.SPACE_MEMBER,
); );
const user = await this.userRepository.save({ const user = await this.userRepository.save({
...rest, ...rest,
appAgreementAcceptedAt: new Date(),
hasAcceptedAppAgreement,
password: hashedPassword, password: hashedPassword,
roleType: { uuid: spaceMemberRole.uuid }, roleType: { uuid: spaceMemberRole.uuid },
region: regionUuid region: regionUuid
@ -65,7 +70,7 @@ export class UserAuthService {
return user; return user;
} catch (error) { } catch (error) {
throw new BadRequestException('Failed to register user'); throw new BadRequestException(error.message || 'Failed to register user');
} }
} }
@ -116,6 +121,7 @@ export class UserAuthService {
firstName: googleUserData['given_name'], firstName: googleUserData['given_name'],
lastName: googleUserData['family_name'], lastName: googleUserData['family_name'],
password: googleUserData['email'], password: googleUserData['email'],
hasAcceptedAppAgreement: true,
}); });
} }
data.email = googleUserData['email']; data.email = googleUserData['email'];
@ -147,6 +153,8 @@ export class UserAuthService {
userId: user.uuid, userId: user.uuid,
uuid: user.uuid, uuid: user.uuid,
role: user.roleType, role: user.roleType,
hasAcceptedWebAgreement: user.hasAcceptedWebAgreement,
hasAcceptedAppAgreement: user.hasAcceptedAppAgreement,
sessionId: session[1].uuid, sessionId: session[1].uuid,
}); });
return res; return res;