feat: complete cmpp platform phases 0-5

This commit is contained in:
hectorzhao
2026-07-01 13:22:04 +08:00
parent 824a8b334f
commit ee926fea04
86 changed files with 10490 additions and 14 deletions
+14
View File
@@ -0,0 +1,14 @@
import { Body, Controller, Post } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { AuthService, LoginDto } from './auth.service';
@ApiTags('auth')
@Controller('client/auth')
export class AuthController {
constructor(private readonly auth: AuthService) {}
@Post('login')
login(@Body() body: LoginDto) {
return this.auth.login(body);
}
}
+11
View File
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { UsersModule } from '../users/users.module';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
@Module({
imports: [UsersModule],
controllers: [AuthController],
providers: [AuthService],
})
export class AuthModule {}
+30
View File
@@ -0,0 +1,30 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { hashPassword, UsersService } from '../users/users.service';
export interface LoginDto {
username: string;
password: string;
}
@Injectable()
export class AuthService {
constructor(private readonly users: UsersService) {}
async login(data: LoginDto) {
const user = await this.users.findByUsername(data.username);
if (!user || user.passwordHash !== hashPassword(data.password) || user.status !== 'active') {
throw new UnauthorizedException('Invalid username or password');
}
return {
accessToken: `dev-token-${user.id}`,
tokenType: 'Bearer',
user: {
id: user.id,
tenantId: user.tenantId,
username: user.username,
displayName: user.displayName,
},
};
}
}