-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an admin status and post status
- Loading branch information
1 parent
43818c7
commit 13b7322
Showing
11 changed files
with
101 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const User = require('../models/users'); | ||
|
||
router.get('/', (req, res, next) => { | ||
res.render('admin', { title: 'Members Only | Admin Page' }) | ||
}) | ||
|
||
router.post('/', async (req, res, next) => { | ||
const admin = process.env.ADMINCODE | ||
|
||
if (req.body.admincode == admin) { | ||
await User.findByIdAndUpdate( | ||
req.user._id, | ||
{ admin: true }, | ||
{ new: true } | ||
) | ||
res.render('admin', { title: 'Members Only | Admin Page', success: 'You are now an admin.' }) | ||
} else { | ||
res.render('admin', { title: 'Members Only | Admin Page', success: '' }) | ||
} | ||
}) | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require('dotenv').config(); | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const User = require('../models/users') | ||
|
||
router.get('/', (req, res, next) => { | ||
res.render('secretpage', { title: 'Members Page | Secret Page', message: '' }) | ||
}) | ||
|
||
router.post('/', async (req, res, next) => { | ||
const secret = process.env.SECRET | ||
// const getUser = req.user | ||
if (req.body.secretcode == secret) { | ||
await User.findByIdAndUpdate( | ||
req.user._id, | ||
{ can_post: true }, | ||
{ new: true } | ||
) | ||
res.render('secretpage', { title: 'Members Page | Secret Page', state: true, message: 'Congrats! You can post now!' }) | ||
} else { | ||
res.render('secretpage', { title: 'Members Page | Secret Page', state: false, message: "Sorry that's not the secret code!" }) | ||
} | ||
}) | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
extends layout | ||
|
||
block content | ||
h1 #{title} | ||
h3 #{success} | ||
|
||
a(href="/") Home | ||
|
||
form(class="signup-form" method="POST") | ||
label(for="admincode") | ||
input(type="text" name="admincode") | ||
button Send |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters