Skip to content

Commit

Permalink
#5 start login and database
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcellino-Palerme committed Oct 26, 2023
1 parent a24f41b commit c1d25b3
Show file tree
Hide file tree
Showing 16 changed files with 778 additions and 152 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: deploy

on:
push:
branches: '*'
branches: 'main'

jobs:
deplou:
Expand Down Expand Up @@ -30,9 +30,21 @@ jobs:
- name: Copy docker files on server
run: |
scp -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa Dockerfile compose.yaml ${{ secrets.USERNAME }}@${{ secrets.HOST }}:~
- name: Create env file
run: |
ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.USERNAME }}@${{ secrets.HOST }} "mkdir secrets"
ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.USERNAME }}@${{ secrets.HOST }} "echo PGPASSWORD=${{ secrets.PASS }} > ./secrets/pg.env"
ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.USERNAME }}@${{ secrets.HOST }} "echo PGUSER=epm2m2 >> ./secrets/pg.env"
ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.USERNAME }}@${{ secrets.HOST }} "echo PGPORT=5432 >> ./secrets/pg.env"
ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.USERNAME }}@${{ secrets.HOST }} "echo PGDATABASE=ep2m2db >> ./secrets/pg.env"
ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.USERNAME }}@${{ secrets.HOST }} "echo POSTGRES_PASSWORD=${{ secrets.PASS }} >> ./secrets/pg.env"
ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.USERNAME }}@${{ secrets.HOST }} "echo POSTGRES_USER=epm2m2 >> ./secrets/pg.env"
- name: RUN on server
run: |
ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.USERNAME }}@${{ secrets.HOST }} "echo ${{ secrets.PASS }}| sudo -S docker compose -f \"compose.yaml\" up -d --build"
ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.USERNAME }}@${{ secrets.HOST }} "docker compose -f \"compose.yaml\" up -d --build"
- name: Delete files
run: |
ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.USERNAME }}@${{ secrets.HOST }} "rm -rf ~/.output"
ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.USERNAME }}@${{ secrets.HOST }} "rm Dockerfile"
ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.USERNAME }}@${{ secrets.HOST }} "rm compose.yaml"
ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.USERNAME }}@${{ secrets.HOST }} "rm -rf ./secrets"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ logs
# sample file
sample/*
.vscode/settings.json
secrets/pg.env
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ EXPOSE 3000
RUN mkdir /results
ENV EP2M2_DIR_SHARE=/shareFile
ENV EP2M2_DIR_RESULT=/results
CMD [ "node", "./server/index.mjs" ]
ENV PGHOST=db
CMD ["node", "./server/index.mjs"]
40 changes: 39 additions & 1 deletion app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,41 @@
import banner from "./components/BannerMain.vue";
import extras from "./components/ExtrasNav.vue";
import extract from "./components/ExtractInfo.vue";
import login from "./components/LoginForm.vue";
import { useCookie } from "nuxt/app";

</script>

<script lang="ts">
export default{
data(){
return {checkSession: false};
},
created:async function() {
const token = await useCookie("token");

console.log("hein");
console.log(token.value);


if (!token.value){
this.checkSession = false;
return null;
}


this.checkSession = await $fetch("/api/checkToken", {
method: "POST",
body: token.value
});


}
};
</script>

<template>
<UCard>
<UCard v-if="checkSession">
<template #header>
<UContainer class="flex justify-between">
<banner />
Expand All @@ -25,6 +55,14 @@ import extract from "./components/ExtractInfo.vue";

<!-- <template #footer/> -->
</UCard>
<UCard v-else>
<template #header>
<UContainer class="flex justify-between">
<banner />
</UContainer>
<login />
</template>
</UCard>
</template>

<style>
Expand Down
75 changes: 75 additions & 0 deletions components/LoginForm.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<script setup lang="ts">
import { ref } from "vue";
import { string, object, email, minLength, Input } from "valibot";
import type { FormSubmitEvent } from "@nuxt/ui/dist/runtime/types";
const schema = object({
email: string([email("Invalid email")]),
password: string([minLength(8, "Must be at least 8 characters")])
});
type Schema = Input<typeof schema>
const state = ref({
email: undefined,
password: undefined
});
async function submit (event: FormSubmitEvent<Schema>) {
// Do something with event.data
console.log(event.data);
console.log(state);
const result = await $fetch("/api/checkLogin", {
method:"POST",
body:{email:state.value.email, password:state.value.password}
});
console.log(result);
}
</script>

<template>
<UContainer class="flex justify-around items-center">
<UForm
class="form"
:schema="schema"
:state="state"
@submit="submit"
>
<UFormGroup
label="Email"
name="email"
>
<UInput v-model="state.email" />
</UFormGroup>

<UFormGroup
label="Password"
name="password"
>
<UInput
v-model="state.password"
type="password"
/>
</UFormGroup>

<UButton type="submit">
Submit
</UButton>
</UForm>
</UContainer>
</template>

<style>
.form {
justify-content: center;
width: 50%;
}
</style>

12 changes: 12 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,28 @@ services:
- "80:3000"
volumes:
- shareFile:/shareFile
env_file:
- ./secrets/pg.env


api:
image: inraep2m2/service-p2m2tools-api:latest
container_name: p2m2ToolsApi
volumes:
- shareFile:/shareFile

db:
image: postgres
container_name: db
volumes:
- ./db/init.sql:/docker-entrypoint-initdb.d/init.sql
env_file:
- ./secrets/pg.env

volumes:
shareFile:





55 changes: 55 additions & 0 deletions db/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
-- CREATE USER ep2m2 WITH PASSWORD 'ep2m2';
CREATE DATABASE ep2m2db;
GRANT ALL PRIVILEGES ON DATABASE ep2m2db TO ep2m2;

\c ep2m2db ep2m2

CREATE TABLE verification_token
(
identifier TEXT NOT NULL,
expires TIMESTAMPTZ NOT NULL,
token TEXT NOT NULL,

PRIMARY KEY (identifier, token)
);

CREATE TABLE accounts
(
id SERIAL,
"userId" INTEGER NOT NULL,
type VARCHAR(255) NOT NULL,
provider VARCHAR(255) NOT NULL,
"providerAccountId" VARCHAR(255) NOT NULL,
refresh_token TEXT,
access_token TEXT,
expires_at BIGINT,
id_token TEXT,
scope TEXT,
session_state TEXT,
token_type TEXT,

PRIMARY KEY (id)
);

CREATE TABLE sessions
(
id SERIAL,
"userId" INTEGER NOT NULL,
expires TIMESTAMPTZ NOT NULL,
"sessionToken" VARCHAR(255) NOT NULL,

PRIMARY KEY (id)
);

CREATE TABLE users
(
id SERIAL,
name VARCHAR(255),
lastname VARCHAR(255),
email VARCHAR(255),
"emailVerified" TIMESTAMPTZ,
hash VARCHAR(255),
image TEXT,

PRIMARY KEY (id)
);
2 changes: 1 addition & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
import {} from 'nuxt'
import {} from "nuxt";

export default defineNuxtConfig({
devtools: { enabled: true },
Expand Down
Loading

0 comments on commit c1d25b3

Please sign in to comment.