UNPKG

@kokkoro/web

Version:

Create web serve for kokkoro.

31 lines (30 loc) 1.19 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.verifyRegister = exports.verifyLogin = void 0; const app_1 = require("../app"); const user_service_1 = __importDefault(require("../service/user.service")); async function verifyLogin(ctx, next) { const { account, password } = ctx.request.body ?? {}; const id = user_service_1.default.loginUser(account, password); if (!id) { throw new app_1.SourceError(403, '用户名或密码错误'); } ctx.request.body.id = id; await next(); } exports.verifyLogin = verifyLogin; async function verifyRegister(ctx, next) { const { account, password } = ctx.request.body ?? {}; if (!account || !password) { throw new app_1.SourceError(403, '用户名与密码不能为空'); } const has_user = await user_service_1.default.hasUser(account); if (has_user) { throw new app_1.SourceError(409, '用户名已被注册'); } await next(); } exports.verifyRegister = verifyRegister;