From 2bd96339ffee06ded8405d36e668e8b3efffb1ed Mon Sep 17 00:00:00 2001 From: ogerly Date: Tue, 23 Feb 2021 14:00:38 +0100 Subject: [PATCH 1/2] add login session + cookies --- package.json | 1 + src/App.vue | 50 +++---- src/main.js | 4 +- src/plugins/dashboard-plugin.js | 2 +- src/routes/router.js | 16 ++- src/routes/routes.js | 17 +-- src/store/store.js | 91 +++++++++---- src/views/AdminOverview.vue | 14 +- src/views/Landing.vue | 122 ++++++++++++++--- src/views/{Pages => Layout}/AuthLayout.vue | 0 src/views/Layout/AuthLayout_gdd.vue | 147 +++++++++++++++++++++ src/views/Layout/DashboardLayout.vue | 29 ++-- src/views/Layout/DashboardNavbar.vue | 10 +- src/views/Pages/UserProfile.vue | 2 +- src/views/Pages/UserProfile/UserCard.vue | 2 +- 15 files changed, 390 insertions(+), 117 deletions(-) rename src/views/{Pages => Layout}/AuthLayout.vue (100%) create mode 100644 src/views/Layout/AuthLayout_gdd.vue diff --git a/package.json b/package.json index 8cb3abd94..2e5a80790 100755 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "vue-cli-plugin-i18n": "^1.0.1", "vue-clickaway": "^2.2.2", "vue-clipboard2": "^0.3.0", + "vue-cookies": "^1.7.4", "vue-flatpickr-component": "^8.1.2", "vue-good-table": "^2.21.3", "vue-i18n": "^8.22.4", diff --git a/src/App.vue b/src/App.vue index feb0d6dfd..ba1a0937c 100755 --- a/src/App.vue +++ b/src/App.vue @@ -2,40 +2,37 @@
-
-
- - - - - -
+
+
diff --git a/src/main.js b/src/main.js index 82c2dce01..d98768a6e 100755 --- a/src/main.js +++ b/src/main.js @@ -2,6 +2,7 @@ import Vue from 'vue'; import DashboardPlugin from './plugins/dashboard-plugin'; import App from './App.vue'; import i18n from './i18n.js'; +import VueCookies from 'vue-cookies'; // store import {store} from './store/store'; @@ -11,7 +12,8 @@ import router from './routes/router'; // plugin setup Vue.use(DashboardPlugin); -Vue.config.productionTip = false +Vue.config.productionTip = false; +Vue.use(VueCookies); /* eslint-disable no-new */ diff --git a/src/plugins/dashboard-plugin.js b/src/plugins/dashboard-plugin.js index 58c74f1fe..41cfe0509 100755 --- a/src/plugins/dashboard-plugin.js +++ b/src/plugins/dashboard-plugin.js @@ -31,7 +31,7 @@ import VueQrcodeReader from "vue-qrcode-reader"; import VueGoodTablePlugin from 'vue-good-table'; // import the styles -import 'vue-good-table/dist/vue-good-table.css' +import 'vue-good-table/dist/vue-good-table.css'; Object.keys(rules).forEach(rule => { diff --git a/src/routes/router.js b/src/routes/router.js index 164380edf..f0b1807a5 100644 --- a/src/routes/router.js +++ b/src/routes/router.js @@ -28,13 +28,15 @@ router.beforeEach((to, from, next) => { } //console.log("----------------") - console.log("to", to) - console.log("store.state.is_auth", store.state.is_auth) - // if (store.state.is_auth != true && to.path != "/login" ) { - // next() - // } else { - // next("/login") - // } + console.log("ROUTER.js to", to) + console.log("ROUTER.js store.state.is_auth", store.state.is_auth) + console.log("ROUTER.js store.commit('isActive')", store.commit('isActive')) + + //if (store.commit('isActive') ) { + // next() + //} else { + // next("/login") + //} //console.log(from) //console.log(next) diff --git a/src/routes/routes.js b/src/routes/routes.js index 7487e0492..c571acc30 100755 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -1,5 +1,6 @@ import DashboardLayout from '@/views/Layout/DashboardLayout.vue' -import AuthLayout from '@/views/Pages/AuthLayout.vue' +import AuthLayoutGDD from '@/views/Layout/AuthLayout_gdd.vue' +import AuthLayout from '@/views/Layout/AuthLayout.vue' import NotFound from '@/views/NotFoundPage.vue' @@ -8,13 +9,18 @@ const routes = [ { path: '/', redirect: 'landing', - component: AuthLayout, + component: AuthLayoutGDD, children: [ { path: '/Landing', name: 'Landing', component: () => import(/* webpackChunkName: "demo" */ '../views/Landing.vue') - } + }, + { + path: '/login', + name: 'login', + component: () => import(/* webpackChunkName: "demo" */ '../views/Pages/Login.vue') + }, ] }, @@ -36,11 +42,6 @@ const routes = [ name: 'profile', component: () => import(/* webpackChunkName: "demo" */ '../views/Pages/UserProfile.vue') }, - { - path: '/login', - name: 'login', - component: () => import(/* webpackChunkName: "demo" */ '../views/Pages/Login.vue') - }, { path: '/register', name: 'register', diff --git a/src/store/store.js b/src/store/store.js index 43112d9f0..792d8f4fd 100644 --- a/src/store/store.js +++ b/src/store/store.js @@ -1,6 +1,9 @@ import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) +import axios from 'axios'; +import VueCookies from 'vue-cookies'; +import router from '../routes/router.js'; export const store = new Vuex.Store({ state: { @@ -10,37 +13,77 @@ export const store = new Vuex.Store({ active: false, modals: false, user : { - name:"oger ly", - email:"test@test.de" - } + name:"", + email:"" + }, + dataLogout: {"session_id": -127182} }, - mutations: { - login (state) { - console.log("store login() user from " + state.is_auth) - if (state.is_auth) { - state.is_auth = false - state.active = false - } else { - state.is_auth = true - state.active = true - } - console.log("store login() user to " + state.is_auth) + mutations: { + isActive(state) { + //("Im Store PRÜFEN PRÜFEN" ) + return true }, - loginAsAdmin (state) { - console.log("store login admin from" + state.is_admin) - if (state.is_admin) { - state.is_admin = false - state.active = false - } else { - state.is_admin = true - state.active = true - } - console.log("store login admin to" + state.is_admin) + login (state, logindata) { + //console.log("Im Store LOGIN() start " ) + //console.log("logon state =>", state ) + //console.log("logon TEST =>", logindata ) + axios.post("http://localhost/login_api/unsecureLogin", logindata).then((ldata) => { + + //console.log("Im Store LOGIN() axios then.statusText ", ldata.statusText); + if (ldata.statusText === "OK") { + //console.log("STORE login() from" + state.is_auth) + state.is_auth = true + state.active = true + $cookies.set('gdd_is_auth','true'); + $cookies.set('gdd_email',logindata.email); + state.user.email = logindata.email + + //console.log("STORE login() to " + state.is_auth) + router.push('/KontoOverview') + + } + + return true + }, (error) => { + console.log(error); + }); + //console.log("STORE login() from" + state.is_auth) + //if (state.is_auth) { + // state.is_auth = false + // state.active = false + //} else { + // state.is_auth = true + // state.active = true + //} + // console.log("STORE login() to " + state.is_auth) }, + creatUser( formdata) { + //console.log("Im Store creatUser() start " ) + axios.post("http://localhost/login_api/createUser", formdata).then((ldata) => { + + //console.log("Im Store creatUser() axios then ", ldata); + // this.ldata = ldata.data; + //return true + }, (error) => { + console.log(error); + }); + }, logout(state){ + axios.post("http://localhost/login_api/logout", this.dataLogout).then((ldata) => { + + //console.log("Im Store logout() axios then ", ldata); + // this.ldata = ldata.data; + //return true state.is_auth = false state.is_admin = false state.active = false + $cookies.set('gdd_is_auth','false'); + $cookies.remove('gdd_email'); + router.push('/Landing') + }, (error) => { + console.log(error); + }); + } } }) \ No newline at end of file diff --git a/src/views/AdminOverview.vue b/src/views/AdminOverview.vue index 854b95be9..b54920a9d 100644 --- a/src/views/AdminOverview.vue +++ b/src/views/AdminOverview.vue @@ -290,7 +290,7 @@ methods: { TransienceList() { axios.get("/json-example/admin_transience_list.json").then((d) => { - console.log(d); + //console.log(d); this.transiencelist = d.data; }, (error) => { @@ -299,7 +299,7 @@ }, TransactionList() { axios.get("/json-example/admin_transaction_list.json").then((d) => { - console.log(d); + //console.log(d); this.transactionlist = d.data; }, (error) => { @@ -308,7 +308,7 @@ }, UserList() { axios.get("/json-example/admin_userlist.json").then((d) => { - console.log(d); + //console.log(d); this.userlist = d.data; }, (error) => { @@ -317,7 +317,7 @@ }, CommunityStatistic() { axios.get("/json-example/admin_community_statistic.json").then((d) => { - console.log(d); + //console.log(d); this.communitystatistic = d.data; }, (error) => { @@ -326,7 +326,7 @@ }, ChartsStatistic() { axios.get("/json-example/admin_charts_statistic.json").then((d) => { - console.log(d); + //console.log(d); this.chartsstatistic = d.data; }, (error) => { @@ -335,7 +335,7 @@ }, CardStatistic() { axios.get("/json-example/admin_card_statistic.json").then((d) => { - console.log(d); + //console.log(d); this.cardstatistic = d.data; }, (error) => { @@ -344,7 +344,7 @@ }, StatisticDatas() { axios.get("/json-example/admin_statisticdatas.json").then((d) => { - console.log(d); + //console.log(d); this.userdata = d.data; }, (error) => { diff --git a/src/views/Landing.vue b/src/views/Landing.vue index bed2cc099..856565a25 100644 --- a/src/views/Landing.vue +++ b/src/views/Landing.vue @@ -4,7 +4,9 @@
- +

GRADIDO

+

Wallet

+ +
+

+ Anmelden +

+ + + +
+ + + + + + + + + + + + + + + + Anmelden +
+
+ +
+

+ neues Mitglied anlegen +

+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ Anmelden +
+
+
@@ -24,32 +94,44 @@
-
- - - - - - -
-

{{ $t('site.landing1.explore') }}

-

{{ $t('site.landing1.text') }}

- {{ $t('site.landing1.link') }} -
-
-
-
-
+
+ diff --git a/src/views/Layout/DashboardLayout.vue b/src/views/Layout/DashboardLayout.vue index 14c94a725..72793376d 100755 --- a/src/views/Layout/DashboardLayout.vue +++ b/src/views/Layout/DashboardLayout.vue @@ -13,28 +13,15 @@ - - - - - - - + + + Logout +