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.A5AuthnPhoneController = 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_phone_auth_guard_1 = require("./a5-authn-phone.auth.guard"); const phone_login_req_dto_1 = require("./dtos/phone.login.req.dto"); const phone_send_req_dto_1 = require("./dtos/phone.send.req.dto"); const phone_verify_req_dto_1 = require("./dtos/phone.verify.req.dto"); let A5AuthnPhoneController = class A5AuthnPhoneController { constructor(service) { this.service = service; } async login(body, userPayload) { return this.service.getTokens(userPayload); } async send(body) { await this.service.sendPhone(body.phone); } async verify(body) { await this.service.verifyPhone(body.phone, body.code); } }; exports.A5AuthnPhoneController = A5AuthnPhoneController; __decorate([ (0, common_1.Post)('login'), (0, common_1.UseGuards)(a5_authn_phone_auth_guard_1.A5AuthnPhoneAuthGuard), (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", [phone_login_req_dto_1.A5AuthnPhoneLoginReqDto, Object]), __metadata("design:returntype", Promise) ], A5AuthnPhoneController.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", [phone_send_req_dto_1.A5AuthnPhoneSendReqDto]), __metadata("design:returntype", Promise) ], A5AuthnPhoneController.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", [phone_verify_req_dto_1.A5AuthnPhoneVerifyReqDto]), __metadata("design:returntype", Promise) ], A5AuthnPhoneController.prototype, "verify", null); exports.A5AuthnPhoneController = A5AuthnPhoneController = __decorate([ (0, swagger_1.ApiTags)('Authentication'), (0, common_1.Controller)('auth/phone'), __param(0, (0, common_1.Inject)(const_1.A5_AUTHN_SERVICE_TOKEN)), __metadata("design:paramtypes", [Object]) ], A5AuthnPhoneController); //# sourceMappingURL=a5-authn-phone.controller.js.map