UNPKG

@hz-9/a5-authn

Version:

Authentication module for the @hz-9/a5-* series of repositories.

83 lines 4.72 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.A5AuthnEmailController = void 0; const a5_crud_zod_1 = require("@hz-9/a5-crud-zod"); const common_1 = require("@nestjs/common"); const swagger_1 = require("@nestjs/swagger"); const const_1 = require("../../const"); const a5_authn_current_user_decorator_1 = require("../../decorators/a5-authn-current-user.decorator"); const dtos_1 = require("../../dtos"); const a5_authn_email_auth_guard_1 = require("./a5-authn-email.auth.guard"); const email_login_req_dto_1 = require("./dtos/email.login.req.dto"); const email_send_req_dto_1 = require("./dtos/email.send.req.dto"); const email_verify_req_dto_1 = require("./dtos/email.verify.req.dto"); let A5AuthnEmailController = class A5AuthnEmailController { constructor(service) { this.service = service; } async login(body, userPayload) { return this.service.getTokens(userPayload); } async send(body) { await this.service.sendEmail(body.email); } async verify(body) { await this.service.verifyEmail(body.email, body.code); } }; exports.A5AuthnEmailController = A5AuthnEmailController; __decorate([ (0, common_1.Post)('login'), (0, common_1.UseGuards)(a5_authn_email_auth_guard_1.A5AuthnEmailAuthGuard), (0, common_1.HttpCode)(common_1.HttpStatus.OK), (0, swagger_1.ApiOperation)({ summary: '邮箱验证码登录' }), (0, swagger_1.ApiResponse)({ status: 200, description: '登录成功', type: dtos_1.A5AuthnLoginResDto }), (0, swagger_1.ApiResponse)({ status: 400, description: '请求参数错误', type: a5_crud_zod_1.ErrorResDto }), (0, swagger_1.ApiResponse)({ status: 401, description: '邮箱或验证码错误', type: a5_crud_zod_1.ErrorResDto }), __param(0, (0, common_1.Body)()), __param(1, (0, a5_authn_current_user_decorator_1.A5AuthnCurrentUser)()), __metadata("design:type", Function), __metadata("design:paramtypes", [email_login_req_dto_1.A5AuthnEmailLoginReqDto, Object]), __metadata("design:returntype", Promise) ], A5AuthnEmailController.prototype, "login", null); __decorate([ (0, common_1.Post)('send'), (0, common_1.HttpCode)(common_1.HttpStatus.OK), (0, swagger_1.ApiOperation)({ summary: '发送邮箱验证码' }), (0, swagger_1.ApiResponse)({ status: 200, description: '发送成功', type: a5_crud_zod_1.EmptyResDto }), (0, swagger_1.ApiResponse)({ status: 400, description: '请求参数错误', type: a5_crud_zod_1.ErrorResDto }), __param(0, (0, common_1.Body)()), __metadata("design:type", Function), __metadata("design:paramtypes", [email_send_req_dto_1.A5AuthnEmailSendReqDto]), __metadata("design:returntype", Promise) ], A5AuthnEmailController.prototype, "send", null); __decorate([ (0, common_1.Get)('verify'), (0, common_1.HttpCode)(common_1.HttpStatus.OK), (0, swagger_1.ApiOperation)({ summary: '验证邮箱验证码' }), (0, swagger_1.ApiResponse)({ status: 200, description: '验证成功', type: dtos_1.A5AuthnLoginResDto }), (0, swagger_1.ApiResponse)({ status: 400, description: '请求参数错误/验证码错误', type: a5_crud_zod_1.ErrorResDto }), __param(0, (0, common_1.Body)()), __metadata("design:type", Function), __metadata("design:paramtypes", [email_verify_req_dto_1.A5AuthnEmailVerifyReqDto]), __metadata("design:returntype", Promise) ], A5AuthnEmailController.prototype, "verify", null); exports.A5AuthnEmailController = A5AuthnEmailController = __decorate([ (0, swagger_1.ApiTags)('Authentication'), (0, common_1.Controller)('auth/email'), __param(0, (0, common_1.Inject)(const_1.A5_AUTHN_SERVICE_TOKEN)), __metadata("design:paramtypes", [Object]) ], A5AuthnEmailController); //# sourceMappingURL=a5-authn-email.controller.js.map