diff --git a/.gitignore b/.gitignore index a3bbd943..f6132c14 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,5 @@ coverage /playwright-report/ /playwright/.cache/ # Webkit with playwright creates a salt file -salt \ No newline at end of file +salt +package-lock.json diff --git a/DockerfileWithToken b/DockerfileWithToken new file mode 100644 index 00000000..2789eb98 --- /dev/null +++ b/DockerfileWithToken @@ -0,0 +1,18 @@ +# build stage +FROM node:lts-alpine AS build-stage +# Set environment variables for non-interactive npm installs +ENV NPM_CONFIG_LOGLEVEL warn +ENV CI true +ENV VITE_TOKEN "your_token" +WORKDIR /app +COPY package.json pnpm-lock.yaml ./ +RUN npm install -g pnpm && pnpm i --frozen-lockfile +COPY . . +RUN pnpm build + +# production stage +FROM nginx:stable-alpine AS production-stage +COPY --from=build-stage /app/dist /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] diff --git a/README.md b/README.md index a13246e8..aefdb6d6 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,15 @@ docker run -d --name it-tools --restart unless-stopped -p 8080:80 ghcr.io/corent - [Tipi](https://www.runtipi.io/docs/apps-available) - [Unraid](https://unraid.net/community/apps?q=it-tools) +## Public +If you want to add permission verification when users access the website, you can build and run the image using the following method. This approach will require users to enter a token before they can continue using the site. +```sh +cd it-tools +# vim DockerfileWithToken, change your_token to the token you want to use +docker build -f DockerfileWithToken -t it-tools:token . +docker run -d --name it-tools --restart unless-stopped -p 8080:80 it-tools:token +``` + ## Contribute ### Recommended IDE Setup diff --git a/components.d.ts b/components.d.ts index 3e65c3cc..57c3a65a 100644 --- a/components.d.ts +++ b/components.d.ts @@ -118,6 +118,7 @@ declare module '@vue/runtime-core' { KeycodeInfo: typeof import('./src/tools/keycode-info/keycode-info.vue')['default'] ListConverter: typeof import('./src/tools/list-converter/list-converter.vue')['default'] LocaleSelector: typeof import('./src/modules/i18n/components/locale-selector.vue')['default'] + Login: typeof import('./src/pages/Login.vue')['default'] LoremIpsumGenerator: typeof import('./src/tools/lorem-ipsum-generator/lorem-ipsum-generator.vue')['default'] MacAddressGenerator: typeof import('./src/tools/mac-address-generator/mac-address-generator.vue')['default'] MacAddressLookup: typeof import('./src/tools/mac-address-lookup/mac-address-lookup.vue')['default'] diff --git a/src/config.ts b/src/config.ts index fa2421ef..461a89ea 100644 --- a/src/config.ts +++ b/src/config.ts @@ -27,6 +27,12 @@ export const config = figue({ default: 'development', env: 'VITE_VERCEL_ENV', }, + token: { + doc: 'Application token', + format: 'string', + default: '', + env: 'VITE_TOKEN', + }, }, plausible: { isTrackerEnabled: { diff --git a/src/pages/Login.vue b/src/pages/Login.vue new file mode 100644 index 00000000..f896af54 --- /dev/null +++ b/src/pages/Login.vue @@ -0,0 +1,120 @@ + + + + + diff --git a/src/router.ts b/src/router.ts index da0c4f1e..8d71ca1d 100644 --- a/src/router.ts +++ b/src/router.ts @@ -26,6 +26,11 @@ const router = createRouter({ name: 'home', component: HomePage, }, + { + path: '/login', + name: 'login', + component: () => import('./pages/Login.vue'), + }, { path: '/about', name: 'about', @@ -38,4 +43,15 @@ const router = createRouter({ ], }); +if (config.app.token){ + router.beforeEach((to, from, next) => { + const isLoggedIn = localStorage.getItem('isLoggedIn') === 'true'; + if (to.path !== '/login' && !isLoggedIn) { + next('/login'); + } else { + next(); + } + }); +} + export default router;