From f3fe7e1de1bb4316dea5befa0dc5cfcccac56973 Mon Sep 17 00:00:00 2001 From: Nathanael Couret Date: Sun, 22 Mar 2020 11:58:24 +0100 Subject: [PATCH 1/9] #15 - Refactored navbar component --- src/components/navigation/TheNav.vue | 46 ++++++++++++++++++++++++++++ src/views/Login.vue | 24 +++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/components/navigation/TheNav.vue create mode 100644 src/views/Login.vue diff --git a/src/components/navigation/TheNav.vue b/src/components/navigation/TheNav.vue new file mode 100644 index 0000000..2a65d59 --- /dev/null +++ b/src/components/navigation/TheNav.vue @@ -0,0 +1,46 @@ + + + + diff --git a/src/views/Login.vue b/src/views/Login.vue new file mode 100644 index 0000000..7c068c2 --- /dev/null +++ b/src/views/Login.vue @@ -0,0 +1,24 @@ + + + + + From 869851fa999b2dccb6d7f3b836730c5149ea4c38 Mon Sep 17 00:00:00 2001 From: Ataww Date: Thu, 23 Apr 2020 21:51:11 +0200 Subject: [PATCH 2/9] #15 - Login card with auth token in local storage --- src/App.vue | 22 ++++++- src/components/navigation/LoginCard.vue | 63 ++++++++++++++++++ src/components/navigation/LoginDialog.vue | 80 +++++++++++++++++++++++ src/components/navigation/TheUserMenu.vue | 70 ++++++++++++++------ src/plugins/vuetify.ts | 8 ++- src/router/index.ts | 6 ++ src/store/modules/authentication.ts | 30 ++++++++- src/views/Login.vue | 64 +++++++++++++++--- 8 files changed, 308 insertions(+), 35 deletions(-) create mode 100644 src/components/navigation/LoginCard.vue create mode 100644 src/components/navigation/LoginDialog.vue diff --git a/src/App.vue b/src/App.vue index aaef3ce..d42830b 100644 --- a/src/App.vue +++ b/src/App.vue @@ -7,10 +7,14 @@ diff --git a/src/components/navigation/LoginDialog.vue b/src/components/navigation/LoginDialog.vue new file mode 100644 index 0000000..829391b --- /dev/null +++ b/src/components/navigation/LoginDialog.vue @@ -0,0 +1,80 @@ + + + + + diff --git a/src/components/navigation/TheUserMenu.vue b/src/components/navigation/TheUserMenu.vue index 6ad7009..4c42e89 100644 --- a/src/components/navigation/TheUserMenu.vue +++ b/src/components/navigation/TheUserMenu.vue @@ -16,6 +16,15 @@ + + Logout + + + Login + + + + User Profile + + Logout + + + Login + + + + diff --git a/src/plugins/vuetify.ts b/src/plugins/vuetify.ts index f557557..17fde5c 100644 --- a/src/plugins/vuetify.ts +++ b/src/plugins/vuetify.ts @@ -43,11 +43,17 @@ import Vuetify, { VTextField, VChipGroup, VChip, - VSkeletonLoader + VSkeletonLoader, + VDialog, + VCardText, + VCardTitle } from 'vuetify/lib' Vue.use(Vuetify, { components: { + VCardText, + VCardTitle, + VDialog, VApp, VRadioGroup, VSwitch, diff --git a/src/router/index.ts b/src/router/index.ts index 103991b..dfa5017 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -2,10 +2,16 @@ import Vue from 'vue' import VueRouter, { RouteConfig } from 'vue-router' import Room from '@/views/Room.vue' import Index from '@/views/Index.vue' +import Login from '@/views/Login.vue' Vue.use(VueRouter) const routes: RouteConfig[] = [ + { + path: '/login', + name: 'login', + component: Login + }, { path: '/:id', name: 'room', diff --git a/src/store/modules/authentication.ts b/src/store/modules/authentication.ts index 395bf0d..69a8022 100644 --- a/src/store/modules/authentication.ts +++ b/src/store/modules/authentication.ts @@ -2,6 +2,8 @@ import { ActionContext, Module } from 'vuex' import axios from 'axios' import { verify } from 'jsonwebtoken' +export const JWT_KEY = 'jsonwebtoken' + // Possible regions in the JWT token. export enum JWTRegion { EU = 'eu', @@ -10,6 +12,19 @@ export enum JWTRegion { SA = 'sa', } +export function regionDomain (region: JWTRegion): string { + switch (region) { + case JWTRegion.EU: + return 'eu' + case JWTRegion.NA: + return 'na' + case JWTRegion.RU: + return 'ru' + case JWTRegion.SA: + return 'asia' + } +} + export interface JWT { iss: string; // Who issued it. Example: GameTactic. aud: string; // For what. Example: GameTactic. @@ -32,6 +47,8 @@ export interface AuthenticationState { export enum AuthenticationActions { AUTHENTICATE = 'authenticate', LOGIN_WG = 'auth_wg', + LOGOUT = 'logout', + STORE_TOKEN = 'storeToken' } export enum AuthenticationMutation { @@ -76,10 +93,19 @@ const AuthenticationModule: Module = { // TODO: You probably want put this into the `state`. -Niko // Im not sure how this should be done, so I did it as I know. context.commit('SET_AUTHENTICATION_TOKEN', extended) + return extended + }, + [AuthenticationActions.STORE_TOKEN] (context: AuthenticationActionContext, token: string) { + localStorage.setItem(JWT_KEY, token) }, - async [AuthenticationActions.LOGIN_WG] (context: AuthenticationActionContext, region: string) { + [AuthenticationActions.LOGIN_WG] (context: AuthenticationActionContext, region: JWTRegion) { // TODO: This is just placeholder logic. Please check it works. -Niko - location.replace(process.env.VUE_APP_MS_AUTH + `/connect/wargaming/${region}/${window.location.href}`) + const returnUrl = process.env.VUE_APP_MS_AUTH + `/connect/wargaming/${regionDomain(region)}/${window.location.href}` + location.assign(returnUrl) + }, + [AuthenticationActions.LOGOUT] (context: AuthenticationActionContext) { + localStorage.removeItem(JWT_KEY) + context.commit(AuthenticationMutation.SET_AUTHENTICATION_TOKEN, null) } } } diff --git a/src/views/Login.vue b/src/views/Login.vue index 7c068c2..fed0bcb 100644 --- a/src/views/Login.vue +++ b/src/views/Login.vue @@ -1,24 +1,70 @@ - From 0e6ab86f02d152e06e161f420f8b9d99c3c5e085 Mon Sep 17 00:00:00 2001 From: Ataww Date: Thu, 23 Apr 2020 21:57:36 +0200 Subject: [PATCH 3/9] #15 - remove legacy login page --- src/components/navigation/LoginDialog.vue | 80 ----------------------- src/components/navigation/TheNav.vue | 46 ------------- src/components/navigation/TheUserMenu.vue | 3 +- src/router/index.ts | 6 -- src/views/Login.vue | 70 -------------------- 5 files changed, 1 insertion(+), 204 deletions(-) delete mode 100644 src/components/navigation/LoginDialog.vue delete mode 100644 src/components/navigation/TheNav.vue delete mode 100644 src/views/Login.vue diff --git a/src/components/navigation/LoginDialog.vue b/src/components/navigation/LoginDialog.vue deleted file mode 100644 index 829391b..0000000 --- a/src/components/navigation/LoginDialog.vue +++ /dev/null @@ -1,80 +0,0 @@ - - - - - diff --git a/src/components/navigation/TheNav.vue b/src/components/navigation/TheNav.vue deleted file mode 100644 index 2a65d59..0000000 --- a/src/components/navigation/TheNav.vue +++ /dev/null @@ -1,46 +0,0 @@ - - - - diff --git a/src/components/navigation/TheUserMenu.vue b/src/components/navigation/TheUserMenu.vue index 4c42e89..6a005df 100644 --- a/src/components/navigation/TheUserMenu.vue +++ b/src/components/navigation/TheUserMenu.vue @@ -63,7 +63,6 @@ import { Component, Prop, Vue } from 'vue-property-decorator' import { namespace } from 'vuex-class' import { Namespaces } from '@/store' import { AuthenticationActions, AuthenticationGetters } from '@/store/modules/authentication' -import LoginDialog from '@/components/navigation/LoginDialog.vue' import GLoginCard from '@/components/navigation/LoginCard.vue' const authNamespace = namespace(Namespaces.AUTH) @@ -75,7 +74,7 @@ const authNamespace = namespace(Namespaces.AUTH) @Component({ name: 'TheUserMenu', - components: { GLoginCard, LoginDialog } + components: { GLoginCard } }) export default class TheUserMenu extends Vue { @authNamespace.Getter(AuthenticationGetters.IS_AUTH) isAuth!: boolean diff --git a/src/router/index.ts b/src/router/index.ts index dfa5017..103991b 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -2,16 +2,10 @@ import Vue from 'vue' import VueRouter, { RouteConfig } from 'vue-router' import Room from '@/views/Room.vue' import Index from '@/views/Index.vue' -import Login from '@/views/Login.vue' Vue.use(VueRouter) const routes: RouteConfig[] = [ - { - path: '/login', - name: 'login', - component: Login - }, { path: '/:id', name: 'room', diff --git a/src/views/Login.vue b/src/views/Login.vue deleted file mode 100644 index fed0bcb..0000000 --- a/src/views/Login.vue +++ /dev/null @@ -1,70 +0,0 @@ - - - - - From eb556efae2ff9244fe922e1399175206ce6daa34 Mon Sep 17 00:00:00 2001 From: Ataww Date: Sun, 26 Apr 2020 17:33:15 +0200 Subject: [PATCH 4/9] #15 - Add login providers from auth uservice --- src/App.vue | 2 + src/components/navigation/LoginCard.vue | 46 ++++----------- src/components/navigation/TheUserMenu.vue | 51 ++++++++++------- .../navigation/login/ProviderBlock.vue | 38 +++++++++++++ src/store/modules/authentication.ts | 57 +++++++++++-------- src/util/ProvidersUtil.ts | 37 ++++++++++++ src/util/TypeUtils.ts | 4 ++ 7 files changed, 154 insertions(+), 81 deletions(-) create mode 100644 src/components/navigation/login/ProviderBlock.vue create mode 100644 src/util/ProvidersUtil.ts create mode 100644 src/util/TypeUtils.ts diff --git a/src/App.vue b/src/App.vue index d42830b..f9ea593 100644 --- a/src/App.vue +++ b/src/App.vue @@ -24,6 +24,7 @@ export default class TheApp extends Vue { @Action(`room/${RoomAction.SET_LOCALE}`) setLocale!: (locale: Locale) => void @authNamespace.Action(AuthenticationActions.AUTHENTICATE) authenticate!: (token: string) => Promise @authNamespace.Action(AuthenticationActions.STORE_TOKEN) storeToken!: (token: string) => void + @authNamespace.Action(AuthenticationActions.LOAD_PROVIDERS) loadProviders!: () => void async created () { this.setGame({ name: GameName['WOWS'], ships: [], gameInfo: undefined }) this.setLocale(Locale['ENUK']) @@ -52,6 +53,7 @@ export default class TheApp extends Vue { } initAuthentication () { + this.loadProviders() const localToken = localStorage.getItem(JWT_KEY) if (this.$route?.query?.code) { this.authenticate(this.$route.query.code as string).then(jwt => this.storeToken(jwt.encoded)) diff --git a/src/components/navigation/LoginCard.vue b/src/components/navigation/LoginCard.vue index a085411..221ed1f 100644 --- a/src/components/navigation/LoginCard.vue +++ b/src/components/navigation/LoginCard.vue @@ -6,18 +6,8 @@

