gugdun 10 mesiacov pred
rodič
commit
f4679675aa
6 zmenil súbory, kde vykonal 66 pridanie a 5 odobranie
  1. 39 0
      public/css/main.css
  2. BIN
      public/img/logout.png
  3. 6 1
      src/db.js
  4. 1 1
      src/routes/auth.js
  5. 9 3
      src/routes/index.js
  6. 11 0
      src/views/chats.ejs

+ 39 - 0
public/css/main.css

@@ -126,6 +126,45 @@ body {
     outline-width: 2px;
     outline-width: 2px;
 }
 }
 
 
+.chats-container {
+    display: flex;
+    flex-direction: column;
+    width: 100%;
+    height: 100%;
+}
+
+.chats-header {
+    display: flex;
+    flex-direction: row;
+    align-items: center;
+    width: 100%;
+    height: 64px;
+}
+
+.chat-list {
+    display: flex;
+    flex-direction: column;
+    width: 100%;
+    height: 100%;
+    overflow-y: scroll;
+}
+
+.chat-title {
+    margin: auto;
+    font-size: 18pt;
+    font-weight: 700;
+}
+
+.logout {
+    display: flex;
+    justify-content: center;
+    align-items: center;
+}
+
+.logout img {
+    width: 66%;
+}
+
 @media screen and (max-width: 600px) {
 @media screen and (max-width: 600px) {
     .hs {
     .hs {
         height: 12px;
         height: 12px;

BIN
public/img/logout.png


+ 6 - 1
src/db.js

@@ -3,5 +3,10 @@
 
 
 const pgp = require('pg-promise')();
 const pgp = require('pg-promise')();
 const db = pgp(process.env.POSTGRES_CONNECTION);
 const db = pgp(process.env.POSTGRES_CONNECTION);
-db.none("CREATE TABLE IF NOT EXISTS users ( id SERIAL PRIMARY KEY, username TEXT UNIQUE, hashed_password BYTEA, salt BYTEA )");
+(async () => {
+    await db.none("CREATE TABLE IF NOT EXISTS users ( id SERIAL PRIMARY KEY, username TEXT UNIQUE, hashed_password BYTEA, salt BYTEA )");
+    await db.none("CREATE TABLE IF NOT EXISTS chats ( id SERIAL PRIMARY KEY, user1_id INTEGER, user2_id INTEGER, CONSTRAINT user1_fk FOREIGN KEY (user1_id) REFERENCES users (id), CONSTRAINT user2_fk FOREIGN KEY (user2_id) REFERENCES users (id) )")
+    await db.none("CREATE TABLE IF NOT EXISTS attachments ( id SERIAL PRIMARY KEY, type TEXT NOT NULL, data BYTEA ) ")
+    await db.none("CREATE TABLE IF NOT EXISTS messages ( id SERIAL PRIMARY KEY, chat_id INTEGER, user_id INTEGER, attachment_id INTEGER, text TEXT, CONSTRAINT chat_fk FOREIGN KEY (chat_id) REFERENCES chats (id), CONSTRAINT user_fk FOREIGN KEY (user_id) REFERENCES users (id), CONSTRAINT attachment_fk FOREIGN KEY (attachment_id) REFERENCES attachments (id) )")
+})();
 module.exports = db;
 module.exports = db;

+ 1 - 1
src/routes/auth.js

@@ -63,7 +63,7 @@ router.post("/register", (req, res, next) => {
     });
     });
 });
 });
 
 
-router.post("/logout", function (req, res, next) {
+router.get("/logout", function (req, res, next) {
     req.logout(function (err) {
     req.logout(function (err) {
         if (err) { return next(err); }
         if (err) { return next(err); }
         res.redirect("/");
         res.redirect("/");

+ 9 - 3
src/routes/index.js

@@ -11,9 +11,15 @@ const views = path.join(__dirname, "..", "views");
 const router = express.Router();
 const router = express.Router();
 
 
 router.get("/", async (req, res) => {
 router.get("/", async (req, res) => {
-    res.render("layout", {
-        child: await ejs.renderFile(path.join(views, "home.ejs"))
-    });
+    if (req.user) {
+        res.render("layout", {
+            child: await ejs.renderFile(path.join(views, "chats.ejs"))
+        });
+    } else {
+        res.render("layout", {
+            child: await ejs.renderFile(path.join(views, "home.ejs"))
+        });
+    }
 });
 });
 
 
 router.get("/login", async (req, res) => {
 router.get("/login", async (req, res) => {

+ 11 - 0
src/views/chats.ejs

@@ -0,0 +1,11 @@
+<div class="chats-container">
+    <div class="chats-header">
+        <span class="chat-title">Chats</span>
+        <a href="/logout" class="logout">
+            <img src="/img/logout.png" class="logout" />
+        </a>
+    </div>
+    <div class="chat-list">
+
+    </div>
+</div>