Commit 4ab57d10 authored by Ibadullina Inabat's avatar Ibadullina Inabat

Merge branch 'task-26-fix/password_recovery' into 'development'

Task 26 fix/password recovery

See merge request !94
parents f43aba8e aeb834b4
......@@ -14,6 +14,7 @@ const dataSource = myDataSource;
/**Make requiest to init recovery process */
router.post ('/', async (req:Request, res:Response):Promise<void |Response>=>{
const {email} = req.body
console.log("emeil", email)
const user = await dataSource
.getRepository(User)
.findOne({
......@@ -21,13 +22,15 @@ router.post ('/', async (req:Request, res:Response):Promise<void |Response>=>{
email:email
}
})
console.log('user ', user)
if (!user) return res.status(404).send({message:'user not found'})
const token = nanoid();
try{
const passwordRecovery = new PasswordRecovery()
passwordRecovery.user= user;
passwordRecovery.user= user;
passwordRecovery.token=token;
await passwordRecovery.save()
console.log('passwordRecover ' , passwordRecovery)
const url = `${FRONTEND_URL}/reset-password/${token}`;
await transporter.sendMail({
from:"planner45@yandex.com",
......@@ -38,7 +41,7 @@ router.post ('/', async (req:Request, res:Response):Promise<void |Response>=>{
html:`Вы отправили запрос на восстановление пароля,
перейдите по ссылке плз: <br><a> href="${url}">${url}</a>`});
return res.send({message:'Email successffuly send'})
} catch (e){
} catch (e){
console.log(e)
res.status(502).send({message:'mail got stuck in ', e })
}
......@@ -69,12 +72,12 @@ router.get('/', async(req: Request, res: Response):Promise<Response|void>=>{
/**change password */
router.patch('/:id/change-password', async (req: Request, res: Response):Promise<Response|void>=>{
const user = await dataSource
const user = await dataSource
.getRepository(User)
.findOneBy({id:req.params.id})
if(!user) return res.status(404).send({Message:'user not found'})
const salt = await bcrypt.genSalt(SALT_WORK_FACTOR);
let newPassword:string = await bcrypt.hash(req.body.password, salt);
const newPassword:string = await bcrypt.hash(req.body.password, salt);
user.password = newPassword
try{
await user.save()
......
......@@ -119,6 +119,7 @@ const App = () => {
<Route path={"/sign-in"} element={<Login />} />
<Route path={"/forgottenpassword"} element={<ForgottenPassword />} />
<Route path={"/reset-password"} element={<div>Reset</div>} />
<Route path='*' element={<h1>404</h1>} />
</Route>
</Routes>
......
......@@ -2,33 +2,41 @@ import { Card, CardActions, CardContent, Grid, IconButton } from "@mui/material"
import { Link } from "react-router-dom";
import ArrowForwardIcon from "@mui/icons-material/ArrowForward";
import { useDispatch, useSelector } from "react-redux";
import DeleteIcon from "@mui/icons-material/Delete";
const ProjectItem = ({ title, tasks, id }) => {
const user = useSelector(state => state.users.user);
const dispatch = useDispatch();
console.log(user)
return <>
<Grid item xs={12} sm={12} md={6} lg={4}>
<Card>
<CardContent >
<strong>
<br></br>
Название проекта: {title}
</strong>
<strong>
<br></br>
{/* Задачи: {tasks} */}
</strong>
</CardContent>
<CardActions>
return <>
<Grid item xs={12} sm={12} md={6} lg={4}>
<Card>
<CardContent >
<strong>
<br></br>
Название проекта: {title}
</strong>
<strong>
<br></br>
{/* Задачи: {tasks} */}
</strong>
</CardContent>
<CardActions>
<IconButton component={Link} to={"/projects/" + id}>
<ArrowForwardIcon />
</IconButton>
</CardActions>
</Card>
</Grid>
<ArrowForwardIcon />
</IconButton>
<IconButton
onClick={(id) => {
// deleteHandle(userId);
}}
>
{(title !== "Личные дела") ?
<DeleteIcon /> : null}
</IconButton>
</CardActions>
</Card>
</Grid>
</>
};
......
......@@ -2,7 +2,7 @@ import { useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { useNavigate } from "react-router-dom";
import Loader from "../../components/UI/Loader/Loader";
import { loginUser } from "../../store/actions/usersActions";
import { forgottenPassword, loginUser } from "../../store/actions/usersActions";
import PersonIcon from '@mui/icons-material/Person';
import styled from "@emotion/styled";
import { Alert, Avatar, Container, Typography } from "@mui/material";
......@@ -25,7 +25,7 @@ const StyledTitle = styled(Typography)`
const ForgottenPassword = () => {
const [state, setState] = useState({
email: '',
redirectUrl: 'http://localhost:3000/passwordreset'
// redirectUrl: 'http://localhost:3000/passwordreset'
});
......@@ -46,7 +46,7 @@ const ForgottenPassword = () => {
const submitHandler = async (e) => {
e.preventDefault();
await dispatch(loginUser(state, navigate));
await dispatch(forgottenPassword(state, navigate));
};
......
......@@ -65,7 +65,7 @@ const Register = () => {
formData.append(key, state[key]);
console.log("key " + key + "state " + state[key])
})
if (state["password"] === state["confirmPassword"]) {
if (state.password && state.password === state.confirmPassword) {
await dispatch(registerUser(formData, navigate));
} else {
alert("Пароли не совпадают")
......
......@@ -85,14 +85,15 @@ export const forgottenPassword = (userData, navigate) => {
return async (dispatch) => {
try {
console.log( 'forgottenPassword userData ',userData)
const response = await axios.post("users/requestPasswordReset", userData);
const response = await axios.post("/password-recovery", userData);
// if (userData.email === response.data.email) {
// }
dispatch(loginUserSuccess(response.data));
console.log('response.data ', response.data)
// dispatch(loginUserSuccess(response.data));
navigate("/")
} catch (e) {
dispatch(loginUserFailure(e?.response?.data?.err))
console.log("user not found")
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment