-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1647679
commit 572cafe
Showing
1,212 changed files
with
65,447 additions
and
27,510 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
MONGODB_URL=mongodb://localhost/project | ||
JWT_SECRET=somethingsecret |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,4 +4,5 @@ dotenv.config(); | |
|
||
export default { | ||
MONGODB_URL: process.env.MONGODB_URL, | ||
JWT_SECRET: process.env.JWT_SECRET | ||
}; |
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 |
---|---|---|
@@ -1,20 +1,46 @@ | ||
import express from 'express'; | ||
import expressAsyncHandler from 'express-async-handler'; | ||
import User from '../models/userModel'; | ||
import { generateToken } from '../utils'; | ||
|
||
const userRouter = express.Router(); | ||
|
||
userRouter.get('/createadmin', async (req, res) => { | ||
try { | ||
const user = new User({ | ||
name: 'admin', | ||
email: '[email protected]', | ||
password: '12345', | ||
isAdmin: true, | ||
userRouter.get( | ||
'/createadmin', | ||
expressAsyncHandler(async (req, res) => { | ||
try { | ||
const user = new User({ | ||
name: 'elif', | ||
email: '[email protected]', | ||
password: 'elif12345', | ||
isAdmin: true, | ||
}); | ||
const createdUser = await user.save(); | ||
res.send(createdUser); | ||
} catch (err) { | ||
res.status(500).send({ message: err.message }); | ||
} | ||
}) | ||
); | ||
userRouter.post( | ||
'/signin', | ||
expressAsyncHandler(async (req, res) => { | ||
const signinUser = await User.findOne({ | ||
email: req.body.email, | ||
password: req.body.password, | ||
}); | ||
const createdUser = await user.save(); | ||
res.send(createdUser); | ||
} catch (err) { | ||
res.status(500).send({ message: err.message }); | ||
} | ||
}); | ||
export default userRouter; | ||
if (!signinUser) { | ||
res.status(401).send({ | ||
message: 'Invalid Email or Password', | ||
}); | ||
} else { | ||
res.send({ | ||
_id: signinUser._id, | ||
name: signinUser.name, | ||
email: signinUser.email, | ||
isAdmin: signinUser.isAdmin, | ||
token: generateToken(signinUser), | ||
}); | ||
} | ||
}) | ||
); |
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,14 @@ | ||
import jwt from 'jsonwebtoken'; | ||
import config from './config'; | ||
|
||
export const generateToken = (user) => { | ||
return jwt.sign( | ||
{ | ||
_id: user._id, | ||
name: user.name, | ||
email: user.email, | ||
isAdmin: user.isAdmin, | ||
}, | ||
config.JWT_SECRET | ||
); | ||
}; |
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,18 @@ | ||
import {getUserInfo} from '../localStorage'; | ||
|
||
const Header = { | ||
render: () => { | ||
const {name} = getUserInfo(); | ||
return ` | ||
<div class="brand"> | ||
<a href="/#/">QuickOrder</a> | ||
</div> | ||
<div> | ||
${name ? `<a href="/#/profile">${name}</a>` : `<a href="/#/signin">Sign-In</a>`} | ||
<a href="/#/cart">Cart</a> | ||
</div>`; | ||
}, | ||
after_render: () => { | ||
}, | ||
}; | ||
export default Header; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.