From 3ad790ff89a79fa4b836153d3572e48272ca22a5 Mon Sep 17 00:00:00 2001 From: Matjaz Date: Fri, 11 Feb 2022 20:02:52 +0100 Subject: [PATCH] Login sistem deluje. --- database/socialbot.db | Bin 45056 -> 45056 bytes models/index.js | 4 ++-- routes/index.js | 27 ++++++++++++++++++--------- views/index.ejs | 10 +++++----- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/database/socialbot.db b/database/socialbot.db index 5d8aa45c2dce28d54784c03557ef7e779495be09..6c5902b227f36b9e54f2f2b4d9679b4a2764fe3c 100644 GIT binary patch delta 136 zcmZp8z|`=7X@WH4!ih4@j0-m=O!a4E+x*R+Pk@<`-+eQCf)l?k8wW#Zqo$`Pr>RA< zNveURxvr_DS)#6qacY{bg`q);ZlXzwNn)yDvUzH<#pJztVY-Hf3WnxZ#s*fV=6c4K bMhe;n237_JMg~Skx&}t*vYUVAvpWC)Rc9ny delta 117 zcmZp8z|`=7X@WH4{E0HojPo}pO!ensWnf_7;tVZLEh^^S%-Fypz{HchnLWXYUzd@C zA+%A`)04r#%rrUGI5Al_Eh#ls*CaJ1RoBueIZ4+j&D=OGB`qbz*wAqD-n^K}ALg?& U8cbfFD+XdQ8CY)qna}P30Px@>vj6}9 diff --git a/models/index.js b/models/index.js index c475401..0645cc5 100644 --- a/models/index.js +++ b/models/index.js @@ -26,8 +26,8 @@ fs db.User.belongsToMany(db.Message, {foreignKey: 'UserId', through: 'UserMessages'}); db.Message.belongsTo(db.User, {through: 'UserMessages'}); - db.User.belongsToMany(db.Session, {foreignKey: 'UserId', through: 'UserSessions'}); - db.Session.belongsTo(db.User, {through: 'UserSessions'}); + db.User.hasMany(db.Session); + db.Session.belongsTo(db.User); Object.keys(db).forEach(modelName => { if (db[modelName].associate) { diff --git a/routes/index.js b/routes/index.js index d0f44dd..4c06968 100644 --- a/routes/index.js +++ b/routes/index.js @@ -7,16 +7,25 @@ var Session = db.Session; /* GET home page. */ router.get('/', async function(req, res, next) { console.log(req.cookies.sessionid); - sessionId = req.cookies.sessionid; - var session = await Session.findAll({ - include: User - }); - - if(session) { - console.log(session); + var sessionId = req.cookies.sessionid; + var session; + var user; + if(sessionId != undefined) { + session = await Session.findOne({ + include: User, + where: { + sessionid: sessionId + } + }); + if(session) { + user = session.User; + res.render('index', { auth: user }); + } else { + res.redirect('/login'); + } + } else { + res.redirect('/login'); } - - res.render('index'); }); module.exports = router; diff --git a/views/index.ejs b/views/index.ejs index adfecaf..428fa16 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -34,8 +34,8 @@
John Doe
-
John Doe
-
john.doe@uplink.si
+
<%= auth.name %>
+
<%= auth.email %>
@@ -106,11 +106,11 @@
-

John Doe

-

john.doe@uplink.si

+

<%= auth.name %>

+

<%= auth.name %>

-

Joined Dec 28, 2021

+

Joined <%= auth.createdAt %>

5 Posts
3 Following