commit
This commit is contained in:
parent
0bac40a72f
commit
8ace4a6356
6 changed files with 32 additions and 7 deletions
2
.dockerignore
Normal file
2
.dockerignore
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
package-lock.json
|
||||||
|
node_modules/
|
9
DOCKERFILE
Normal file
9
DOCKERFILE
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
FROM node:latest
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY . /app
|
||||||
|
|
||||||
|
RUN npm i
|
||||||
|
|
||||||
|
CMD ["npm", "run", "start"]
|
|
@ -12,11 +12,11 @@ router.post('/', async (req, res) => {
|
||||||
const user = await getUser(username);
|
const user = await getUser(username);
|
||||||
|
|
||||||
if (!user[0]) {
|
if (!user[0]) {
|
||||||
return res.status(500).send({error: "wrong login informations"});
|
return res.status(400).send({error: "wrong login informations"});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(sha256(password) == user[0].password)) {
|
if (!(sha256(password) == user[0].password)) {
|
||||||
return res.status(500).send({error: "wrong login informations"});
|
return res.status(400).send({error: "wrong login informations"});
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(200).send({message: "connection successful", token: jwt.sign({username: username, expiration: 20000}, process.env.JWTSecret)});
|
res.status(200).send({message: "connection successful", token: jwt.sign({username: username, expiration: 20000}, process.env.JWTSecret)});
|
||||||
|
|
|
@ -9,13 +9,13 @@ router.post('/', async (req, res) => {
|
||||||
const {username, name, lastname, password} = req.body;
|
const {username, name, lastname, password} = req.body;
|
||||||
|
|
||||||
if (!username || !name || !lastname || !password) {
|
if (!username || !name || !lastname || !password) {
|
||||||
return res.status(500).send({error: "invalid request"});
|
return res.status(400).send({error: "invalid request"});
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await getUser(username);
|
const user = await getUser(username);
|
||||||
|
|
||||||
if (user[0]) {
|
if (user[0]) {
|
||||||
return res.status(500).send({error: "user already exist"});
|
return res.status(400).send({error: "user already exist"});
|
||||||
}
|
}
|
||||||
|
|
||||||
await addUser(username, name, lastname, sha256(password));
|
await addUser(username, name, lastname, sha256(password));
|
||||||
|
|
|
@ -8,12 +8,14 @@ const router = express.Router();
|
||||||
router.post('/', async (req, res) => {
|
router.post('/', async (req, res) => {
|
||||||
const {token} = req.body;
|
const {token} = req.body;
|
||||||
|
|
||||||
let user;
|
if (!token) {
|
||||||
|
return res.status(400).send({error: "invalid token"});
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
user = jwt.verify(token, process.env.JWTSecret);
|
jwt.verify(token, process.env.JWTSecret);
|
||||||
} catch {
|
} catch {
|
||||||
return res.status(500).send({error: "invalid token"});
|
return res.status(400).send({error: "invalid token"});
|
||||||
}
|
}
|
||||||
|
|
||||||
const games = await getGames();
|
const games = await getGames();
|
||||||
|
|
12
docker-compose.yml
Normal file
12
docker-compose.yml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
version: '3.1'
|
||||||
|
|
||||||
|
services:
|
||||||
|
joclud_api:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: DOCKERFILE
|
||||||
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- /full/path/to/bot:/app
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
Loading…
Add table
Add a link
Reference in a new issue