@l1go/console-core
TypeScript icon, indicating that this package has built-in type declarations

0.0.12 • Public • Published

修改configuration.ts

import * as consoleCore from '@l1go/console-core'

@Configuration({
  imports: [
    consoleCore,
  ],
  importConfigs: ["./config"],
})

this.app.use(await this.app.generateMiddleware('consoleMiddleware'));

登录接口

@Provide()
@Controller('/console')
export class ConsoleLoginController {
  @Inject()
  ctx: Context;

  @Logger()
  coreLogger: ILogger;

  @Inject()
  userService: UserService;

  @Post('/api/login')
  @Validate()
  async login(@Body(ALL) user: UserLoginInput) {
    try {
      const result = await this.userService.login(user);
      if (result) {
        let u = {
          role: 'user'
        }
        this.ctx.session.user = u
        return { success: true, message: "OK" };
      }
      return { success: false, message: result.message };
    } catch (error) {
      if (error instanceof ValidationError) {
        return { success: false, message: "Params Validation Error", data: {} };
      } else {
        this.coreLogger.error(error)
        return { success: false, message: "Unknown Errors", data: {} };
      }
    }
  }
}

Readme

Keywords

Package Sidebar

Install

npm i @l1go/console-core

Weekly Downloads

1

Version

0.0.12

License

MIT

Unpacked Size

3.07 MB

Total Files

25

Last publish

Collaborators

  • roy2an