Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
planner-team-one
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
21
Issues
21
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Евгений Положенцев
planner-team-one
Commits
4ab57d10
Commit
4ab57d10
authored
Dec 21, 2022
by
Ibadullina Inabat
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'task-26-fix/password_recovery' into 'development'
Task 26 fix/password recovery See merge request
!94
parents
f43aba8e
aeb834b4
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
31 deletions
+44
-31
passwordRecovery.ts
planner-api/src/routers/passwordRecovery.ts
+7
-4
App.js
planner-front/src/App.js
+1
-0
ProjectItem.js
...c/components/ProjectComponents/ProjectItem/ProjectItem.js
+28
-20
ForgottenPassword.js
...ont/src/containers/ForgottenPassword/ForgottenPassword.js
+3
-3
Register.js
planner-front/src/containers/Register/Register.js
+1
-1
usersActions.js
planner-front/src/store/actions/usersActions.js
+4
-3
No files found.
planner-api/src/routers/passwordRecovery.ts
View file @
4ab57d10
...
@@ -14,6 +14,7 @@ const dataSource = myDataSource;
...
@@ -14,6 +14,7 @@ const dataSource = myDataSource;
/**Make requiest to init recovery process */
/**Make requiest to init recovery process */
router
.
post
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
void
|
Response
>=>
{
router
.
post
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
void
|
Response
>=>
{
const
{
email
}
=
req
.
body
const
{
email
}
=
req
.
body
console
.
log
(
"emeil"
,
email
)
const
user
=
await
dataSource
const
user
=
await
dataSource
.
getRepository
(
User
)
.
getRepository
(
User
)
.
findOne
({
.
findOne
({
...
@@ -21,13 +22,15 @@ router.post ('/', async (req:Request, res:Response):Promise<void |Response>=>{
...
@@ -21,13 +22,15 @@ router.post ('/', async (req:Request, res:Response):Promise<void |Response>=>{
email
:
email
email
:
email
}
}
})
})
console
.
log
(
'user '
,
user
)
if
(
!
user
)
return
res
.
status
(
404
).
send
({
message
:
'user not found'
})
if
(
!
user
)
return
res
.
status
(
404
).
send
({
message
:
'user not found'
})
const
token
=
nanoid
();
const
token
=
nanoid
();
try
{
try
{
const
passwordRecovery
=
new
PasswordRecovery
()
const
passwordRecovery
=
new
PasswordRecovery
()
passwordRecovery
.
user
=
user
;
passwordRecovery
.
user
=
user
;
passwordRecovery
.
token
=
token
;
passwordRecovery
.
token
=
token
;
await
passwordRecovery
.
save
()
await
passwordRecovery
.
save
()
console
.
log
(
'passwordRecover '
,
passwordRecovery
)
const
url
=
`
${
FRONTEND_URL
}
/reset-password/
${
token
}
`
;
const
url
=
`
${
FRONTEND_URL
}
/reset-password/
${
token
}
`
;
await
transporter
.
sendMail
({
await
transporter
.
sendMail
({
from
:
"planner45@yandex.com"
,
from
:
"planner45@yandex.com"
,
...
@@ -38,7 +41,7 @@ router.post ('/', async (req:Request, res:Response):Promise<void |Response>=>{
...
@@ -38,7 +41,7 @@ router.post ('/', async (req:Request, res:Response):Promise<void |Response>=>{
html
:
`Вы отправили запрос на восстановление пароля,
html
:
`Вы отправили запрос на восстановление пароля,
перейдите по ссылке плз: <br><a> href="
${
url
}
">
${
url
}
</a>`
});
перейдите по ссылке плз: <br><a> href="
${
url
}
">
${
url
}
</a>`
});
return
res
.
send
({
message
:
'Email successffuly send'
})
return
res
.
send
({
message
:
'Email successffuly send'
})
}
catch
(
e
){
}
catch
(
e
){
console
.
log
(
e
)
console
.
log
(
e
)
res
.
status
(
502
).
send
({
message
:
'mail got stuck in '
,
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>=>{
...
@@ -69,12 +72,12 @@ router.get('/', async(req: Request, res: Response):Promise<Response|void>=>{
/**change password */
/**change password */
router
.
patch
(
'/:id/change-password'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
|
void
>=>
{
router
.
patch
(
'/:id/change-password'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
|
void
>=>
{
const
user
=
await
dataSource
const
user
=
await
dataSource
.
getRepository
(
User
)
.
getRepository
(
User
)
.
findOneBy
({
id
:
req
.
params
.
id
})
.
findOneBy
({
id
:
req
.
params
.
id
})
if
(
!
user
)
return
res
.
status
(
404
).
send
({
Message
:
'user not found'
})
if
(
!
user
)
return
res
.
status
(
404
).
send
({
Message
:
'user not found'
})
const
salt
=
await
bcrypt
.
genSalt
(
SALT_WORK_FACTOR
);
const
salt
=
await
bcrypt
.
genSalt
(
SALT_WORK_FACTOR
);
le
t
newPassword
:
string
=
await
bcrypt
.
hash
(
req
.
body
.
password
,
salt
);
cons
t
newPassword
:
string
=
await
bcrypt
.
hash
(
req
.
body
.
password
,
salt
);
user
.
password
=
newPassword
user
.
password
=
newPassword
try
{
try
{
await
user
.
save
()
await
user
.
save
()
...
...
planner-front/src/App.js
View file @
4ab57d10
...
@@ -119,6 +119,7 @@ const App = () => {
...
@@ -119,6 +119,7 @@ const App = () => {
<
Route
path
=
{
"/sign-in"
}
element
=
{
<
Login
/>
}
/
>
<
Route
path
=
{
"/sign-in"
}
element
=
{
<
Login
/>
}
/
>
<
Route
path
=
{
"/forgottenpassword"
}
element
=
{
<
ForgottenPassword
/>
}
/
>
<
Route
path
=
{
"/forgottenpassword"
}
element
=
{
<
ForgottenPassword
/>
}
/
>
<
Route
path
=
{
"/reset-password"
}
element
=
{
<
div
>
Reset
<
/div>} /
>
<
Route
path
=
'*'
element
=
{
<
h1
>
404
<
/h1>} /
>
<
Route
path
=
'*'
element
=
{
<
h1
>
404
<
/h1>} /
>
<
/Route
>
<
/Route
>
<
/Routes
>
<
/Routes
>
...
...
planner-front/src/components/ProjectComponents/ProjectItem/ProjectItem.js
View file @
4ab57d10
...
@@ -2,33 +2,41 @@ import { Card, CardActions, CardContent, Grid, IconButton } from "@mui/material"
...
@@ -2,33 +2,41 @@ import { Card, CardActions, CardContent, Grid, IconButton } from "@mui/material"
import
{
Link
}
from
"react-router-dom"
;
import
{
Link
}
from
"react-router-dom"
;
import
ArrowForwardIcon
from
"@mui/icons-material/ArrowForward"
;
import
ArrowForwardIcon
from
"@mui/icons-material/ArrowForward"
;
import
{
useDispatch
,
useSelector
}
from
"react-redux"
;
import
{
useDispatch
,
useSelector
}
from
"react-redux"
;
import
DeleteIcon
from
"@mui/icons-material/Delete"
;
const
ProjectItem
=
({
title
,
tasks
,
id
})
=>
{
const
ProjectItem
=
({
title
,
tasks
,
id
})
=>
{
const
user
=
useSelector
(
state
=>
state
.
users
.
user
);
const
user
=
useSelector
(
state
=>
state
.
users
.
user
);
const
dispatch
=
useDispatch
();
const
dispatch
=
useDispatch
();
console
.
log
(
user
)
console
.
log
(
user
)
return
<>
return
<>
<
Grid
item
xs
=
{
12
}
sm
=
{
12
}
md
=
{
6
}
lg
=
{
4
}
>
<
Grid
item
xs
=
{
12
}
sm
=
{
12
}
md
=
{
6
}
lg
=
{
4
}
>
<
Card
>
<
Card
>
<
CardContent
>
<
CardContent
>
<
strong
>
<
strong
>
<
br
><
/br
>
<
br
><
/br
>
Название
проекта
:
{
title
}
Название
проекта
:
{
title
}
<
/strong
>
<
/strong
>
<
strong
>
<
strong
>
<
br
><
/br
>
<
br
><
/br
>
{
/* Задачи: {tasks} */
}
{
/* Задачи: {tasks} */
}
<
/strong
>
<
/strong
>
<
/CardContent
>
<
/CardContent
>
<
CardActions
>
<
CardActions
>
<
IconButton
component
=
{
Link
}
to
=
{
"/projects/"
+
id
}
>
<
IconButton
component
=
{
Link
}
to
=
{
"/projects/"
+
id
}
>
<
ArrowForwardIcon
/>
<
ArrowForwardIcon
/>
<
/IconButton>
<
/IconButton
>
<
/CardActions
>
<
IconButton
<
/Card
>
onClick
=
{(
id
)
=>
{
<
/Grid>
// deleteHandle(userId);
}}
>
{(
title
!==
"Личные дела"
)
?
<
DeleteIcon
/>
:
null
}
<
/IconButton
>
<
/CardActions
>
<
/Card
>
<
/Grid
>
<
/
>
<
/
>
};
};
...
...
planner-front/src/containers/ForgottenPassword/ForgottenPassword.js
View file @
4ab57d10
...
@@ -2,7 +2,7 @@ import { useState } from "react";
...
@@ -2,7 +2,7 @@ import { useState } from "react";
import
{
useDispatch
,
useSelector
}
from
"react-redux"
;
import
{
useDispatch
,
useSelector
}
from
"react-redux"
;
import
{
useNavigate
}
from
"react-router-dom"
;
import
{
useNavigate
}
from
"react-router-dom"
;
import
Loader
from
"../../components/UI/Loader/Loader"
;
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
PersonIcon
from
'@mui/icons-material/Person'
;
import
styled
from
"@emotion/styled"
;
import
styled
from
"@emotion/styled"
;
import
{
Alert
,
Avatar
,
Container
,
Typography
}
from
"@mui/material"
;
import
{
Alert
,
Avatar
,
Container
,
Typography
}
from
"@mui/material"
;
...
@@ -25,7 +25,7 @@ const StyledTitle = styled(Typography)`
...
@@ -25,7 +25,7 @@ const StyledTitle = styled(Typography)`
const
ForgottenPassword
=
()
=>
{
const
ForgottenPassword
=
()
=>
{
const
[
state
,
setState
]
=
useState
({
const
[
state
,
setState
]
=
useState
({
email
:
''
,
email
:
''
,
redirectUrl
:
'http://localhost:3000/passwordreset'
//
redirectUrl: 'http://localhost:3000/passwordreset'
});
});
...
@@ -46,7 +46,7 @@ const ForgottenPassword = () => {
...
@@ -46,7 +46,7 @@ const ForgottenPassword = () => {
const
submitHandler
=
async
(
e
)
=>
{
const
submitHandler
=
async
(
e
)
=>
{
e
.
preventDefault
();
e
.
preventDefault
();
await
dispatch
(
loginUser
(
state
,
navigate
));
await
dispatch
(
forgottenPassword
(
state
,
navigate
));
};
};
...
...
planner-front/src/containers/Register/Register.js
View file @
4ab57d10
...
@@ -65,7 +65,7 @@ const Register = () => {
...
@@ -65,7 +65,7 @@ const Register = () => {
formData
.
append
(
key
,
state
[
key
]);
formData
.
append
(
key
,
state
[
key
]);
console
.
log
(
"key "
+
key
+
"state "
+
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
));
await
dispatch
(
registerUser
(
formData
,
navigate
));
}
else
{
}
else
{
alert
(
"Пароли не совпадают"
)
alert
(
"Пароли не совпадают"
)
...
...
planner-front/src/store/actions/usersActions.js
View file @
4ab57d10
...
@@ -85,14 +85,15 @@ export const forgottenPassword = (userData, navigate) => {
...
@@ -85,14 +85,15 @@ export const forgottenPassword = (userData, navigate) => {
return
async
(
dispatch
)
=>
{
return
async
(
dispatch
)
=>
{
try
{
try
{
console
.
log
(
'forgottenPassword userData '
,
userData
)
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) {
// if (userData.email === response.data.email) {
// }
// }
dispatch
(
loginUserSuccess
(
response
.
data
));
console
.
log
(
'response.data '
,
response
.
data
)
// dispatch(loginUserSuccess(response.data));
navigate
(
"/"
)
navigate
(
"/"
)
}
catch
(
e
)
{
}
catch
(
e
)
{
dispatch
(
loginUserFailure
(
e
?.
response
?.
data
?.
err
)
)
console
.
log
(
"user not found"
)
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment