Skip to content

Commit

Permalink
protect rating from unverified users
Browse files Browse the repository at this point in the history
  • Loading branch information
baijanathTharu committed Jan 13, 2021
1 parent 3afc266 commit 087ed58
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion server/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
PORT=8080
DB_URL=mongodb://localhost:27017/movie-rating
DB_URL_LOCAL=mongodb://localhost:27017/movie-rating
DB_URL_PROD=
SECRET_KEY=12345
CLOUDINARY_CLOUD_NAME=
CLOUDINARY_API_KEY=
Expand Down
15 changes: 15 additions & 0 deletions server/src/middlewares/checkActive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const UserModel = require('../modules/users/user.model');

module.exports = function (req, res, next) {
UserModel.findById(req.userId, function (e, user) {
if (e) return next(e);
console.log('user: ', user);
if (user.status === 'active') {
return next();
}
next({
msg: 'Please verify your email to start rating movie!',
status: 403,
});
});
};
2 changes: 1 addition & 1 deletion server/src/modules/users/secret/secret.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const SecretModel = new mongoose.Schema({
createdAt: {
type: Date,
default: Date.now(),
expires: '120s',
expires: '600s',
},
});

Expand Down
3 changes: 2 additions & 1 deletion server/src/route/api.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ const authenticate = require('../middlewares/authenticate');
const authorize = require('../middlewares/authorize');
const ratingRoute = require('../modules/movies/rating.route');
const searchMovies = require('../modules/movies/movie.search');
const checkActive = require('../middlewares/checkActive');

router.use('/movies', authenticate, authorize, movieRoute);
router.use('/rate', authenticate, ratingRoute);
router.use('/rate', authenticate, checkActive, ratingRoute);
router.use('/users', userRoute);
router.use('/auth', authRoute);
router.use('/search/movies', searchMovies);
Expand Down

0 comments on commit 087ed58

Please sign in to comment.