first commit
This commit is contained in:
139
myteamwallet_backend/src/auth/auth.controller.ts
Normal file
139
myteamwallet_backend/src/auth/auth.controller.ts
Normal file
@@ -0,0 +1,139 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
Request,
|
||||
Post,
|
||||
UseGuards,
|
||||
Patch,
|
||||
Delete,
|
||||
UseInterceptors,
|
||||
ClassSerializerInterceptor,
|
||||
SerializeOptions,
|
||||
} from '@nestjs/common';
|
||||
import { AuthService } from './auth.service';
|
||||
import { AuthEmailLoginDto } from './dto/auth-email-login.dto';
|
||||
import { AuthForgotPasswordDto } from './dto/auth-forgot-password.dto';
|
||||
import { AuthConfirmEmailDto } from './dto/auth-confirm-email.dto';
|
||||
import { AuthResetPasswordDto } from './dto/auth-reset-password.dto';
|
||||
import { AuthUpdateDto } from './dto/auth-update.dto';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import {
|
||||
ApiTags,
|
||||
ApiBearerAuth,
|
||||
ApiOperation,
|
||||
ApiOkResponse,
|
||||
} from '@nestjs/swagger';
|
||||
import { CreateInviteDTO } from './dto/create-invite.dto';
|
||||
|
||||
@ApiTags('Auth')
|
||||
@Controller({
|
||||
path: 'auth',
|
||||
version: '1',
|
||||
})
|
||||
@UseInterceptors(ClassSerializerInterceptor)
|
||||
export class AuthController {
|
||||
constructor(public service: AuthService) {}
|
||||
|
||||
@Post('email/login')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
public async login(@Body() loginDto: AuthEmailLoginDto) {
|
||||
return this.service.validateLogin(loginDto);
|
||||
}
|
||||
|
||||
@Post('admin/email/login')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
public async adminLogin(@Body() loginDTO: AuthEmailLoginDto) {
|
||||
return this.service.validateLogin(loginDTO);
|
||||
}
|
||||
|
||||
@Post('email/register')
|
||||
@HttpCode(HttpStatus.CREATED)
|
||||
async register(@Body() createUserDto: any) {
|
||||
return this.service.register(createUserDto);
|
||||
}
|
||||
|
||||
@Post('email/confirm')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async confirmEmail(@Body() confirmEmailDto: AuthConfirmEmailDto) {
|
||||
return this.service.confirmEmail(confirmEmailDto.hash);
|
||||
}
|
||||
|
||||
@Post('forgot/password')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async forgotPassword(@Body() forgotPasswordDto: AuthForgotPasswordDto) {
|
||||
return this.service.forgotPassword(forgotPasswordDto.email);
|
||||
}
|
||||
|
||||
@Post('reset/password')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async resetPassword(@Body() resetPasswordDto: AuthResetPasswordDto) {
|
||||
return this.service.resetPassword(
|
||||
resetPasswordDto.hash,
|
||||
resetPasswordDto.password,
|
||||
);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@SerializeOptions({
|
||||
groups: ['exposeProvider'],
|
||||
})
|
||||
@Get('me')
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
@HttpCode(HttpStatus.OK)
|
||||
public me(@Request() request: Request) {
|
||||
return this.service.me(request.headers['authorization']);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@Patch('me')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@HttpCode(HttpStatus.OK)
|
||||
public async update(@Request() request, @Body() userDto: AuthUpdateDto) {
|
||||
return this.service.update(request.user, userDto);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@Delete('me')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@HttpCode(HttpStatus.OK)
|
||||
public async delete(@Request() request) {
|
||||
return this.service.softDelete(request.user);
|
||||
}
|
||||
|
||||
@ApiOperation({
|
||||
summary: 'Erstellt Registrierungstoken',
|
||||
description:
|
||||
'Encoded den JWT Token für eine Einladung für eine neue Registrierung. Team- und Rollen-Infos müssen da sein. Der Token ist dann 30 Tage gültig.',
|
||||
})
|
||||
@ApiOkResponse({
|
||||
description: 'JWT Token',
|
||||
isArray: false,
|
||||
type: 'string',
|
||||
})
|
||||
@Post('invite')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
public getInvite(
|
||||
@Body()
|
||||
invite: any,
|
||||
) {
|
||||
return this.service.createTeamInvite(invite);
|
||||
}
|
||||
|
||||
@ApiOperation({
|
||||
summary: 'Verifiziert Registrierungstoken',
|
||||
description:
|
||||
'Decoded und prüft den JWT Token einer Einladung für die Registrierung',
|
||||
})
|
||||
@ApiOkResponse({
|
||||
description: 'Object mit teamName, teamId, roleName, roleId',
|
||||
isArray: false,
|
||||
type: CreateInviteDTO,
|
||||
})
|
||||
@Post('verify-invite')
|
||||
public verifyInvite(@Body() body: any) {
|
||||
return this.service.getTeamFromInvite(body.token);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user