Please select a realm to log in with

- - EU - - - NA - - - ASIA - - - CIS - + + @@ -26,35 +16,21 @@ import { Component, Vue } from 'vue-property-decorator' import { namespace } from 'vuex-class' import { Namespaces } from '@/store' -import { AuthenticationActions, JWTRegion } from '@/store/modules/authentication' +import { AuthenticationActions, AuthenticationGetters } from '@/store/modules/authentication' +import { Providers } from '@/util/ProvidersUtil' +import ProviderBlock from '@/components/navigation/login/ProviderBlock.vue' const authNamespace = namespace(Namespaces.AUTH) @Component({ - name: 'g-login-card' + name: 'LoginCard', + components: { + ProviderBlock + } }) export default class extends Vue { - @authNamespace.Action(AuthenticationActions.LOGIN_WG) authenticate!: (region: string) => void; - - authEU () { - console.log('authentication to ' + JWTRegion.EU) - this.authenticate(JWTRegion.EU) - } - - authNA () { - console.log('authentication to ' + JWTRegion.NA) - this.authenticate(JWTRegion.NA) - } - - authASIA () { - console.log('authentication to ' + JWTRegion.SA) - this.authenticate(JWTRegion.SA) - } - - authRU () { - console.log('authentication to ' + JWTRegion.RU) - this.authenticate(JWTRegion.RU) - } + @authNamespace.Action(AuthenticationActions.LOGIN_WG) authenticate!: (endpoint: string) => void + @authNamespace.Getter(AuthenticationGetters.PROVIDERS) providers!: Providers } diff --git a/src/components/navigation/TheUserMenu.vue b/src/components/navigation/TheUserMenu.vue index 6a005df..20f63c8 100644 --- a/src/components/navigation/TheUserMenu.vue +++ b/src/components/navigation/TheUserMenu.vue @@ -1,5 +1,18 @@ From a4efb91f33e35e32aca611e968627be24d9d5df2 Mon Sep 17 00:00:00 2001 From: Ataww Date: Sun, 17 May 2020 20:32:49 +0200 Subject: [PATCH 6/9] Login dialog gaps --- src/components/navigation/LoginCard.vue | 11 +---------- src/components/navigation/login/ProviderBlock.vue | 6 +++++- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/components/navigation/LoginCard.vue b/src/components/navigation/LoginCard.vue index b41b1a9..3bf5076 100644 --- a/src/components/navigation/LoginCard.vue +++ b/src/components/navigation/LoginCard.vue @@ -2,7 +2,7 @@ @@ -35,14 +35,5 @@ export default class extends Vue { &-title { font-weight: bold; } - &-content { - display: grid; - grid-template-columns: 1fr; - grid-row-gap: 10px; - - &-block { - margin-top: 10px; - } - } } diff --git a/src/components/navigation/login/ProviderBlock.vue b/src/components/navigation/login/ProviderBlock.vue index fb45668..43c8a2f 100644 --- a/src/components/navigation/login/ProviderBlock.vue +++ b/src/components/navigation/login/ProviderBlock.vue @@ -1,5 +1,5 @@ - Logout + {{ $t('navigation.login.logout') }} - User Profile + {{ $t('user.profile') }} - Logout + {{ $t('navigation.login.logout') }} - Login + {{ $t('navigation.login.title') }} diff --git a/src/store/modules/authentication.ts b/src/store/modules/authentication.ts index 9db6cdd..b07b9f5 100644 --- a/src/store/modules/authentication.ts +++ b/src/store/modules/authentication.ts @@ -134,10 +134,6 @@ const AuthenticationModule: Module = { throw Error('Could not fetch authentication providers') } const providers = response.data.providers - providers['test others'] = { - facebook: 'testFB', - google: 'testGoogle' - } context.commit(AuthenticationMutation.SET_PROVIDERS, mapProviders(providers)) } else { throw Error('Authentication URI is not set') From 35ae7e8508f1c145c5382a37c854e082b408fe5f Mon Sep 17 00:00:00 2001 From: Ataww Date: Sun, 24 May 2020 20:53:32 +0200 Subject: [PATCH 8/9] feature/15 - closeable login dialog on mobile --- src/components/navigation/LoginCard.vue | 20 ++++++++++---- src/components/navigation/TheUserMenu.vue | 32 +++++++++-------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/components/navigation/LoginCard.vue b/src/components/navigation/LoginCard.vue index 4e65bdf..6907463 100644 --- a/src/components/navigation/LoginCard.vue +++ b/src/components/navigation/LoginCard.vue @@ -1,6 +1,11 @@ diff --git a/src/components/navigation/TheUserMenu.vue b/src/components/navigation/TheUserMenu.vue index 6dfbbd9..9e17108 100644 --- a/src/components/navigation/TheUserMenu.vue +++ b/src/components/navigation/TheUserMenu.vue @@ -1,18 +1,4 @@ - + {{ $t('navigation.login.logout') }} + + {{ $t('navigation.login.title') }} + + + + {{ $t('navigation.login.logout') }} - + {{ $t('navigation.login.title') }} - - + + { this.isDialogOpen = true }) } - onClickCloseDialog () { + onClickCloseLoginDialog () { this.isDialogOpen = false } From b2850c5d4b8ef57712595b6eef3ef83ca15644d5 Mon Sep 17 00:00:00 2001 From: Ataww Date: Tue, 26 May 2020 00:11:07 +0200 Subject: [PATCH 9/9] PR feedbacks --- src/App.vue | 34 ++++++++++--------- src/components/navigation/LoginCard.vue | 13 +++---- src/components/navigation/TheUserMenu.vue | 4 +-- .../navigation/login/ProviderBlock.vue | 8 ++--- src/store/modules/types.ts | 4 +-- 5 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/App.vue b/src/App.vue index 46ffc59..8a37dfb 100644 --- a/src/App.vue +++ b/src/App.vue @@ -7,7 +7,7 @@ diff --git a/src/components/navigation/LoginCard.vue b/src/components/navigation/LoginCard.vue index 6907463..2d2d874 100644 --- a/src/components/navigation/LoginCard.vue +++ b/src/components/navigation/LoginCard.vue @@ -1,14 +1,15 @@ @@ -41,7 +42,7 @@ export default class extends Vue { diff --git a/src/store/modules/types.ts b/src/store/modules/types.ts index 31ec6cf..c868f12 100644 --- a/src/store/modules/types.ts +++ b/src/store/modules/types.ts @@ -23,7 +23,7 @@ export interface Game { api: Api[]; } -export enum RoleTypes { +export enum RoleTypes { ROON_OWNER = 'roomOwner', ADMIN = 'admin' } @@ -85,4 +85,4 @@ export interface PresentationPayload { export interface Presentation { enabledBy: string | undefined; tacticId: string | undefined; -} \ No newline at end of file +}