Compare commits

..

2 commits

Author SHA1 Message Date
Nathan Lamy
3058fe2ea2 feat: improve auth flow 2025-08-21 18:46:29 +02:00
Nathan Lamy
deacf02a18 chore: add docker build 2025-08-21 18:01:20 +02:00
6 changed files with 73 additions and 32 deletions

20
.dockerignore Normal file
View file

@ -0,0 +1,20 @@
# Adonis default .gitignore ignores
node_modules
build
coverage
.vscode
.DS_STORE
.env
tmp
# Additional .gitignore ignores (any custom file you wish)
.idea
# Additional good to have ignores for dockerignore
Dockerfile*
docker-compose*
.dockerignore
*.md
.git
.gitignore
data/

View file

@ -1,25 +1,23 @@
ARG NODE_IMAGE=node:22-slim
ARG NODE_IMAGE=node:22-alpine
###### First Stage - Creating base ######
FROM $NODE_IMAGE as base
RUN mkdir -p /home/node/app && chown node:node /home/node/app
RUN npm install --global pnpm
FROM $NODE_IMAGE AS base
RUN apk --no-cache add dumb-init
RUN mkdir -p /home/node/app && chown node:node /home/node/app
RUN npm install -g pnpm
WORKDIR /home/node/app
USER node
RUN mkdir tmp
###### Second Stage - Installing dependencies ######
FROM base AS dependencies
COPY --chown=node:node ./package*.json ./
COPY --chown=node:node ./package.json ./
COPY --chown=node:node ./pnpm-lock.yaml ./
RUN pnpm install
COPY --chown=node:node . .
###### Third Stage - Building Stage ######
FROM dependencies AS build
RUN node ace build
###### Final Stage - Production ######
FROM base as production
FROM base AS production
ENV NODE_ENV=production
ENV PORT=3333
ENV HOST=0.0.0.0
@ -28,3 +26,4 @@ COPY --chown=node:node ./pnpm-lock.yaml ./
RUN pnpm install --prod
COPY --chown=node:node --from=build /home/node/app/build .
EXPOSE 3333
CMD [ "dumb-init", "node", "bin/server.js" ]

View file

@ -6,6 +6,7 @@ import { inject } from '@adonisjs/core'
import app from '@adonisjs/core/services/app'
import env from '#start/env'
import User from '#models/user'
import { DateTime } from 'luxon'
@inject()
export default class AuthController {
@ -89,9 +90,16 @@ export default class AuthController {
}
}
const lastYear = DateTime.now().minus({ years: 1 })
return User.query()
.select('firstName', 'lastName')
.select('firstName', 'lastName', 'id')
.where('className', className)
.whereExists((query) => {
query
.from('colles')
.whereRaw('colles.student_id = users.id')
.where('colles.date', '>=', lastYear.toISODate())
})
.orderBy('lastName', 'asc')
.then((users) => {
return {
@ -99,6 +107,7 @@ export default class AuthController {
data: users.map((user) => ({
value: `${user.firstName}::${user.lastName}`,
label: user.fullName,
userId: user.id,
})),
}
})
@ -106,12 +115,11 @@ export default class AuthController {
// POST /auth/register
async register({ request, response, auth }: HttpContext) {
const { name, className, token } = await request.validateUsing(registerValidator)
const { userId, className, token } = await request.validateUsing(registerValidator)
// Validate token
const { success, email } = this.authService.validateToken(token)
const [firstName, lastName] = name.split('::')
if (!success || !email || !firstName || !lastName) {
if (!success || !email) {
return response.badRequest({
success: false,
message: 'Votre lien de connexion est invalide ou a expiré.',
@ -119,8 +127,7 @@ export default class AuthController {
}
const user = await User.query()
.where('firstName', firstName)
.where('lastName', lastName)
.where('id', userId)
.where('className', className)
.first()
if (!user) {

View file

@ -21,7 +21,7 @@ export const verifyCodeValidator = vine.compile(
export const registerValidator = vine.compile(
vine.object({
name: vine.string().minLength(2).maxLength(50).trim(),
userId: vine.number().positive(),
className: vine.string().minLength(2).maxLength(50),
token: vine.string(),
})

2
build.sh Executable file
View file

@ -0,0 +1,2 @@
docker build -t git.lamy-charrier.fr/khollise/api:v1.0 .
# docker push git.lamy-charrier.fr/khollise/api:v1.0

View file

@ -4,7 +4,7 @@ services:
container_name: khollise-redis
restart: unless-stopped
ports:
- "127.0.0.1:6379:6379"
- '127.0.0.1:6379:6379'
postgres:
image: postgres:15
@ -17,19 +17,32 @@ services:
volumes:
- ./data:/var/lib/postgresql/data
ports:
- "127.0.0.1:5432:5432"
- '127.0.0.1:5432:5432'
pgadmin:
image: dpage/pgadmin4
container_name: pgadmin4_container
restart: unless-stopped
ports:
- "8888:80"
environment:
PGADMIN_DEFAULT_EMAIL: nathan@lamy-charrier.fr
PGADMIN_DEFAULT_PASSWORD: securepass
volumes:
- pgadmin-data:/var/lib/pgadmin
api:
image: git.lamy-charrier.fr/khollise/api:v1.0
container_name: khollise-api
restart: unless-stopped
depends_on:
- redis
- postgres
# Link env file
env_file:
- ./prod.env
ports:
- '3333:3333'
volumes:
pgadmin-data:
# pgadmin:
# image: dpage/pgadmin4
# container_name: pgadmin4_container
# restart: unless-stopped
# ports:
# - "8888:80"
# environment:
# PGADMIN_DEFAULT_EMAIL: nathan@lamy-charrier.fr
# PGADMIN_DEFAULT_PASSWORD: securepass
# volumes:
# - pgadmin-data:/var/lib/pgadmin
# volumes:
# pgadmin-data: