Skip to content

Commit

Permalink
Merge pull request #22 from Floskinner/main
Browse files Browse the repository at this point in the history
Cleanup and Fix login/logout
  • Loading branch information
Floskinner authored Mar 14, 2022
2 parents c96107b + 9cd0fc7 commit 875b448
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 12 deletions.
19 changes: 19 additions & 0 deletions controllers/usersController.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const bcrypt = require('bcryptjs');
const jwt = require('jsonwebtoken');
const User = require('../database/Models/User/User');
const UserPlatform = require('../database/Models/UserPlatform/UserPlatform');
const Token = require('../database/Models/JWT/Token');

module.exports = {
/**
Expand All @@ -30,6 +31,24 @@ module.exports = {
let platforms = app.platformRepo.selectAll();
res.render('sign-up', { platforms: platforms, title: "Registrieren" });
},

/**
* POST-Request logout current user
* @param {Request} req The req object represents the HTTP request and has properties for the request query string, parameters, body, HTTP headers, and so on
* @param {Response} res The res object represents the HTTP response that an Express app sends when it gets an HTTP request.
* @param {*} next Control to the next handler
* @returns Redirect Redirect to /index.html
*/
logout: function (req, res, next) {
const user_token = req.cookies['jwt'];
const exp = req.userData.exp;
const token = new Token(user_token, exp);

app.tokenRepo.insert(token);

return res.redirect(302, '/');
},

/**
* POST-Request create a new user
* @param {Request} req The req object represents the HTTP request and has properties for the request query string, parameters, body, HTTP headers, and so on
Expand Down
1 change: 0 additions & 1 deletion database/Models/UserPlatform/UserPlatformRepository.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const UserPlatform = require('./UserPlatform.js');
const User = require('./UserPlatform.js');

/**
* DB Connection to the userPlatformMapping Table
Expand Down
6 changes: 6 additions & 0 deletions handlers/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,15 @@ let isLoggedIn = (req, res, next) => {
const invalid = app.tokenRepo.selectToken(new Token(token, decoded.exp));

req.userData = decoded;

if (sign_in_or_sign_up && invalid === undefined) {
return res.redirect('/gaming');
}

if (invalid && !sign_in_or_sign_up) {
return res.redirect('/users/sign-in');
}

next();
} catch (err) {
if (sign_in_or_sign_up) {
Expand Down
Binary file removed public/images/facebook.png
Binary file not shown.
Binary file removed public/images/icons8-facebook-neu-48.png
Binary file not shown.
Binary file removed public/images/icons8-fingerabdruck-50.png
Binary file not shown.
Binary file removed public/images/icons8-pfeil -lang,-rechts-32.png
Binary file not shown.
Binary file removed public/images/icons8-plus-50.png
Binary file not shown.
Binary file removed public/images/icons8-sign-up-64.png
Binary file not shown.
Binary file removed public/images/isolated-phone-in-grey-background.jpg
Binary file not shown.
Binary file removed public/images/old/UNeverGameAloneLogo-old.png
Binary file not shown.
Binary file removed public/images/old/UNeverGameAloneLogo-older.png
Binary file not shown.
Binary file removed public/images/old/background.jpg
Binary file not shown.
12 changes: 1 addition & 11 deletions routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,12 @@
let express = require('express');
let router = express.Router();
let userController = require("../controllers/usersController")
const app = require('../app')
const userValidater = require('../handlers/middleware.js');
const Token = require('../database/Models/JWT/Token');

/**
* GET of /users/logout
*/
router.get("/logout", userValidater.isLoggedIn, (req, res, next) => {
const user_token = req.cookies['jwt'];
const exp = req.userData.exp;
const token = new Token(user_token, exp);

app.tokenRepo.insert(token);

return res.redirect(302, '/');
})
router.get("/logout", userValidater.isLoggedIn, userController.logout)

/**
* GET of /users/sign-up
Expand Down

0 comments on commit 875b448

Please sign in to comment.