Skip to content

Commit

Permalink
Merge pull request #64 from JumboCode/sign-in-page-forgot-pass
Browse files Browse the repository at this point in the history
Sign in page forgot pass
  • Loading branch information
myix765 authored Dec 11, 2024
2 parents 2338897 + e129b6d commit b2630e0
Show file tree
Hide file tree
Showing 10 changed files with 326 additions and 71 deletions.
25 changes: 25 additions & 0 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,28 @@ app.put('/api/users/:id/unenroll', async (req, res) => {
res.status(500).json({ message: 'Error unenrolling into class' })
}
})

//Forgot Password
app.post('/api/users/reset-password', async (req, res) => {
const { username, password } = req.body;
const user = await User.findOne({ username });
try{
if (user) {
const user = { username: username };
const updatedPassword = { password: password };
const options = { returnDocument: 'after' };
await User.findOneAndUpdate(user, updatedPassword, options);

res.status(200).send("Password updated successfully.");

} else {
console.log('Login failed: User not found');
res.status(401).send('Invalid username.');
}
} catch (err){
console.error('Error resetting password');
res.status(500).send("Server error resetting password.");
}


});
194 changes: 138 additions & 56 deletions package-lock.json

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

Loading

0 comments on commit b2630e0

Please sign in to comment.