diff --git a/frontend/src/api/admin.ts b/frontend/src/api/admin.ts index d3fdfc1..0c8ef35 100644 --- a/frontend/src/api/admin.ts +++ b/frontend/src/api/admin.ts @@ -8,7 +8,7 @@ export const set_role = ( user: number, role: UserRole, token: string -): Promise => +): Promise => post_token( '/api/admin/set_role', { @@ -21,7 +21,7 @@ export const set_role = ( export const logout = ( user: number, token: string -): Promise => +): Promise => post_token( '/api/admin/logout', { @@ -33,7 +33,7 @@ export const logout = ( export const delete_user = ( user: number, token: string -): Promise => +): Promise => post_token( '/api/admin/delete', { @@ -45,7 +45,7 @@ export const delete_user = ( export const disable_tfa = ( user: number, token: string -): Promise => +): Promise => post_token( '/api/admin/disable_2fa', { diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index f006059..b045c4c 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -7,6 +7,7 @@ import FSView from '@/views/FSView.vue'; import SetTokenView from '@/views/SetTokenView.vue'; import ProfileView from '@/views/ProfileView.vue'; import TFAView from '@/views/TFAView.vue'; +import AdminView from '@/views/AdminView.vue'; const routes: Array = [ { @@ -24,6 +25,10 @@ const routes: Array = [ name: '2fa', component: TFAView }, + { + path: '/admin', + component: AdminView + }, { path: '/about', component: AboutView diff --git a/frontend/src/views/AdminView.vue b/frontend/src/views/AdminView.vue new file mode 100644 index 0000000..fc715ee --- /dev/null +++ b/frontend/src/views/AdminView.vue @@ -0,0 +1,109 @@ + + + + + diff --git a/src/controller/admin.ts b/src/controller/admin.ts index 1008d95..78c3039 100644 --- a/src/controller/admin.ts +++ b/src/controller/admin.ts @@ -10,22 +10,16 @@ import { import { AuthService } from 'services/auth'; import { Requests, Responses, UserRole } from 'dto'; import { Role } from 'authguards'; -import { InjectRepository } from '@nestjs/typeorm'; -import { tfaTypes, User } from 'entities'; -import { Repository } from 'typeorm'; +import { tfaTypes } from 'entities'; @Controller('api/admin') export default class AdminController { - constructor( - @InjectRepository(User) - private userRepo: Repository, - private authService: AuthService - ) {} + constructor(private authService: AuthService) {} @Role(UserRole.ADMIN) @Get('users') async getUsers(): Promise { - const users = await this.userRepo.find(); + const users = await this.authService.getUsers(); const entries = users.map( (user) => new Responses.Admin.GetUsersEntry( diff --git a/src/services/auth/base.ts b/src/services/auth/base.ts index a56f5e0..31add80 100644 --- a/src/services/auth/base.ts +++ b/src/services/auth/base.ts @@ -30,6 +30,10 @@ export default class BaseAuthService { protected fsService: FileSystemService ) {} + getUsers(): Promise { + return this.userRepo.find(); + } + async getUser(userId: number): Promise { return this.userRepo.findOneBy({ id: userId