Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/ForkClone.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Fork and Clone
# Fork and Clone

## Steps to fork the repo:
## Steps to fork the repo:

### Step 1

Expand All @@ -10,7 +10,7 @@ Go to the main GitHub page of the repo:

### Step 2

Once you are on the main GitHub page of the repo, click the Fork button at the top right of the page.
Once you are on the main GitHub page of the repo, click the Fork button at the top right of the page.

![](fork.png)

Expand Down Expand Up @@ -38,7 +38,7 @@ You will now have a forked version of the original repo that is up to date with
### Step 1

Clone this repo to your local machine using (https://github.com/gbowne1/codebooker.git)

### Step 2

Create your feature branch using git checkout -b my-feature
Expand All @@ -54,4 +54,4 @@ Push to the branch using git push origin my-feature;
### Step 5

Create a new [pull request] (SubmitPR.md)
After your Pull Request is merged, can you delete your feature branch.
After your Pull Request is merged, can you delete your feature branch.
2 changes: 1 addition & 1 deletion src/components/Register/Register.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
justify-content: center;
min-height: 100vh;
padding: 16px;
}
}
15 changes: 5 additions & 10 deletions src/pages/ForgotPassword/ForgotPassword.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,25 @@
width: 35%;
}



.MuiInputBase-input {
font-family: 'Roboto', 'Open Sans', sans-serif;
}


.checkbox-wrapper input {
margin-right: .5rem;
margin-right: 0.5rem;
}



.forgotpassword-button {
display: flex;
align-items: center;
justify-content: center;
background-color: #1976d2;
color: #fff;
padding: .5rem 1.25rem;
padding: 0.5rem 1.25rem;
border: none;
font-weight: 500;
font-size: .9rem;
border-radius: .25rem;
font-size: 0.9rem;
border-radius: 0.25rem;
cursor: pointer;
width: 35%;
}
Expand All @@ -56,4 +51,4 @@
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
}
}
29 changes: 17 additions & 12 deletions src/pages/ForgotPassword/ForgotPassword.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ const ForgotPassword = () => {
console.error(error);
}


setLoading(false);
}



};

return (
<div className='forgotpassword-wrapper'>
Expand All @@ -39,9 +35,9 @@ const ForgotPassword = () => {
Update your password
</Typography>
<div>
<Typography component='p' variant='p' mt={2}>
Enter your email address and click SEND EMAIL.
</Typography>
<Typography component='p' variant='p' mt={2}>
Enter your email address and click SEND EMAIL.
</Typography>
</div>
</div>
<div className='forgotpassword-wrapper-input'>
Expand All @@ -52,13 +48,22 @@ const ForgotPassword = () => {
/>
</div>

<button onClick={handleForgotPassword} className='forgotpassword-button'>
{loading && <CircularProgress size={15} sx={{mr:'10px'}} color="inherit" />}
SEND EMAIL
<button
onClick={handleForgotPassword}
className='forgotpassword-button'
>
{loading && (
<CircularProgress
size={15}
sx={{ mr: '10px' }}
color='inherit'
/>
)}
SEND EMAIL
</button>
<div className='forgotpassword-wrapper-cancel'>
<Typography variant='body2'>
<Link to='/login'>Cancel</Link>
<Link to='/login'>Cancel</Link>
</Typography>
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion src/pages/Home/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ function Home() {
const notify = (username) => toast.success('Welcome! ' + username);

useEffect(() => {
if (location.state.loggin && localStorage.getItem('user')) {
if (
location.state &&
location.state.loggin &&
localStorage.getItem('user')
) {
notify(JSON.parse(localStorage.getItem('user')).username);
}
}, []);
Expand Down
13 changes: 4 additions & 9 deletions src/pages/Login/Login.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,22 @@
width: 35%;
}



.MuiInputBase-input {
font-family: 'Roboto', 'Open Sans', sans-serif;
}


.checkbox-wrapper input {
margin-right: .5rem;
margin-right: 0.5rem;
}



.login-button {
background-color: #1976d2;
color: #fff;
padding: .5rem 1.25rem;
padding: 0.5rem 1.25rem;
border: none;
font-weight: 700;
font-size: 1.25rem;
border-radius: .25rem;
border-radius: 0.25rem;
cursor: pointer;
width: 35%;
}
Expand All @@ -53,4 +48,4 @@
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
}
}
8 changes: 7 additions & 1 deletion src/pages/ResetPassword/ResetPassword.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,13 @@ const ResetPassword = () => {
variant='contained'
sx={{ mt: 3, mb: 2 }}
>
{loading && <CircularProgress size={15} sx={{mr:'10px'}} color="inherit" />}
{loading && (
<CircularProgress
size={15}
sx={{ mr: '10px' }}
color='inherit'
/>
)}
Reset password
</Button>
</Box>
Expand Down
21 changes: 9 additions & 12 deletions src/server/controller/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ module.exports.forgotPassword = async (req, res) => {
}

// delete token if it exist in db
const existingToken = await Token.findOne({userId:existinguser._id});
const existingToken = await Token.findOne({ userId: existinguser._id });

if(existingToken){
if (existingToken) {
await existingToken.deleteOne();
console.log("found");
console.log('found');
}

// Create new reset token
Expand All @@ -137,21 +137,19 @@ module.exports.forgotPassword = async (req, res) => {
{ expiresIn: '30m' } //30min
);


// get token expiration time
const expiresIn = new Date(Date.now() + 30 * 60 * 1000);

// Save token to db
const newToken = new Token({
userId:existinguser._id,
token:resetToken,
created_on:Date.now(),
const newToken = new Token({
userId: existinguser._id,
token: resetToken,
created_on: Date.now(),
expires_in: expiresIn,
});

await newToken.save();


// URL link
const resetLink = `http://localhost:3000/reset-password/${resetToken}`;

Expand Down Expand Up @@ -202,18 +200,17 @@ module.exports.resetPassword = async (req, res) => {
//Find token in DB
const userToken = await Token.findOne({
token: token,
expires_in:{$gt:Date.now()}
expires_in: { $gt: Date.now() },
});


if (!userToken) {
return res.status(401).json({
message: 'Token expired or invalid',
});
}

// Find user with that specific token
const userWithToken = await User.findOne({_id:userToken.userId});
const userWithToken = await User.findOne({ _id: userToken.userId });

// hash new password
const hashPassword = await bcrypt.hash(password, 12);
Expand Down
28 changes: 14 additions & 14 deletions src/server/model/tokenModel.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
const mongoose = require('mongoose');

const tokenSchema = new mongoose.Schema({
userId:{
userId: {
type: mongoose.Schema.Types.ObjectId,
required:true,
ref:"User"
required: true,
ref: 'User',
},
token:{
type:String,
required:true,
token: {
type: String,
required: true,
},

created_on:{
type:Date,
required: true
created_on: {
type: Date,
required: true,
},
expires_in:{
type:Date,
expires_in: {
type: Date,
required: true,
index: { expires: '1s' }
}
index: { expires: '1s' },
},
});

const Token = mongoose.model('Token', tokenSchema);

module.exports = Token;
module.exports = Token;
4 changes: 0 additions & 4 deletions src/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/server/routes/userRoutes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
const express = require('express');
const router = express.Router();
const { login, signup, logout, forgotPassword, resetPassword } = require('../controller/userController');
const {
login,
signup,
logout,
forgotPassword,
resetPassword,
} = require('../controller/userController');

router.post('/login', login);
router.post('/logout', logout);
Expand Down