diff --git a/package-lock.json b/package-lock.json index 76d1157e..54b22878 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10918,6 +10918,11 @@ "vue-style-loader": "^4.1.0" } }, + "vue-router": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/vue-router/-/vue-router-3.0.6.tgz", + "integrity": "sha512-Ox0ciFLswtSGRTHYhGvx2L44sVbTPNS+uD2kRISuo8B39Y79rOo0Kw0hzupTmiVtftQYCZl87mwldhh2L9Aquw==" + }, "vue-style-loader": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/vue-style-loader/-/vue-style-loader-4.1.2.tgz", diff --git a/package.json b/package.json index be7d5a08..df1b706d 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "axios": "^0.18.0", "core-js": "^2.6.5", "vue": "^2.6.10", + "vue-router": "^3.0.6", "vuetify": "^1.5.5", "vuex": "^3.1.1" }, diff --git a/src/App.vue b/src/App.vue index 3f883af0..202e2e77 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,48 +1,30 @@ + + + \ No newline at end of file diff --git a/src/components/Menu.vue b/src/components/Menu.vue new file mode 100644 index 00000000..3463f318 --- /dev/null +++ b/src/components/Menu.vue @@ -0,0 +1,155 @@ + + + \ No newline at end of file diff --git a/src/components/MenuMobile.vue b/src/components/MenuMobile.vue new file mode 100644 index 00000000..2869ded5 --- /dev/null +++ b/src/components/MenuMobile.vue @@ -0,0 +1,146 @@ + + + \ No newline at end of file diff --git a/src/main.js b/src/main.js index d5b3650f..cc98210a 100644 --- a/src/main.js +++ b/src/main.js @@ -2,6 +2,7 @@ import Vue from 'vue' import './plugins/vuetify' import App from './App.vue' import store from './store/store' +import router from './router' @@ -20,5 +21,6 @@ Vue.config.productionTip = false new Vue({ store, + router, render: h => h(App), }).$mount('#app') diff --git a/src/router/index.js b/src/router/index.js new file mode 100644 index 00000000..04895761 --- /dev/null +++ b/src/router/index.js @@ -0,0 +1,59 @@ +import Vue from 'vue' +import Router from 'vue-router' +import Startpage from '../views/Startpage' +import HelloWorld from '../components/HelloWorld' +import Login from '../views/Login' +import Dashboard from '../views/Dashboard' +import store from '../store/store'; +import OAuthPermission from '../views/OAuthPermission' +import ListApps from '../views/ListApps' +import AppDetails from '../views/AppDetails' + +Vue.use(Router) + +function guard(to, from, next){ + if(store.state.loggedIn) { + next(); // allow to enter route + } else{ + store.state.redirectIfLoggedIn = to; + next('/login'); // go to '/login'; + } +} + +export default new Router({ + routes: [ + { + path: '/', + name: 'Startpage', + component: Startpage + }, + { + path: '/login', + name: 'Login', + component: Login + }, + { + path: '/oauth', + name: 'oAuthPermission', + component: OAuthPermission + }, + { + beforeEnter: guard, + path: '/dashboard', + name: 'Dashboard', + component: Dashboard + }, + { + beforeEnter: guard, + path: '/apps', + name: 'Apps', + component: ListApps + }, + { + beforeEnter: guard, + path: '/apps/:id', + name: 'appDetails', + component: AppDetails + } + ] +}) \ No newline at end of file diff --git a/src/services/Api.js b/src/services/Api.js index dcc9553c..56ed9ed9 100644 --- a/src/services/Api.js +++ b/src/services/Api.js @@ -2,7 +2,8 @@ import axios from 'axios' export default() => { return axios.create({ - baseURL: `http://localhost:8000/api/`, + baseURL: `http://127.0.0.1:8000/api/`, + //baseURL: `https://account.keks.cloud/api/`, withCredentials: false, headers: { 'Accept': 'application/json', diff --git a/src/services/Apps.js b/src/services/Apps.js new file mode 100644 index 00000000..73668543 --- /dev/null +++ b/src/services/Apps.js @@ -0,0 +1,22 @@ +import Api from '@/services/Api' + +export default { + listApps (params) { + return Api().get('/v1/app') + }, + getAppImage(id) { + return "https://account.keks.cloud/gui/apps/"+id+"/icon"; + }, + getApp(id) { + return Api().get('/v1/app/'+id) + }, + getAppByKey(key) { + return Api().get("/v1/app/find?apiKey="+key); + }, + getAccess(id) { + return Api().get('/v1/app/'+id+'/access?create=1') + }, + allowAccess(id, redirect_uri, scope) { + return Api().post('/v1/app/'+id+'/access/allow', {redirect_uri: redirect_uri, scope:scope}); + } +} \ No newline at end of file diff --git a/src/services/Server.js b/src/services/Server.js index f574b19d..ffe6cc9e 100644 --- a/src/services/Server.js +++ b/src/services/Server.js @@ -1,7 +1,7 @@ import Api from '@/services/Api' export default { - getSettings (params) { + getPublicSettings (params) { return Api().get('/v1/server/settings') } } \ No newline at end of file diff --git a/src/services/User.js b/src/services/User.js new file mode 100644 index 00000000..cdcdee50 --- /dev/null +++ b/src/services/User.js @@ -0,0 +1,21 @@ +import Api from '@/services/Api' + +export default { + login(username, password) { + return Api().post('/v1/user/login', {username: username, password: password}); + }, + + setAccessToken(access_token) { + localStorage.setItem('access_token', access_token) + Api().defaults.headers.common['Authorization'] = `Bearer ${access_token}` + }, + getTokenFromStorage() { + this.setAccessToken(localStorage.getItem("access_token")); + }, + me() { + return Api().get('/v1/user/me') + }, + logout() { + localStorage.removeItem("access_token"); + } +} \ No newline at end of file diff --git a/src/store/store.js b/src/store/store.js index 1d295b47..cffaa817 100644 --- a/src/store/store.js +++ b/src/store/store.js @@ -1,13 +1,19 @@ import Vuex from 'vuex' import Vue from 'vue' import ServerService from '../services/Server' +import UserService from '../services/User' Vue.use(Vuex) export default new Vuex.Store({ state: { settingsLoaded: false, - settings: [] // The TV inventory + loggedIn : false, + meLoaded: false, + me: [], + redirectIfLoggedIn: null, + settings: [], // The TV inventory + sideMenu: false, //Toggle Side Menu on side Bar }, getters: { @@ -21,6 +27,19 @@ export default new Vuex.Store({ return state.settings[i]["value"]; } } + }, + getAllDataLoaded: (state) => { + var loaded = true; + if(!state.meLoaded) { + loaded = false; + } + if(!state.settingsLoaded) { + loaded = false; + } + return loaded; + }, + getMe: (state) => { + return state.me; } }, @@ -28,19 +47,41 @@ export default new Vuex.Store({ setSettings: function(state, settings) { state.settings = settings; state.settingsLoaded = true; - } + }, + setMe: function(state, me) { + if(me == false) { + state.loggedIn = false; + state.meLoaded = true; + } else { + state.me = me; + state.loggedIn = true; + state.meLoaded = true; + } + }, + }, actions: { getSettings: function (context) { return new Promise((resolve, reject) => { - ServerService.getSettings().then((res) => { - console.log(res); + ServerService.getPublicSettings().then((res) => { context.commit('setSettings', res.data.data) resolve() }); }) - + }, + checkAccount: function(context) { + UserService.getTokenFromStorage(); + return new Promise((resolve, reject) => { + UserService.me().then((res) => { + console.log("GET USER DATA"); + context.commit('setMe', res.data.data) + }, (res) => { + context.commit('setMe', false) + console.log("DONT GET USER DATA"); + console.log(res.response.data) + }) + }) } } }); \ No newline at end of file diff --git a/src/views/AppDetails.vue b/src/views/AppDetails.vue new file mode 100644 index 00000000..274e45f5 --- /dev/null +++ b/src/views/AppDetails.vue @@ -0,0 +1,192 @@ + + + + + diff --git a/src/views/Dashboard.vue b/src/views/Dashboard.vue new file mode 100644 index 00000000..12a8661a --- /dev/null +++ b/src/views/Dashboard.vue @@ -0,0 +1,89 @@ + + + + + diff --git a/src/views/ListApps.vue b/src/views/ListApps.vue new file mode 100644 index 00000000..1fafe438 --- /dev/null +++ b/src/views/ListApps.vue @@ -0,0 +1,70 @@ + + + + diff --git a/src/views/Login.vue b/src/views/Login.vue new file mode 100644 index 00000000..5f963c4f --- /dev/null +++ b/src/views/Login.vue @@ -0,0 +1,100 @@ + + + + + diff --git a/src/views/OAuthPermission.vue b/src/views/OAuthPermission.vue new file mode 100644 index 00000000..380fe064 --- /dev/null +++ b/src/views/OAuthPermission.vue @@ -0,0 +1,141 @@ + + + + + diff --git a/src/components/Startpage.vue b/src/views/Startpage.vue similarity index 97% rename from src/components/Startpage.vue rename to src/views/Startpage.vue index 5b610ba7..76b6b469 100644 --- a/src/components/Startpage.vue +++ b/src/views/Startpage.vue @@ -1,6 +1,6 @@