diff --git a/frontend/src/App.vue b/frontend/src/App.vue index b4c26ef8e..bb9330920 100755 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -13,43 +13,12 @@ export default { name: 'app', created () { - if (this.$cookies.get('gdd_is_auth') == 'true' && this.$store.state.is_auth == true) { - this.$store.state.user.email = this.$cookies.get('gdd_email') - - // if ( this.$store.state.is_auth == false && this.$store.state.is_admin == false) { - // this.$router.push("/Landing") - // } else { - this.$router.push('/KontoOverview') - // } - }else { - this.$router.push("/Landing") - } - - //var user = { id:1, name:'Journal',session:'25j_7Sl6xDq2Kc3ym0fmrSSk2xV2XkUkX' }; - //this.$cookies.set('user',user); - //// print user name - //console.log("APP.vue START created get cookie is_auth=>",this.$cookies.get('gdd_is_auth')) - - }, - methods: { - /* - login() { - //console.log("app.vue user login() : " + this.$store.state.is_auth) - this.$store.commit('login') - //this.$router.push('/KontoOverview') - }, - loginAsAdmin () { - // console.log("app.vue admin login(): " + this.$store.state.is_admin) - this.$store.state.modals = true - //this.$store.commit('loginAsAdmin') - //this.$router.push('/AdminOverview') - }, - - logout(){ - // console.log("app.vue user logout() : ") - this.$store.commit('logout') - } - */ + if ( $cookies.isKey("gdd_session_id") == true ) { + this.$store.state.email = this.$cookies.get('gdd_u') + this.$router.push('/KontoOverview') + }else { + this.$router.push("/Login") + } } } diff --git a/frontend/src/mixins/loginAPI.js b/frontend/src/mixins/loginAPI.js new file mode 100644 index 000000000..d102f381d --- /dev/null +++ b/frontend/src/mixins/loginAPI.js @@ -0,0 +1,19 @@ +// TODO move this +const LOGIN_API_URL = 'http://localhost/login_api/' + +// define a mixin object +const loginAPI = { + actions: { + login: async () => { + return axios.post(LOGIN_API_URL + 'unsecureLogin', data); + }, + creatUser : async () => { + return axios.post(LOGIN_API_URL + 'createUser', data); + }, + logout: async () => { + return axios.post(LOGIN_API_URL + 'logout', data); + }, + } +} + +export default loginAPI \ No newline at end of file diff --git a/frontend/src/routes/router.js b/frontend/src/routes/router.js index 497d323b2..4b26c18bf 100644 --- a/frontend/src/routes/router.js +++ b/frontend/src/routes/router.js @@ -26,22 +26,7 @@ router.beforeEach((to, from, next) => { if (!language) { language = 'de' } - - //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) - - next() - + next() }) -export default router +export default router \ No newline at end of file diff --git a/frontend/src/routes/routes.js b/frontend/src/routes/routes.js index c571acc30..1ce4875a1 100755 --- a/frontend/src/routes/routes.js +++ b/frontend/src/routes/routes.js @@ -11,17 +11,21 @@ const routes = [ redirect: 'landing', 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') }, - + { + path: '/Landing', + name: 'Landing', + component: () => import(/* webpackChunkName: "demo" */ '../views/Landing.vue') + }, + { + path: '/register', + name: 'register', + component: () => import(/* webpackChunkName: "demo" */ '../views/Pages/Register.vue') + }, ] }, { @@ -41,12 +45,7 @@ const routes = [ path: '/profile', name: 'profile', component: () => import(/* webpackChunkName: "demo" */ '../views/Pages/UserProfile.vue') - }, - { - path: '/register', - name: 'register', - component: () => import(/* webpackChunkName: "demo" */ '../views/Pages/Register.vue') - }, + } ] }, , diff --git a/frontend/src/store/store.js b/frontend/src/store/store.js index 2447966cc..995727987 100644 --- a/frontend/src/store/store.js +++ b/frontend/src/store/store.js @@ -3,22 +3,25 @@ import Vuex from 'vuex' Vue.use(Vuex) import router from '../routes/router.js' import loginAPI from '../apis/loginAPI' +import axios from 'axios' // TODO make persistent: https://translate.google.de/translate?hl=de&sl=en&u=https://sandulat.com/safely-persisting-vuex-store-in-local-storage/&prev=search&pto=aue export const store = new Vuex.Store({ state: { - /*path: 'http://192.168.0.89/account/', - is_auth: false, - is_admin: false, - active: false, - modals: false, + session_id: null, + email: null, user : { name:"", - email:"" + balance: 0 }, - dataLogout: {"session_id": -127182}*/ - session_id: null, - email: null + ajaxCreateData: { + session_id : '', + email: "max.musterman@gmail.de", + amount: 10000000, + target_date:"2021-02-19T13:25:36+00:00", + memo:"AGE", + auto_sign: true + } }, // Retrieve a state variable getters: { @@ -48,6 +51,8 @@ export const store = new Vuex.Store({ // TODO show user a success message commit('session_id', result.result.data.session_id) commit('email', data.email) + $cookies.set('gdd_session_id', result.result.data.session_id); + $cookies.set('gdd_u', data.email); router.push('/KontoOverview') } else { // Register failed, we perform a logout @@ -74,8 +79,138 @@ export const store = new Vuex.Store({ } commit('session_id', null) - commit('email', null) - router.push('/landing') + commit('email', null) + $cookies.remove('gdd_session_id'); + $cookies.remove('gdd_u'); + router.push('/Login') + }, + ajaxCreate: async (state) => { + state.ajaxCreateData.session_id = state.session_id + console.log(" state.ajaxCreateData => ", state.ajaxCreateData) + axios.post(" http://localhost/transaction-creations/ajaxCreate/", state.ajaxCreateData).then((req) => { + console.log("ajaxCreate => ", req) + }, (error) => { + console.log(error); + }); + }, + ajaxListTransactions: async (state) => { + // console.log("ajaxListTransactions => START") + axios.get("http://localhost/state-balances/ajaxListTransactions/" + state.session_id).then((req) => { + console.log("ajaxListTransactions => ", req) + }, (error) => { + console.log(error); + }); + }, + accountBalance: async ({ state }) => { + //console.log(" => START") + state.url = "http://localhost/state-balances/ajaxGetBalance/" + state.session_id + //console.log(state.url) + axios.get(state.url).then((req) => { + console.log("accountBalance => ", req.data.balance) + state.user.balance = req.data.balance + }, (error) => { + console.log(error); + }); } - } -}) \ No newline at end of file + } +}) + +/* + 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); + if (ldata.statusText === "OK") { + //console.log("STORE login() ldatasession_id", ldata.data.session_id) + state.is_auth = true + state.active = true + state.session_id= ldata.data.session_id + state.user.email = logindata.email + $cookies.set('gdd_is_auth','true'); + $cookies.set('gdd_session_id', ldata.data.session_id); + $cookies.set('gdd_u',logindata.email); + console.log("cookie ? GRADIDO_LOGIN", $cookies.get('GRADIDO_LOGIN')) + //this.$store.dispatch('accountBalance') + //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( state, 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; + router.push('/Login') + + }, (error) => { + console.log(error); + }); + }, + logout(state){ + axios.post("http://localhost/login_api/logout", {"session_id": state.session_id}).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 + state.session_id = '' + state.user.email = '' + $cookies.set('gdd_is_auth','false'); + $cookies.remove('gdd_u'); + $cookies.remove('gdd_session_id'); + router.push('/Login') + }, (error) => { + console.log(error); + }); + + }, + ajaxCreate(state){ + state.ajaxCreateData.session_id = state.session_id + console.log(" state.ajaxCreateData => ", state.ajaxCreateData) + axios.post(" http://localhost/transaction-creations/ajaxCreate/", state.ajaxCreateData).then((req) => { + console.log("ajaxCreate => ", req) + }, (error) => { + console.log(error); + }); + }, + ajaxListTransactions(state) { + console.log("ajaxListTransactions => START") + axios.get("http://localhost/state-balances/ajaxListTransactions/"+ state.session_id).then((req) => { + console.log("ajaxListTransactions => ", req) + }, (error) => { + console.log(error); + }); + }, + accountBalance(state) { + console.log(" => START") + state.url = "http://localhost/state-balances/ajaxGetBalance/"+ state.session_id + console.log(state.url) + axios.get(state.url).then((req) => { + console.log("accountBalance => ", req.data.balance) + state.user.balance = req.data.balance + }, (error) => { + console.log(error); + }); + } +*/ \ No newline at end of file diff --git a/frontend/src/views/KontoOverview.vue b/frontend/src/views/KontoOverview.vue index a72d1d3eb..4fbcc5e37 100644 --- a/frontend/src/views/KontoOverview.vue +++ b/frontend/src/views/KontoOverview.vue @@ -30,11 +30,20 @@ +
this.$store.dispatch('ajaxCreate')
+
this.$store.dispatch('ajaxListTransactions')
+
this.$store.dispatch('accountBalance')

-

User Data

- /public/json-example/userdata.json +

User Balanace

+ this.$store.state.user.balance

- {{userdata}} + {{this.$store.state.user}} +

+
+

User Balanace

+ this.$store.state.user.balance +

+ {{this.$store.state.user.balance}}


@@ -80,6 +89,9 @@ GddAddWork, GddWorkTable, //axios + }, + created() { + }, methods: { UserData() { diff --git a/frontend/src/views/KontoOverview/GddStatus.vue b/frontend/src/views/KontoOverview/GddStatus.vue index 1b0985665..87825d232 100644 --- a/frontend/src/views/KontoOverview/GddStatus.vue +++ b/frontend/src/views/KontoOverview/GddStatus.vue @@ -4,13 +4,12 @@ - + {{ balance_gdd }} GDD @@ -34,5 +33,11 @@ \ No newline at end of file diff --git a/frontend/src/views/Pages/Login.vue b/frontend/src/views/Pages/Login.vue index b5f19cd2d..686d024f1 100755 --- a/frontend/src/views/Pages/Login.vue +++ b/frontend/src/views/Pages/Login.vue @@ -1,13 +1,23 @@