Skip to content

Commit

Permalink
completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Smnthjm08 committed Apr 2, 2024
1 parent 4603300 commit 7e76abf
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 63 deletions.
40 changes: 20 additions & 20 deletions server/routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,25 @@ router.get('/dashboard', authMiddleware, async (req, res) => {
});

//POST - admin register
router.post('/register', async (req, res) => {
try {
const {username, password} = req.body;
const hashedPassword = await bcrypt.hash(password, 10);

try{
const user = await User.create({ username, password: hashedPassword });
res.status(201).json({ message: "User Created!", user});
} catch{
if(error.code === 11000){
res.status(409).json({ message: "User already in use"});
}
res.status(500).json({ message: "Internal Server Error"});
}
}
catch (error) {
console.log(error);
}
});
// router.post('/register', async (req, res) => {
// try {
// const {username, password} = req.body;
// const hashedPassword = await bcrypt.hash(password, 10);

// try{
// const user = await User.create({ username, password: hashedPassword });
// res.status(201).json({ message: "User Created!", user});
// } catch{
// if(error.code === 11000){
// res.status(409).json({ message: "User already in use"});
// }
// res.status(500).json({ message: "Internal Server Error"});
// }
// }
// catch (error) {
// console.log(error);
// }
// });

//admin - create new post
router.get('/add-post', authMiddleware, async (req, res) => {
Expand All @@ -130,7 +130,7 @@ router.get('/add-post', authMiddleware, async (req, res) => {
// create Post
router.post('/add-post', authMiddleware, async (req, res) => {
try {
console.log(req.body);
// console.log(req.body);

try {
const newPost = new Post({
Expand Down
5 changes: 5 additions & 0 deletions server/routes/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,10 @@ router.get('/about', (req, res) => {
});
});

router.get('/contact', (req, res) => {
res.render('contact', {
currentRoute: '/contact'
});
});

module.exports = router;
22 changes: 21 additions & 1 deletion views/about.ejs
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
<h1>About</h1>
<h1>About</h1>
<br/>
<h4>Hello, this is Sumanth JM</h4>
<h4>This is my first web application using NodeJs, ExpressJs, and MongoDB. Do support.</h4>
<h4>This web application requires Node.js and a MongoDB database (with a free cluster available). You'll also need to create a `.env` file to securely store your credentials, including the MongoDB URI and a JWT secret for authentication.

Once you have Node.js installed and your MongoDB cluster set up, create a `.env` file in the root directory of the project and add your MongoDB URI and a JWT secret according to the provided example format.

To install the necessary dependencies for the project, run `npm install`. After installing dependencies, you can start the server by running `npm run dev`.

This web application provides a platform for building a blog. It includes features for user authentication and utilizes JSON Web Tokens (JWT) for secure authentication. The MongoDB database serves as the backend storage for the blog content, and the Node.js server handles the application logic and communication with the database.

By following the installation steps and starting the server, you can run the web application locally, allowing you to create and manage a blog with user authentication and secure database storage.</h4>


<a href="https://twitter.com/jm_sumanth"><b>X</b></a>

<br/>
<br/>

<a href="https://github.com/Smnthjm08"><b>GitHub</b></a>
9 changes: 8 additions & 1 deletion views/contact.ejs
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
<h1>Contact</h1>
<h1>Contact</h1>



<a href="https://twitter.com/jm_sumanth"><b>X</b></a>
<br/>

<a href="https://github.com/Smnthjm08"><b>GitHub</b></a></h4>
2 changes: 1 addition & 1 deletion views/layouts/admin.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= locals.title %></title>
<meta name="description" content="<%= locals.description %>">
<link rel="stylesheet" href="/public/css/style.css">
<link rel="stylesheet" href="/css/style.css">
<script type="text/javascript" defer src="/js/script.js"></script>
</head>
<body>
Expand Down
47 changes: 24 additions & 23 deletions views/partials/header.ejs
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
<header class="header">
<a href="/" class="header__logo">Blog🖌️</a>

<a href="/" class="header__logo">NodeJs</a>
<nav class="header__nav">
<ul>
<li>
<a href="/" class="<%= isActiveRoute("/", currentRoute) %>">Home</a>
</li>
<li>
<a href="../about.ejs" class="<%= isActiveRoute("/about", currentRoute) %></a>">About</a>
</li>
<li>
<a href="../contact.ejs" class="<%= isActiveRoute("/contact", currentRoute) %></a>">Contact</a>
</li>
</ul>
<ul>
<li>
<a href="/" class="<%= isActiveRoute('/', currentRoute) %>">Home</a>
</li>
<li>
<a href="/about" class="<%= isActiveRoute('/about', currentRoute) %>">About</a>
</li>
<li>
<a href="/contact" class="<%= isActiveRoute('/contact', currentRoute) %>">Contact</a>
</li>
</ul>

</nav>

<div class="header__button">
<button class="searchBtn" aria-expanded="false">
Search

<svg width="17" height="17" viewBox="0 0 17 17" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M7.79167 13.4583C10.9213 13.4583 13.4583 10.9213 13.4583 7.79167C13.4583 4.66205 10.9213 2.125 7.79167 2.125C4.66205 2.125 2.125 4.66205 2.125 7.79167C2.125 10.9213 4.66205 13.4583 7.79167 13.4583Z" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M14.875 14.875L11.7938 11.7938" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
<button class="searchBtn" aria-expanded="false">
Search
<svg width="17" height="17" viewBox="0 0 17 17" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M7.79167 13.4583C10.9213 13.4583 13.4583 10.9213 13.4583 7.79167C13.4583 4.66205 10.9213 2.125 7.79167 2.125C4.66205 2.125 2.125 4.66205 2.125 7.79167C2.125 10.9213 4.66205 13.4583 7.79167 13.4583Z" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M14.875 14.875L11.7938 11.7938" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
</div>
</header>

</header>
37 changes: 20 additions & 17 deletions views/partials/header_admin.ejs
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<header class="header">
<a href="/" class="header__logo">Admin</a>

<a href="/" class="header__logo">Admin Panel</a>
<nav class="header__nav">
<ul>
<li>
<a href="/" class="">Home</a>
</li>
<li>
<a href="../about.ejs" class="">About</a>
</li>
<li>
<a href="../contact.ejs" class="">Contact</a>
</li>
</ul>
<ul>
<li>
<a href="/" class="">Home</a>
</li>
<li>
<a href="/about" class="">About</a>
</li>
<li>
<a href="/contact" class="">Contact</a>
</li>
</ul>

</nav>

<div class="header__button">
<a href="/logout">Logout</a>
<a href="/logout">
Logout
</a>
</div>
</header>

</header>

0 comments on commit 7e76abf

Please sign in to comment.