/** * @file 认证模块Controller层实现 * @author AI Assistant * @date 2024-12-19 * @lastEditor AI Assistant * @lastEditTime 2025-01-07 * @description 认证模块的路由控制器,处理用户注册、邮箱激活、用户登录等请求 */ import { Elysia } from 'elysia'; import { RegisterSchema, ActivateSchema, LoginSchema } from './auth.schema'; import { RegisterResponses, ActivateResponses, LoginResponses } from './auth.response'; import { authService } from './auth.service'; import { tags } from '@/modules/tags'; /** * 认证控制器 * @description 处理用户认证相关的HTTP请求 */ export const authController = new Elysia() /** * 用户注册接口 * @route POST /api/auth/register * @description 用户注册,包含验证码验证、用户名邮箱唯一性检查等 * @param body RegisterRequest 注册请求参数 * @returns RegisterSuccessResponse | RegisterErrorResponse */ .post( '/register', ({ body, set }) => authService.register(body), { body: RegisterSchema, detail: { summary: '用户注册', description: '用户注册接口,需要提供用户名、邮箱、密码和验证码', tags: [tags.auth], operationId: 'registerUser', }, response: RegisterResponses, } ) /** * 邮箱激活接口 * @route POST /api/auth/activate * @description 通过激活Token激活用户邮箱 * @param body ActivateRequest 激活请求参数 * @returns ActivateSuccessResponse | ActivateErrorResponse */ .post( '/activate', ({ body, set }) => authService.activate(body), { body: ActivateSchema, detail: { summary: '邮箱激活', description: '通过激活Token激活用户邮箱,激活成功后用户状态将变为active', tags: [tags.auth], operationId: 'activateUser', }, response: ActivateResponses, } ) /** * 用户登录接口 * @route POST /api/auth/login * @description 用户登录,支持用户名或邮箱登录,返回JWT令牌 * @param body LoginRequest 登录请求参数 * @returns LoginSuccessResponse | LoginErrorResponse */ .post( '/login', ({ body, set }) => authService.login(body), { body: LoginSchema, detail: { summary: '用户登录', description: '用户登录接口,支持用户名或邮箱登录,登录成功返回JWT访问令牌和刷新令牌', tags: [tags.auth], operationId: 'loginUser', }, response: LoginResponses, } );