From d7ebb12451cca9555e3b8f871d88ef94e2210eea Mon Sep 17 00:00:00 2001 From: amnesia Date: Thu, 29 Feb 2024 16:52:41 -0500 Subject: [PATCH] working login --- .env | 3 + quasar.config.ts | 4 +- src/layouts/AuthLayout.vue | 55 ++++++++++++++ src/layouts/MainLayout.vue | 101 ++++++++++++++++++++++++-- src/pages/IndexPage.vue | 139 ++++++++++++++++++++++++++++++------ src/pages/TodayDelivery.vue | 100 ++++++++++++++++++++++++-- src/pages/auth/Login.vue | 132 ++++++++++++++++++++++++++++++++++ src/router/routes.ts | 18 +++-- src/services/auth.header.ts | 12 ++++ 9 files changed, 523 insertions(+), 41 deletions(-) create mode 100644 .env create mode 100644 src/layouts/AuthLayout.vue create mode 100644 src/pages/auth/Login.vue create mode 100644 src/services/auth.header.ts diff --git a/.env b/.env new file mode 100644 index 0000000..0f32182 --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ +VITE_BASE_URL="http://localhost:4056" +VITE_PAY_URL="http://localhost:4052" +VITE_AUTO_URL="http://localhost:4053" \ No newline at end of file diff --git a/quasar.config.ts b/quasar.config.ts index 67eb512..a4ecce4 100644 --- a/quasar.config.ts +++ b/quasar.config.ts @@ -88,7 +88,7 @@ export default configure((/* ctx */) => { // https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#framework framework: { - config: {dark: true,}, + config: {dark: true, }, // iconSet: 'material-icons', // Quasar icon set // lang: 'en-US', // Quasar language pack @@ -101,7 +101,7 @@ export default configure((/* ctx */) => { // directives: [], // Quasar plugins - plugins: [] + plugins: ['Notify'] }, // animations: 'all', // --- includes all animations diff --git a/src/layouts/AuthLayout.vue b/src/layouts/AuthLayout.vue new file mode 100644 index 0000000..3520f92 --- /dev/null +++ b/src/layouts/AuthLayout.vue @@ -0,0 +1,55 @@ + + + + + diff --git a/src/layouts/MainLayout.vue b/src/layouts/MainLayout.vue index 3eaee65..2b562de 100644 --- a/src/layouts/MainLayout.vue +++ b/src/layouts/MainLayout.vue @@ -15,6 +15,18 @@ Auburn Oil
+
+ Welcome {{employee.employee_first_name}} {{employee.employee_last_name}} +
+
+ + + + +
+ + +
@@ -25,6 +37,18 @@ bordered > + + + + + + + + Home + + + + @@ -38,8 +62,8 @@ - - + + label @@ -87,7 +111,8 @@ import {defineComponent} from 'vue' import EssentialLink from 'components/EssentialLink.vue' import {useRoute} from 'vue-router' // - +import authHeader from "../services/auth.header" +import axios from "axios" export default defineComponent({ name: 'MainLayout', @@ -98,15 +123,79 @@ export default defineComponent({ data() { return { + user: { + user_id: 0, + uuid: '', + api_key: '', + username: '', + password_hash: '', + member_since: '', + email: '', + last_seen: '', + admin: 0, + admin_role: 0, + confirmed: 0, + + }, + loaded: false, + employee: { + id: '', + employee_last_name: "", + employee_first_name: "", + employee_town: "", + employee_address: "", + employee_apt: "", + employee_zip: "", + employee_birthday: "", + employee_phone_number: "", + employee_start_date: "", + employee_end_date: "", + employee_type: '', + employee_state: '', + }, leftDrawerOpen: false, } }, + created() { + this.userStatus() + }, methods: { toggleLeftDrawer() { this.leftDrawerOpen = !this.leftDrawerOpen - } + }, + userStatus() { + let path = import.meta.env.VITE_BASE_URL + '/auth/whoami'; + axios({ + method: 'get', + url: path, + withCredentials: true, + headers: authHeader(), + }) + .then((response: any) => { + if (response.data.ok) { + this.user = response.data.user; + this.getEmployee(this.user.user_id) + } + }) + }, + getEmployee(userid: any) { + let path = import.meta.env.VITE_BASE_URL + "/employee/" + userid; + axios({ + method: "get", + url: path, + withCredentials: true, + headers: authHeader(), + }) + .then((response: any) => { + if (response.data) { + + this.employee = response.data; + this.loaded = true; + } + }) + }, } }) @@ -114,8 +203,8 @@ export default defineComponent({ diff --git a/src/pages/IndexPage.vue b/src/pages/IndexPage.vue index ffd6799..27ca742 100644 --- a/src/pages/IndexPage.vue +++ b/src/pages/IndexPage.vue @@ -1,36 +1,135 @@ diff --git a/src/pages/TodayDelivery.vue b/src/pages/TodayDelivery.vue index 4d7b4bc..cd51ecd 100644 --- a/src/pages/TodayDelivery.vue +++ b/src/pages/TodayDelivery.vue @@ -1,18 +1,104 @@ + + + diff --git a/src/pages/auth/Login.vue b/src/pages/auth/Login.vue new file mode 100644 index 0000000..76cb5cd --- /dev/null +++ b/src/pages/auth/Login.vue @@ -0,0 +1,132 @@ + + + + + diff --git a/src/router/routes.ts b/src/router/routes.ts index a789a17..6524d06 100644 --- a/src/router/routes.ts +++ b/src/router/routes.ts @@ -5,15 +5,21 @@ const routes: RouteRecordRaw[] = [ path: '/', component: () => import('layouts/MainLayout.vue'), children: [ - { path: '', component: () => import('pages/IndexPage.vue') }, - { path: '/today', name: 'today', component: () => import('pages/TodayDelivery.vue') }, - { path: '/tomorrow', name: 'tomorrow', component: () => import('pages/TomorrowDelivery.vue') }, - { path: '/automatic', name: 'automatic', component: () => import('pages/Automatics.vue') }, - { path: '/stats', name: 'stats', component: () => import('pages/DriverStats.vue') }, + { path: '', name: 'home', component: () => import('pages/IndexPage.vue') }, + { path: '/today', name: 'today', component: () => import('pages/TodayDelivery.vue') }, + { path: '/tomorrow', name: 'tomorrow', component: () => import('pages/TomorrowDelivery.vue') }, + { path: '/automatic', name: 'automatic', component: () => import('pages/Automatics.vue') }, + { path: '/stats', name: 'stats', component: () => import('pages/DriverStats.vue') }, ] }, - +{ + path: '/auth', + component: () => import('layouts/AuthLayout.vue'), + children: [ + { path: '/login', name: 'login', component: () => import('pages/auth/Login.vue') }, + ] + }, // Always leave this as last one, // but you can also remove it diff --git a/src/services/auth.header.ts b/src/services/auth.header.ts new file mode 100644 index 0000000..a8672c2 --- /dev/null +++ b/src/services/auth.header.ts @@ -0,0 +1,12 @@ +export default function authHeader (): Record { + + let user_token = localStorage.getItem('auth_user') + let auth_token = localStorage.getItem('auth_token') + + if (user_token && auth_token) { + return { 'Authorization': 'bearer ' + auth_token }; + } + else { + return {'Authorization': 'None'}; + } +}