From b4f1096048a31cdb313b49c8f7a01c7cca02dfdb Mon Sep 17 00:00:00 2001 From: ogerly Date: Tue, 20 Apr 2021 07:55:42 +0200 Subject: [PATCH 1/3] reset pwd clear data files seperated --- frontend/src/App.vue | 5 +- frontend/src/apis/loginAPI.js | 9 ++ frontend/src/routes/router.js | 4 - frontend/src/routes/routes.js | 4 +- frontend/src/store/store.js | 9 -- .../{Password.vue => ForgotPassword.vue} | 26 ++-- .../views/{ => Pages}/KontoOverview.spec.js | 0 .../src/views/{ => Pages}/KontoOverview.vue | 6 +- frontend/src/views/Pages/Login.vue | 3 + frontend/src/views/Pages/ResetPassword.vue | 147 ++++++++++++++++++ 10 files changed, 180 insertions(+), 33 deletions(-) rename frontend/src/views/Pages/{Password.vue => ForgotPassword.vue} (79%) rename frontend/src/views/{ => Pages}/KontoOverview.spec.js (100%) rename frontend/src/views/{ => Pages}/KontoOverview.vue (88%) create mode 100644 frontend/src/views/Pages/ResetPassword.vue diff --git a/frontend/src/App.vue b/frontend/src/App.vue index fafd46b32..6cf78bb54 100755 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -60,7 +60,10 @@ export default { this.$router.push('overview') } else { //console.log('app.vue to Logout') - this.$store.dispatch('logout') + if (this.$route.path == '/reset') { + } else { + this.$store.dispatch('logout') + } } }, data() { diff --git a/frontend/src/apis/loginAPI.js b/frontend/src/apis/loginAPI.js index d422fe3ff..91020ddbb 100644 --- a/frontend/src/apis/loginAPI.js +++ b/frontend/src/apis/loginAPI.js @@ -63,6 +63,15 @@ const loginAPI = { } return apiPost(CONFIG.LOGIN_API_URL + 'createUser', payload) }, + sendEmail: async (email, email_text = 7, email_verification_code_type = 'resetPassword') => { + //console.log('api email', email) + const payload = { + email, + email_text, + email_verification_code_type, + } + return apiPost(CONFIG.LOGIN_API_URL + 'sendEmail', payload) + }, } export default loginAPI diff --git a/frontend/src/routes/router.js b/frontend/src/routes/router.js index cd3646fe0..571c64582 100644 --- a/frontend/src/routes/router.js +++ b/frontend/src/routes/router.js @@ -21,10 +21,6 @@ const router = new VueRouter({ }) router.beforeEach((to, from, next) => { - let language = to.params.lang - if (!language) { - language = 'de' - } next() }) diff --git a/frontend/src/routes/routes.js b/frontend/src/routes/routes.js index b50f2a7b1..d487ed05e 100755 --- a/frontend/src/routes/routes.js +++ b/frontend/src/routes/routes.js @@ -3,7 +3,7 @@ import NotFound from '@/views/NotFoundPage.vue' const routes = [ { path: '/overview', - component: () => import('../views/KontoOverview.vue'), + component: () => import('../views/Pages/KontoOverview.vue'), meta: { requiresAuth: true, }, @@ -38,7 +38,7 @@ const routes = [ }, { path: '/password', - component: () => import('../views/Pages/Password.vue'), + component: () => import('../views/Pages/ForgotPassword.vue'), }, { path: '/explorer', diff --git a/frontend/src/store/store.js b/frontend/src/store/store.js index 96b2c4be8..65463a3df 100644 --- a/frontend/src/store/store.js +++ b/frontend/src/store/store.js @@ -63,7 +63,6 @@ export const store = new Vuex.Store({ state.user.balance_gdt = balance / 10000 }, }, - // Asyncronous actions - used for api calls actions: { login: async ({ dispatch, commit }, data) => { const result = await loginAPI.login(data.email, data.password) @@ -74,19 +73,11 @@ export const store = new Vuex.Store({ $cookies.set('gdd_u', data.email) router.push('/overview') } else { - // Register failed, we perform a logout - //alert('>>>>> FAIl LOGIN') commit('loginfail', true) //dispatch('logout') } }, - passwordReset: async (data) => { - //console.log('<<<<<<<<<<< PASSWORT RESET TODO >>>>>>>>>>>', data.email) - }, - schoepfen: async (data) => { - // http://localhost/transaction-creations/ajaxCreate - }, createUser: async ({ commit, dispatch }, data) => { // console.log('action: createUser') const result = await loginAPI.create( diff --git a/frontend/src/views/Pages/Password.vue b/frontend/src/views/Pages/ForgotPassword.vue similarity index 79% rename from frontend/src/views/Pages/Password.vue rename to frontend/src/views/Pages/ForgotPassword.vue index 0db2a2725..d99d7731e 100644 --- a/frontend/src/views/Pages/Password.vue +++ b/frontend/src/views/Pages/ForgotPassword.vue @@ -26,17 +26,10 @@ :placeholder="$t('form.email')" name="Email" :rules="{ required: true, email: true }" - v-model="model.email" + v-model="form.email" > - {{ form }}
- + {{ $t('site.password.reset_now') }}
@@ -53,21 +46,26 @@ + From 38a447f62d4dcee03f11b1c1790f8422a6221d84 Mon Sep 17 00:00:00 2001 From: ogerly Date: Tue, 20 Apr 2021 08:00:17 +0200 Subject: [PATCH 2/3] reset to router --- frontend/src/routes/routes.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/frontend/src/routes/routes.js b/frontend/src/routes/routes.js index d487ed05e..f70afa1b5 100755 --- a/frontend/src/routes/routes.js +++ b/frontend/src/routes/routes.js @@ -41,9 +41,8 @@ const routes = [ component: () => import('../views/Pages/ForgotPassword.vue'), }, { - path: '/explorer', - name: 'Explorer', - component: () => import('../views/Pages/Explorer.vue'), + path: '/reset', + component: () => import('../views/Pages/ResetPassword.vue'), }, { path: '*', component: NotFound }, ] From 7fe5119783b1b4418cbc13bc75110746f3429e26 Mon Sep 17 00:00:00 2001 From: ogerly Date: Tue, 20 Apr 2021 09:27:35 +0200 Subject: [PATCH 3/3] add specs --- .../src/views/Pages/ResetPassword.spec.js | 107 ++++++++++++++++++ frontend/src/views/Pages/ResetPassword.vue | 2 +- 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 frontend/src/views/Pages/ResetPassword.spec.js diff --git a/frontend/src/views/Pages/ResetPassword.spec.js b/frontend/src/views/Pages/ResetPassword.spec.js new file mode 100644 index 000000000..ebff0fc20 --- /dev/null +++ b/frontend/src/views/Pages/ResetPassword.spec.js @@ -0,0 +1,107 @@ +import { mount, RouterLinkStub } from '@vue/test-utils' +import Vuex from 'vuex' +import flushPromises from 'flush-promises' + +import ResetPassword from './ResetPassword' + +const localVue = global.localVue + +describe('ResetPassword', () => { + let wrapper + + let mocks = { + $i18n: { + locale: 'en', + }, + $t: jest.fn((t) => t), + } + + let state = { + // loginfail: false, + } + + let store = new Vuex.Store({ + state, + }) + + let stubs = { + RouterLink: RouterLinkStub, + } + + const Wrapper = () => { + return mount(ResetPassword, { localVue, mocks, store, stubs }) + } + + describe('mount', () => { + beforeEach(() => { + wrapper = Wrapper() + }) + + it('renders the Reset Password form', () => { + expect(wrapper.find('div.resetpwd-form').exists()).toBeTruthy() + }) + + //describe('Register header', () => { + // it('has a welcome message', () => { + // expect(wrapper.find('div.header').text()).toBe('site.signup.title site.signup.subtitle') + // }) + //}) + + //describe('links', () => { + // it('has a link "Back"', () => { + // expect(wrapper.findAllComponents(RouterLinkStub).at(0).text()).toEqual('back') + // }) + + // it('links to /login when clicking "Back"', () => { + // expect(wrapper.findAllComponents(RouterLinkStub).at(0).props().to).toBe('/login') + // }) + //}) + + //describe('Register form', () => { + // it('has a register form', () => { + // expect(wrapper.find('form').exists()).toBeTruthy() + // }) + + // it('has 3 text input fields', () => { + // expect(wrapper.findAll('input[type="text"]').length).toBe(3) + // }) + + // it('has 2 password input fields', () => { + // expect(wrapper.findAll('input[type="password"]').length).toBe(2) + // }) + + // it('has 1 checkbox input fields', () => { + // expect(wrapper.findAll('input[type="checkbox"]').length).toBe(1) + // }) + + // it('has no submit button when not completely filled', () => { + // expect(wrapper.find('button[type="submit"]').exists()).toBe(false) + // }) + + // it('shows a warning when no valid Email is entered', async () => { + // wrapper.findAll('input[type="text"]').at(2).setValue('no_valid@Email') + // await flushPromises() + // await expect(wrapper.find('.invalid-feedback').text()).toEqual( + // 'The Email field must be a valid email', + // ) + // }) + + // it('shows 4 warnings when no password is set', async () => { + // const passwords = wrapper.findAll('input[type="password"]') + // passwords.at(0).setValue('') + // passwords.at(1).setValue('') + // await flushPromises() + // await expect(wrapper.find('div.hints').text()).toContain( + // 'site.signup.lowercase', + // 'site.signup.uppercase', + // 'site.signup.minimum', + // 'site.signup.one_number', + // ) + // }) + + // //TODO test different invalid password combinations + //}) + + // TODO test submit button + }) +}) diff --git a/frontend/src/views/Pages/ResetPassword.vue b/frontend/src/views/Pages/ResetPassword.vue index 0923d57ba..145fba404 100644 --- a/frontend/src/views/Pages/ResetPassword.vue +++ b/frontend/src/views/Pages/ResetPassword.vue @@ -1,5 +1,5 @@