Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion app/public/zadanie01/index.html
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
<!-- Twój kod -->
<!-- Twój kod -->

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Coders Lab</title>
<link rel="stylesheet" href="./css/style.css">
</head>
<body>
<h1>Chcesz wiedzieć czy liczba B jest dzielnikiem liczby A?</h1>
<form action="/result" method="post">
Liczba A: <input type="text" name="numberA"><br>
Liczba B: <input type="text" name="numberB"><br>
<button type="submit">Sprawdź!</button>
</form>
</body>
</html>
21 changes: 20 additions & 1 deletion app/public/zadanie02/index.html
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
<!-- Twój kod -->
<!-- Twój kod -->

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Coders Lab</title>
<link rel="stylesheet" href="./css/style.css">
</head>
<body>
<h1>Jak masz na imię?</h1>
<form action="/cookie/set" method="post">
Imię: <input type="text" name="name"><br>
<button type="submit">Wyślij!</button>
</form>
</body>
</html>
20 changes: 20 additions & 0 deletions app/public/zadanieDnia/add.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- Twój kod -->

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Coders Lab</title>
<link rel="stylesheet" href="./css/style.css">
</head>
<body>
<h1>Napisz komentarz:</h1>
<form action="/save" method="post">
<textarea name="comment" cols="40" rows="5"></textarea>
<button type="submit">Wyślij!</button>
</form>
</body>
</html>
1 change: 0 additions & 1 deletion app/public/zadanieDnia/index.html

This file was deleted.

24 changes: 23 additions & 1 deletion app/zadanie01.js
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
//Twój kod
//Twój kod

const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));

app.use(express.static('./public/zadanie01/'));

app.post('/result', (req, res) => {
const {numberA, numberB} = req.body;
let information = '';
if (parseInt(numberA) % parseInt(numberB) === 0) {
information = `Tak! Liczba ${numberB} jest dzielnikiem liczby ${numberA}`;
} else {
information = `Nie! Liczba ${numberB} nie jest dzielnikiem liczby ${numberA}`;
}
res.send(`<h1>${information}</h1>`);
});

app.listen(3000, () => {
console.log('Serwer uruchomiony na porcie 3000');
});
32 changes: 31 additions & 1 deletion app/zadanie02.js
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
//Twój kod
//Twój kod

const express = require('express');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const app = express();
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: false }));

app.use(express.static('./public/zadanie02/'));

app.post('/cookie/set', (req, res) => {
const {name} = req.body;
res.cookie('nameSaved', name, {
maxAge : 2592000000,
});
res.send(`Zapisano imię: ${name}`);
});

app.get('/cookie/show', (req, res) => {
res.send(`Zapisane imię: ${req.cookies.nameSaved}`);
});

app.get('/cookie/check', (req, res) => {
let information = req.cookies.nameSaved === undefined ? 'Nie zapisano imienia.' : 'Imię zapisane.';
res.send(information);
});

app.listen(3000, () => {
console.log('Serwer uruchomiony na porcie 3000');
});
52 changes: 51 additions & 1 deletion app/zadanieDnia.js
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
//Twój kod
//Twój kod

const express = require('express');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const app = express();
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: false }));

app.use(express.static('./public/zadanieDnia/'));

app.post('/save', (req, res) => {
const comments = addComment(req.cookies.commentSaved, req.body.comment)

res.cookie('commentSaved', comments, {
maxAge : 2592000000,
});
res.send('Zapisano komentarz <a href="/">Powrót do strony głównej</a>');
});

app.get('/', (req, res) => {
const comments = readComments(req.cookies.commentSaved);
res.send(`${comments}</br><a href="/add.html">Dodaj nowy komentarz</a>`);
});

app.listen(3000, () => {
console.log('Serwer uruchomiony na porcie 3000');
});

// Funkcje pomocnicze

/**
* Ta funkcja pobiera string dotychczasowego ciastka, dodaje nowy komentarz i zwraca nowy string - taki z jakim należy nadpisać to ciasto.
* @param {string} commentsCookieValue Wartość dotychczasowego ciastka przechowującego komentarze
* @param {string} newComment Nowy komentarz
* @return {string} Nowy string z komentarzami do zapisania w ciastku
*/
function addComment(commentsCookieValue, newComment) {
const comments = readComments(commentsCookieValue);
comments.push(newComment);
return JSON.stringify(comments);
}

/**
* Ta funkcja odczytuje już dodane komentarze i zwraca je w postaci tablicy.
* @param {string} commentsCookieValue Wartość dotychczasowego ciastka przechowującego komentarze
* @return {Array} Tablica z komentarzami
*/
function readComments(commentsCookieValue) {
return commentsCookieValue ? JSON.parse(commentsCookieValue) : [];
}