2023-11-09 10:14:15 -05:00
|
|
|
import { ApiProperty } from '@nestjs/swagger';
|
|
|
|
|
import { Transform } from 'class-transformer';
|
|
|
|
|
import { IsEmail, IsNotEmpty, IsString, MinLength } from 'class-validator';
|
2025-04-10 15:53:21 +01:00
|
|
|
import { AuthApiKey, AuthSession, AuthSharedLink, AuthUser, UserAdmin } from 'src/database';
|
2024-10-17 13:17:32 -04:00
|
|
|
import { ImmichCookie } from 'src/enum';
|
2024-07-10 13:58:06 +02:00
|
|
|
import { toEmail } from 'src/validation';
|
2023-11-09 10:14:15 -05:00
|
|
|
|
2024-04-19 11:19:23 -04:00
|
|
|
export type CookieResponse = {
|
|
|
|
|
isSecure: boolean;
|
|
|
|
|
values: Array<{ key: ImmichCookie; value: string }>;
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-09 23:34:12 -05:00
|
|
|
export class AuthDto {
|
2025-02-12 15:23:08 -05:00
|
|
|
user!: AuthUser;
|
2023-12-09 23:34:12 -05:00
|
|
|
|
2025-01-10 14:02:12 -05:00
|
|
|
apiKey?: AuthApiKey;
|
2025-02-12 15:23:08 -05:00
|
|
|
sharedLink?: AuthSharedLink;
|
|
|
|
|
session?: AuthSession;
|
2023-11-09 10:14:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class LoginCredentialDto {
|
|
|
|
|
@IsEmail({ require_tld: false })
|
2024-07-10 13:58:06 +02:00
|
|
|
@Transform(toEmail)
|
2023-11-09 10:14:15 -05:00
|
|
|
@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;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-10 15:53:21 +01:00
|
|
|
export function mapLoginResponse(entity: UserAdmin, accessToken: string): LoginResponseDto {
|
2023-11-09 10:14:15 -05:00
|
|
|
return {
|
2024-04-19 11:19:23 -04:00
|
|
|
accessToken,
|
2023-11-09 10:14:15 -05:00
|
|
|
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 OAuthCallbackDto {
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
@IsString()
|
|
|
|
|
@ApiProperty()
|
|
|
|
|
url!: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class OAuthConfigDto {
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
@IsString()
|
|
|
|
|
redirectUri!: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class OAuthAuthorizeResponseDto {
|
|
|
|
|
url!: string;
|
|
|
|
|
}
|