mirror of
https://github.com/certd/certd.git
synced 2026-05-16 21:27:34 +08:00
perf: 支持passkey登录
This commit is contained in:
@@ -4,6 +4,7 @@ import { In } from 'typeorm';
|
||||
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
|
||||
import { UserService } from '../../../modules/sys/authority/service/user-service.js';
|
||||
import { BasicController } from '../../basic/code-controller.js';
|
||||
import { RoleService } from '../../../modules/sys/authority/service/role-service.js';
|
||||
|
||||
/**
|
||||
* 通知
|
||||
@@ -15,6 +16,8 @@ export class BasicUserController extends BasicController {
|
||||
service: UserService;
|
||||
@Inject()
|
||||
authService: AuthService;
|
||||
@Inject()
|
||||
roleService: RoleService;
|
||||
|
||||
getService(): UserService {
|
||||
return this.service;
|
||||
@@ -57,4 +60,15 @@ export class BasicUserController extends BasicController {
|
||||
return this.ok(users);
|
||||
}
|
||||
|
||||
@Post('/getSimpleRoles', {summary: Constants.per.authOnly})
|
||||
async getSimpleRoles() {
|
||||
const roles = await this.roleService.find({
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
});
|
||||
return this.ok(roles);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { BaseController, Constants } from '@certd/lib-server';
|
||||
import { UserService } from '../../../modules/sys/authority/service/user-service.js';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { PasskeyService } from '../../../modules/login/service/passkey-service.js';
|
||||
import { RoleService } from '../../../modules/sys/authority/service/role-service.js';
|
||||
import { UserService } from '../../../modules/sys/authority/service/user-service.js';
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -10,8 +11,14 @@ import { RoleService } from '../../../modules/sys/authority/service/role-service
|
||||
export class MineController extends BaseController {
|
||||
@Inject()
|
||||
userService: UserService;
|
||||
|
||||
@Inject()
|
||||
roleService: RoleService;
|
||||
|
||||
@Inject()
|
||||
passkeyService: PasskeyService;
|
||||
|
||||
|
||||
@Post('/info', { summary: Constants.per.authOnly })
|
||||
public async info() {
|
||||
const userId = this.getUserId();
|
||||
@@ -43,4 +50,30 @@ export class MineController extends BaseController {
|
||||
});
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post('/passkeys', { summary: Constants.per.authOnly })
|
||||
public async getPasskeys() {
|
||||
const userId = this.getUserId();
|
||||
const passkeys = await this.passkeyService.find({
|
||||
select: ['id', 'deviceName', 'registeredAt'],
|
||||
where: { userId }});
|
||||
return this.ok(passkeys);
|
||||
}
|
||||
|
||||
@Post('/unbindPasskey', { summary: Constants.per.authOnly })
|
||||
public async unbindPasskey(@Body(ALL) body: any) {
|
||||
const userId = this.getUserId();
|
||||
const passkeyId = body.id;
|
||||
|
||||
const passkey = await this.passkeyService.findOne({
|
||||
where: { id: passkeyId, userId },
|
||||
});
|
||||
|
||||
if (!passkey) {
|
||||
throw new Error('Passkey不存在');
|
||||
}
|
||||
|
||||
await this.passkeyService.delete([passkey.id]);
|
||||
return this.ok({});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user