diff --git a/backend/controllers/userController.js b/backend/controllers/userController.js index 45bbd0b..c1db779 100644 --- a/backend/controllers/userController.js +++ b/backend/controllers/userController.js @@ -3,6 +3,7 @@ const catchAsync=require('../utils/catchAsync'); const AppError = require('../utils/AppError'); const Chat=require('../models/chatModel'); const multer=require('multer'); +const bcrypt=require('bcryptjs'); const multerstorage=multer.diskStorage({ destination:(req,file,cb)=>{ @@ -87,6 +88,23 @@ exports.UploadPhoto=catchAsync(async(req,res,next)=>{ }) }) +exports.updatePassword=catchAsync(async(req,res,next)=>{ + if(!req.body.password) + next(new AppError('Password field is not allowed to be empty',400)) + + try{ + const encryptPassword=await bcrypt.hash(req.body.password,12) + const updatedUser = await User.findByIdAndUpdate({_id:req.user.id},{password:encryptPassword}); + }catch(err){ + res.json({err}) + } + + res.status(200).json({ + status:'success', + message:"Password Updated" + }) +}) + // exports.AvailableUsersToCreateGroup=catchAsync(async(req,res)=>{ diff --git a/backend/routes/userRouter.js b/backend/routes/userRouter.js index ae9debe..c42c375 100644 --- a/backend/routes/userRouter.js +++ b/backend/routes/userRouter.js @@ -12,6 +12,7 @@ router.post('/login',authController.login); router.post('/ispresent',authController.isUserPresent) router.post('/protect',authController.protect,authController.send); router.post('/uploadPhoto',authController.protect,userController.uploadUserPhoto,userController.UploadPhoto) +router.post('/updatepassword',authController.protect,userController.updatePassword) module.exports=router; \ No newline at end of file diff --git a/frontend/src/pages/Settings.js b/frontend/src/pages/Settings.js index 8912912..11f1b34 100644 --- a/frontend/src/pages/Settings.js +++ b/frontend/src/pages/Settings.js @@ -2,23 +2,67 @@ import React from "react"; import Profile from "../components/SettingsComponents/Profile"; import InputName from "../components/SettingsComponents/InputName"; import InputEmail from "../components/SettingsComponents/InputEmail"; -import { useState,useEffect} from "react"; -import {setUser} from '../services/Actions/User/actions' +import { TextField } from "@mui/material"; +import { useState, useEffect } from "react"; +import { setUser } from '../services/Actions/User/actions' import { useDispatch } from 'react-redux'; import { ToastContainer, toast } from "react-toastify"; import InfoIcon from '@mui/icons-material/Info'; +import CheckCircleIcon from '@mui/icons-material/CheckCircle'; +import CancelIcon from '@mui/icons-material/Cancel'; + +const PasswordRequirements = ({ password }) => { + const specialCharacterRegex = /[!@#$%^&*(),.?":{}|<>]/; + const numberRegex = /[0-9]/; + const uppercaseRegex = /[A-Z]/; + + const boxStyle = { + border: '1px solid #ccc', + padding: '8px', + borderRadius: '4px', + marginTop: '8px', + backgroundColor: '#f9f9f9', + width: "40%" + }; + + return ( +