2023-11-09 10:14:15 -05:00
|
|
|
import { UserEntity, UserTokenEntity } from '@app/infra/entities';
|
|
|
|
|
import { ApiProperty } from '@nestjs/swagger';
|
|
|
|
|
import { Transform } from 'class-transformer';
|
|
|
|
|
import { IsEmail, IsNotEmpty, IsString, MinLength } from 'class-validator';
|
|
|
|
|
|
|
|
|
|
export class AuthUserDto {
|
|
|
|
|
id!: string;
|
|
|
|
|
email!: string;
|
|
|
|
|
isAdmin!: boolean;
|
|
|
|
|
isPublicUser?: boolean;
|
|
|
|
|
sharedLinkId?: string;
|
|
|
|
|
isAllowUpload?: boolean;
|
|
|
|
|
isAllowDownload?: boolean;
|
|
|
|
|
isShowMetadata?: boolean;
|
|
|
|
|
accessTokenId?: string;
|
|
|
|
|
externalPath?: string | null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class LoginCredentialDto {
|
|
|
|
|
@IsEmail({ require_tld: false })
|
|
|
|
|
@Transform(({ value }) => value?.toLowerCase())
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
@ApiProperty({ example: 'testuser@email.com' })
|
|
|
|
|
email!: string;
|
|
|
|
|
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
@ApiProperty({ example: 'password' })
|
|
|
|
|
password!: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class LoginResponseDto {
|
|
|
|
|
accessToken!: string;
|
|
|
|
|
userId!: string;
|
|
|
|
|
userEmail!: string;
|
2023-11-11 20:03:32 -05:00
|
|
|
name!: string;
|
2023-11-09 10:14:15 -05:00
|
|
|
profileImagePath!: string;
|
|
|
|
|
isAdmin!: boolean;
|
|
|
|
|
shouldChangePassword!: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function mapLoginResponse(entity: UserEntity, accessToken: string): LoginResponseDto {
|
|
|
|
|
return {
|
|
|
|
|
accessToken: accessToken,
|
|
|
|
|
userId: entity.id,
|
|
|
|
|
userEmail: entity.email,
|
2023-11-11 20:03:32 -05:00
|
|
|
name: entity.name,
|
2023-11-09 10:14:15 -05:00
|
|
|
isAdmin: entity.isAdmin,
|
|
|
|
|
profileImagePath: entity.profileImagePath,
|
|
|
|
|
shouldChangePassword: entity.shouldChangePassword,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class LogoutResponseDto {
|
|
|
|
|
successful!: boolean;
|
|
|
|
|
redirectUri!: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class SignUpDto extends LoginCredentialDto {
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
@ApiProperty({ example: 'Admin' })
|
2023-11-11 20:03:32 -05:00
|
|
|
name!: string;
|
2023-11-09 10:14:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class ChangePasswordDto {
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
@ApiProperty({ example: 'password' })
|
|
|
|
|
password!: string;
|
|
|
|
|
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
@MinLength(8)
|
|
|
|
|
@ApiProperty({ example: 'password' })
|
|
|
|
|
newPassword!: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class ValidateAccessTokenResponseDto {
|
|
|
|
|
authStatus!: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class AuthDeviceResponseDto {
|
|
|
|
|
id!: string;
|
|
|
|
|
createdAt!: string;
|
|
|
|
|
updatedAt!: string;
|
|
|
|
|
current!: boolean;
|
|
|
|
|
deviceType!: string;
|
|
|
|
|
deviceOS!: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const mapUserToken = (entity: UserTokenEntity, currentId?: string): AuthDeviceResponseDto => ({
|
|
|
|
|
id: entity.id,
|
|
|
|
|
createdAt: entity.createdAt.toISOString(),
|
|
|
|
|
updatedAt: entity.updatedAt.toISOString(),
|
|
|
|
|
current: currentId === entity.id,
|
|
|
|
|
deviceOS: entity.deviceOS,
|
|
|
|
|
deviceType: entity.deviceType,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export class OAuthCallbackDto {
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
@IsString()
|
|
|
|
|
@ApiProperty()
|
|
|
|
|
url!: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class OAuthConfigDto {
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
@IsString()
|
|
|
|
|
redirectUri!: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @deprecated use oauth authorize */
|
|
|
|
|
export class OAuthConfigResponseDto {
|
|
|
|
|
enabled!: boolean;
|
|
|
|
|
passwordLoginEnabled!: boolean;
|
|
|
|
|
url?: string;
|
|
|
|
|
buttonText?: string;
|
|
|
|
|
autoLaunch?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class OAuthAuthorizeResponseDto {
|
|
|
|
|
url!: string;
|
|
|
|
|
}
|