Login sistem deluje.

This commit is contained in:
Matjaz
2022-02-11 20:02:52 +01:00
parent 40da8e140d
commit 3ad790ff89
4 changed files with 25 additions and 16 deletions

Binary file not shown.

View File

@ -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) {

View File

@ -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;

View File

@ -34,8 +34,8 @@
<div class="flex items-center">
<img src="/images/avatar_48.png" alt="John Doe" class="rounded-md mr-2">
<div>
<div class="w-full font-bold text-sm">John Doe</div>
<div class="w-full text-sm text-gray-400">john.doe@uplink.si</div>
<div class="w-full font-bold text-sm"><%= auth.name %></div>
<div class="w-full text-sm text-gray-400"><%= auth.email %></div>
</div>
</div>
<div>
@ -106,11 +106,11 @@
<div class="p-4">
<div>
<h4 class="font-bold">John Doe</h4>
<p class="text-sm text-gray-400">john.doe@uplink.si</p>
<h4 class="font-bold"><%= auth.name %></h4>
<p class="text-sm text-gray-400"><%= auth.name %></p>
</div>
<div class="text-sm text-gray-400 mt-3">
<p>Joined Dec 28, 2021</p>
<p>Joined <%= auth.createdAt %></p>
<div class="flex">
<div class="pr-5"><span class="text-white">5</span> Posts</div>
<div class="pr-5"><span class="text-white">3</span> Following</div>