verifizierung
This commit is contained in:
@@ -14,6 +14,7 @@ import type { AuthenticatedRequest } from './auth.types';
|
||||
import { AuthService } from './auth.service';
|
||||
import { LoginDto } from './dto/login.dto';
|
||||
import { RefreshTokenDto } from './dto/refresh-token.dto';
|
||||
import { ResendVerificationDto } from './dto/resend-verification.dto';
|
||||
import { RegisterDto } from './dto/register.dto';
|
||||
import { JwtAuthGuard } from './jwt-auth.guard';
|
||||
|
||||
@@ -31,6 +32,12 @@ export class AuthController {
|
||||
return this.authService.verifyEmail(token);
|
||||
}
|
||||
|
||||
@Post('resend-verification')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
resendVerification(@Body() resendVerificationDto: ResendVerificationDto) {
|
||||
return this.authService.resendVerificationEmail(resendVerificationDto);
|
||||
}
|
||||
|
||||
@Post('login')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
login(@Body() loginDto: LoginDto) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import { Repository } from 'typeorm';
|
||||
import { LoginDto } from './dto/login.dto';
|
||||
import { RegisterDto } from './dto/register.dto';
|
||||
import { RefreshTokenDto } from './dto/refresh-token.dto';
|
||||
import { ResendVerificationDto } from './dto/resend-verification.dto';
|
||||
import {
|
||||
AuthTokenResponse,
|
||||
AuthTokens,
|
||||
@@ -106,6 +107,29 @@ export class AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
async resendVerificationEmail(
|
||||
resendVerificationDto: ResendVerificationDto,
|
||||
): Promise<{ message: string }> {
|
||||
const email = this.normalizeEmail(resendVerificationDto.email);
|
||||
const message =
|
||||
'Falls ein unverifiziertes Konto mit dieser E-Mail existiert, wurde eine neue Verifizierungsmail versendet.';
|
||||
const user = await this.usersRepository.findOne({ where: { email } });
|
||||
|
||||
if (!user || user.verified) {
|
||||
return { message };
|
||||
}
|
||||
|
||||
user.verificationToken = this.createToken();
|
||||
const savedUser = await this.usersRepository.save(user);
|
||||
|
||||
this.eventEmitter.emit(AppEvents.UserRegistered, {
|
||||
email: savedUser.email,
|
||||
verificationUrl: this.createVerificationUrl(savedUser.verificationToken!),
|
||||
});
|
||||
|
||||
return { message };
|
||||
}
|
||||
|
||||
async login(loginDto: LoginDto): Promise<AuthTokenResponse> {
|
||||
const email = this.normalizeEmail(loginDto.email);
|
||||
const password = this.requirePassword(loginDto.password);
|
||||
|
||||
3
listify-api/src/auth/dto/resend-verification.dto.ts
Normal file
3
listify-api/src/auth/dto/resend-verification.dto.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export class ResendVerificationDto {
|
||||
email?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user