From e49f8a3153d9d2f76d474203727f298f10a26300 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 25 Aug 2022 17:54:00 +0200 Subject: [PATCH] Created Profile page in frontend --- frontend/src/App.vue | 10 ++- frontend/src/api/auth.ts | 63 +++++++++++++++ frontend/src/api/index.ts | 1 + frontend/src/api/user.ts | 12 +++ frontend/src/router/index.ts | 22 +++-- frontend/src/views/HomeView.vue | 2 +- frontend/src/views/LoginView.vue | 4 +- frontend/src/views/ProfileView.vue | 124 +++++++++++++++++++++++++++++ frontend/src/views/SignupView.vue | 6 +- frontend/src/views/TFAView.vue | 89 +++++++++++++++++++++ 10 files changed, 319 insertions(+), 14 deletions(-) create mode 100644 frontend/src/api/user.ts create mode 100644 frontend/src/views/ProfileView.vue create mode 100644 frontend/src/views/TFAView.vue diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 924349a..089e1c2 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -27,9 +27,13 @@ provide('jwt', { diff --git a/frontend/src/api/auth.ts b/frontend/src/api/auth.ts index a2fea85..c4d9afd 100644 --- a/frontend/src/api/auth.ts +++ b/frontend/src/api/auth.ts @@ -28,3 +28,66 @@ export const refresh_token = ( token: string ): Promise => post_token('/api/auth/refresh', {}, token); + +export const change_password = ( + oldPw: string, + newPw: string, + token: string +): Promise => + post_token( + '/api/auth/change_password', + { + oldPassword: oldPw, + newPassword: newPw + }, + token + ); + +export const logout_all = ( + token: string +): Promise => + post_token('/api/auth/logout_all', {}, token); + +export function tfa_setup( + mail: false, + token: string +): Promise; +export function tfa_setup( + mail: true, + token: string +): Promise; +export function tfa_setup( + mail: boolean, + token: string +): Promise< + | Responses.Auth.RequestEmailTfaResponse + | Responses.Auth.RequestTotpTfaResponse + | Responses.ErrorResponse +> { + return post_token( + '/api/auth/2fa/setup', + { + mail + }, + token + ); +} + +export const tfa_complete = ( + mail: boolean, + code: string, + token: string +): Promise => + post_token( + '/api/auth/2fa/complete', + { + mail, + code + }, + token + ); + +export const tfa_disable = ( + token: string +): Promise => + post_token('/api/auth/2fa/disable', {}, token); diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.ts index 4790bba..29c0f1d 100644 --- a/frontend/src/api/index.ts +++ b/frontend/src/api/index.ts @@ -3,4 +3,5 @@ export { Requests, Responses } from 'dto'; export { isErrorResponse } from './base'; export * as Auth from './auth'; export * as FS from './fs'; +export * as User from './user'; export * from './util'; diff --git a/frontend/src/api/user.ts b/frontend/src/api/user.ts new file mode 100644 index 0000000..af40f3b --- /dev/null +++ b/frontend/src/api/user.ts @@ -0,0 +1,12 @@ +import { get_token, post_token } from '@/api/base'; +import { Responses } from 'dto'; + +export const get_user_info = ( + token: string +): Promise => + get_token('/api/user/info', token); + +export const delete_user = ( + token: string +): Promise => + post_token('/api/user/delete', {}, token); diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 12066ff..f006059 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -5,6 +5,8 @@ import HomeView from '@/views/HomeView.vue'; import AboutView from '@/views/AboutView.vue'; import FSView from '@/views/FSView.vue'; import SetTokenView from '@/views/SetTokenView.vue'; +import ProfileView from '@/views/ProfileView.vue'; +import TFAView from '@/views/TFAView.vue'; const routes: Array = [ { @@ -12,9 +14,18 @@ const routes: Array = [ name: 'home', component: HomeView }, + { + path: '/profile', + name: 'profile', + component: ProfileView + }, + { + path: '/profile/2fa-enable', + name: '2fa', + component: TFAView + }, { path: '/about', - name: 'about', component: AboutView }, { @@ -27,14 +38,15 @@ const routes: Array = [ name: 'signup', component: SignupView }, - { - path: '/set_token', - component: SetTokenView - }, { path: '/fs/:node_id', name: 'fs', component: FSView + }, + + { + path: '/set_token', + component: SetTokenView } ]; diff --git a/frontend/src/views/HomeView.vue b/frontend/src/views/HomeView.vue index 090de60..0140b62 100644 --- a/frontend/src/views/HomeView.vue +++ b/frontend/src/views/HomeView.vue @@ -13,7 +13,7 @@ async function start_redirect() { if (!token) return; const root = await FS.get_root(token); if (isErrorResponse(root)) return jwt.logout(); - await router.push({ + await router.replace({ name: 'fs', params: { node_id: root.rootId } }); diff --git a/frontend/src/views/LoginView.vue b/frontend/src/views/LoginView.vue index 22c0eec..be6a3d0 100644 --- a/frontend/src/views/LoginView.vue +++ b/frontend/src/views/LoginView.vue @@ -48,14 +48,14 @@ async function login() { - Login with gitlab - Signup instead? diff --git a/frontend/src/views/ProfileView.vue b/frontend/src/views/ProfileView.vue new file mode 100644 index 0000000..f4cb406 --- /dev/null +++ b/frontend/src/views/ProfileView.vue @@ -0,0 +1,124 @@ + + + + + diff --git a/frontend/src/views/SignupView.vue b/frontend/src/views/SignupView.vue index 438ef63..34491f9 100644 --- a/frontend/src/views/SignupView.vue +++ b/frontend/src/views/SignupView.vue @@ -2,9 +2,9 @@ import { ref } from 'vue'; import { Auth, isErrorResponse } from '@/api'; -let username = ref(''); -let password = ref(''); -let password2 = ref(''); +const username = ref(''); +const password = ref(''); +const password2 = ref(''); const error = ref(''); async function signup() { diff --git a/frontend/src/views/TFAView.vue b/frontend/src/views/TFAView.vue new file mode 100644 index 0000000..cf7582b --- /dev/null +++ b/frontend/src/views/TFAView.vue @@ -0,0 +1,89 @@ + + + + +