mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
fece460051
* move email templates to server
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
HttpCode,
|
|
HttpStatus,
|
|
NotFoundException,
|
|
Post,
|
|
Req,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { LoginDto } from './dto/login.dto';
|
|
import { AuthService } from './services/auth.service';
|
|
import { CreateUserDto } from './dto/create-user.dto';
|
|
import { SetupGuard } from './guards/setup.guard';
|
|
import { EnvironmentService } from '../../integrations/environment/environment.service';
|
|
import { CreateAdminUserDto } from './dto/create-admin-user.dto';
|
|
import { ChangePasswordDto } from './dto/change-password.dto';
|
|
import { AuthUser } from '../../decorators/auth-user.decorator';
|
|
import { User, Workspace } from '@docmost/db/types/entity.types';
|
|
import { AuthWorkspace } from '../../decorators/auth-workspace.decorator';
|
|
import { JwtAuthGuard } from '../../guards/jwt-auth.guard';
|
|
|
|
@Controller('auth')
|
|
export class AuthController {
|
|
constructor(
|
|
private authService: AuthService,
|
|
private environmentService: EnvironmentService,
|
|
) {}
|
|
|
|
@HttpCode(HttpStatus.OK)
|
|
@Post('login')
|
|
async login(@Req() req, @Body() loginInput: LoginDto) {
|
|
return this.authService.login(loginInput, req.raw.workspaceId);
|
|
}
|
|
|
|
@HttpCode(HttpStatus.OK)
|
|
@Post('register')
|
|
async register(@Req() req, @Body() createUserDto: CreateUserDto) {
|
|
return this.authService.register(createUserDto, req.raw.workspaceId);
|
|
}
|
|
|
|
@UseGuards(SetupGuard)
|
|
@HttpCode(HttpStatus.OK)
|
|
@Post('setup')
|
|
async setupWorkspace(
|
|
@Req() req,
|
|
@Body() createAdminUserDto: CreateAdminUserDto,
|
|
) {
|
|
if (this.environmentService.isCloud()) throw new NotFoundException();
|
|
return this.authService.setup(createAdminUserDto);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
@HttpCode(HttpStatus.OK)
|
|
@Post('change-password')
|
|
async changePassword(
|
|
@Body() dto: ChangePasswordDto,
|
|
@AuthUser() user: User,
|
|
@AuthWorkspace() workspace: Workspace,
|
|
) {
|
|
return this.authService.changePassword(dto, user.id, workspace.id);
|
|
}
|
|
}
|