Réparation du docker-compose de la base de données Mongo et début de l'authentification
This commit is contained in:
parent
5af779e6e5
commit
44370a1b00
5 changed files with 56 additions and 19 deletions
|
@ -1,14 +1,14 @@
|
|||
services:
|
||||
mongodb:
|
||||
image: mongo:latest
|
||||
build: ./mongodb_rs
|
||||
hostname: mongodb
|
||||
restart: always
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
- MONGO_INITDB_ROOT_USERNAME=temp-root-username
|
||||
- MONGO_INITDB_ROOT_PASSWORD=temp-password
|
||||
- MONGO_INITDB_DATABASE=chat_projetweb
|
||||
- MONGO_REPLICA_HOST=localhost
|
||||
- MONGO_REPLICA_PORT=27017
|
||||
ports:
|
||||
- "27017:27017"
|
||||
volumes:
|
||||
|
|
11
mongodb_rs/Dockerfile
Normal file
11
mongodb_rs/Dockerfile
Normal file
|
@ -0,0 +1,11 @@
|
|||
FROM mongo:5
|
||||
|
||||
# we take over the default & start mongo in replica set mode in a background task
|
||||
ENTRYPOINT mongod --port $MONGO_REPLICA_PORT --replSet rs0 --bind_ip 0.0.0.0 & MONGOD_PID=$!; \
|
||||
# we prepare the replica set with a single node and prepare the root user config
|
||||
INIT_REPL_CMD="rs.initiate({ _id: 'rs0', members: [{ _id: 0, host: '$MONGO_REPLICA_HOST:$MONGO_REPLICA_PORT' }] })"; \
|
||||
INIT_USER_CMD="db.getUser('$MONGO_INITDB_ROOT_USERNAME') || db.createUser({ user: '$MONGO_INITDB_ROOT_USERNAME', pwd: '$MONGO_INITDB_ROOT_PASSWORD', roles: ['root'] })"; \
|
||||
# we wait for the replica set to be ready and then submit the command just above
|
||||
until (mongo admin --port $MONGO_REPLICA_PORT --eval "$INIT_REPL_CMD && $INIT_USER_CMD"); do sleep 1; done; \
|
||||
# we are done but we keep the container by waiting on signals from the mongo task
|
||||
echo "REPLICA SET ONLINE"; wait $MONGOD_PID;
|
|
@ -14,7 +14,7 @@ datasource db {
|
|||
}
|
||||
|
||||
model User {
|
||||
id String @id @default(cuid()) @map("_id") @db.ObjectId
|
||||
id String @id @default(auto()) @map("_id") @db.ObjectId
|
||||
username String @unique
|
||||
surname String
|
||||
name String
|
||||
|
@ -28,7 +28,7 @@ model User {
|
|||
}
|
||||
|
||||
model Channel {
|
||||
id String @id @default(cuid()) @map("_id") @db.ObjectId
|
||||
id String @id @default(auto()) @map("_id") @db.ObjectId
|
||||
name String
|
||||
topic String
|
||||
users User[] @relation(fields: [userIDs], references: [id])
|
||||
|
@ -39,7 +39,7 @@ model Channel {
|
|||
}
|
||||
|
||||
model Message {
|
||||
id String @id @default(cuid()) @map("_id") @db.ObjectId
|
||||
id String @id @default(auto()) @map("_id") @db.ObjectId
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
userId String @db.ObjectId
|
||||
channel Channel @relation(fields: [channelId], references: [id])
|
||||
|
|
21
src/routes/+page.server.ts
Normal file
21
src/routes/+page.server.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import type { Actions } from '@sveltejs/kit';
|
||||
import prismaClient from '$lib/prismaClient';
|
||||
|
||||
export const actions: Actions = {
|
||||
login: async ({request}) => {
|
||||
const formData = await request.formData();
|
||||
|
||||
console.log(formData.get("username"));
|
||||
|
||||
await prismaClient.user.create({
|
||||
data: {
|
||||
email: "fdp",
|
||||
username: "test",
|
||||
surname: "azeza",
|
||||
name: "aiudhza",
|
||||
password: "feur"
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
|
@ -3,6 +3,9 @@
|
|||
import { Button } from "$lib/components/ui/button";
|
||||
import { Input } from "$lib/components/ui/input";
|
||||
import * as Card from "$lib/components/ui/card";
|
||||
import { enhance } from '$app/forms';
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<div class="w-full h-full flex justify-center items-center">
|
||||
|
@ -11,18 +14,20 @@
|
|||
<Card.Title>🌳</Card.Title>
|
||||
<Card.Description>Un chat collaboratif</Card.Description>
|
||||
</Card.Header>
|
||||
<Card.Content>
|
||||
<div class="grid w-full max-w-sm items-center gap-1.5">
|
||||
<Label for="username">Nom d'utilisateur</Label>
|
||||
<Input type="text" id="username" />
|
||||
</div>
|
||||
<div class="pt-4 grid w-full max-w-sm items-center gap-1.5">
|
||||
<Label for="password">Mot de passe</Label>
|
||||
<Input type="password" id="password" />
|
||||
</div>
|
||||
</Card.Content>
|
||||
<Card.Footer>
|
||||
<Button>Se connecter</Button>
|
||||
</Card.Footer>
|
||||
<form method="POST" action="?/login" use:enhance>
|
||||
<Card.Content>
|
||||
<div class="grid w-full max-w-sm items-center gap-1.5">
|
||||
<Label for="username">Nom d'utilisateur</Label>
|
||||
<Input type="text" name="username" id="username" />
|
||||
</div>
|
||||
<div class="pt-4 grid w-full max-w-sm items-center gap-1.5">
|
||||
<Label for="password">Mot de passe</Label>
|
||||
<Input type="password" name="password" id="password" />
|
||||
</div>
|
||||
</Card.Content>
|
||||
<Card.Footer>
|
||||
<Button type="submit">Se connecter</Button>
|
||||
</Card.Footer>
|
||||
</form>
|
||||
</Card.Root>
|
||||
</div>
|
Loading…
Add table
Reference in a new issue