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
9b487731
Commit
9b487731
authored
Nov 10, 2022
by
Ibadullina Inabat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
проделана работа по восстановлению пароля
parent
0e93993f
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
127 additions
and
80 deletions
+127
-80
users.ts
planner-api/src/routers/users.ts
+2
-0
App.js
planner-front/src/App.js
+2
-0
ResetPasswordForm.js
planner-front/src/components/UserForm/ResetPasswordForm.js
+28
-0
UserForm.js
planner-front/src/components/UserForm/UserForm.js
+5
-5
UserRegistrationForm.js
...ner-front/src/components/UserForm/UserRegistrationForm.js
+2
-2
ForgottenPassword.js
...ont/src/containers/ForgottenPassword/ForgottenPassword.js
+63
-63
Login.js
planner-front/src/containers/Login/Login.js
+1
-1
Register.js
planner-front/src/containers/Register/Register.js
+1
-1
usersActions.js
planner-front/src/store/actions/usersActions.js
+18
-0
usersReducer.js
planner-front/src/store/reducers/usersReducer.js
+5
-8
No files found.
planner-api/src/routers/users.ts
View file @
9b487731
...
...
@@ -36,6 +36,7 @@ router.post('/', async (req : Request, res : Response):Promise<object> => {
router
.
post
(
'/sessions/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
object
>
=>
{
const
{
email
,
password
}
=
req
.
body
;
console
.
log
(
"email"
+
email
,
"password"
+
password
)
const
user
=
await
dataSource
.
createQueryBuilder
()
.
select
(
"user"
)
...
...
@@ -45,6 +46,7 @@ router.post('/sessions/', async (req : Request, res : Response):Promise<object>
if
(
!
user
)
return
res
.
status
(
404
).
send
({
Message
:
'user not found'
})
const
isMatch
:
boolean
=
await
user
.
checkPassword
(
password
);
console
.
log
(
"123"
)
if
(
!
isMatch
)
return
res
.
status
(
400
).
send
({
error
:
"Wrong Password"
})
...
...
planner-front/src/App.js
View file @
9b487731
...
...
@@ -6,6 +6,7 @@ import MyTasks from './containers/MyTasks/MyTasks';
import
Login
from
'./containers/Login/Login'
;
import
Register
from
'./containers/Register/Register'
;
import
MonthCalendar
from
'./containers/MonthCalendar/MonthCalendar'
;
import
ForgottenPassword
from
"./containers/ForgottenPassword/ForgottenPassword"
;
const
ProtectedRoute
=
({
isAllowed
,
roles
,
redirectUrl
,
children
})
=>
{
const
user
=
useSelector
(
state
=>
state
.
users
?.
user
);
...
...
@@ -95,6 +96,7 @@ const App = () => {
}
/
>
<
Route
path
=
{
"/sign-in"
}
element
=
{
<
Login
/>
}
/
>
<
Route
path
=
{
"/forgottenpassword"
}
element
=
{
<
ForgottenPassword
/>
}
/
>
<
Route
path
=
'*'
element
=
{
<
h1
>
404
<
/h1>}/
>
<
/Route
>
<
/Routes
>
...
...
planner-front/src/components/UserForm/ResetPasswordForm.js
0 → 100644
View file @
9b487731
import
{
Button
,
Grid
}
from
"@mui/material"
;
import
{
NavLink
}
from
"react-router-dom"
;
import
FormElement
from
"../UI/Form/FormElement/FormElement"
;
const
ResetPasswordForm
=
({
state
,
onChange
,
onSubmit
,
getFieldError
,
buttonText
})
=>
{
return
<
form
onSubmit
=
{
onSubmit
}
>
<
Grid
container
spacing
=
{
2
}
>
<
FormElement
onChange
=
{
onChange
}
name
=
"email"
label
=
"Enter your email address"
state
=
{
state
}
error
=
{
getFieldError
?.(
"email"
)}
/
>
<
/Grid
>
<
Button
sx
=
{{
mt
:
"15px"
}}
type
=
"submit"
fullWidth
variant
=
"contained"
color
=
"primary"
>
{
buttonText
}
<
/Button
>
<
/form
>
}
export
default
ResetPasswordForm
;
\ No newline at end of file
planner-front/src/components/UserForm/UserForm.js
View file @
9b487731
import
{
Button
,
Grid
}
from
"@mui/material"
;
//
import { NavLink } from "react-router-dom";
import
{
NavLink
}
from
"react-router-dom"
;
import
FormElement
from
"../UI/Form/FormElement/FormElement"
;
const
UserForm
=
({
state
,
onChange
,
onSubmit
,
getFieldError
,
buttonText
,
resetPassword
})
=>
{
...
...
@@ -30,17 +30,17 @@ const UserForm = ({ state, onChange, onSubmit, getFieldError, buttonText, resetP
>
{
buttonText
}
<
/Button
>
{
/*
<Button
<
Button
component
=
{
NavLink
}
to
=
{
"/forgottenpassword"
}
sx={{ mt: "15px" }}
sx
=
{{
mt
:
"15px"
,
color
:
"red"
}}
type
=
"submit"
fullWidth
variant
=
"contained"
color="
primary
"
color
=
"
inherit
"
>
{
resetPassword
}
</Button>
*/
}
<
/Button
>
<
/form
>
}
...
...
planner-front/src/components/UserForm/UserRegistrationForm.js
View file @
9b487731
...
...
@@ -25,13 +25,13 @@ const UserRegistrationForm = ({ state, onChange, onSubmit, getFieldError, button
state
=
{
state
}
error
=
{
getFieldError
?.(
"email"
)}
/
>
<
FormElement
{
/*
<FormElement
onChange={onChange}
name="number"
label="Number"
state={state}
error={getFieldError?.("number")}
/
>
/>
*/
}
<
FormElement
onChange
=
{
onChange
}
name
=
"password"
...
...
planner-front/src/containers/ForgottenPassword/ForgottenPassword.js
View file @
9b487731
//
import { useState } from "react";
//
import { useDispatch, useSelector } from "react-redux";
//
import { useNavigate } from "react-router-dom";
//
import Loader from "../../components/UI/Loader/Loader";
// import UserForm from "../../components/UserForm/UserForm
";
// import { 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
";
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
PersonIcon
from
'@mui/icons-material/Person'
;
import
styled
from
"@emotion/styled"
;
import
{
Alert
,
Avatar
,
Container
,
Typography
}
from
"@mui/material
"
;
import
ResetPasswordForm
from
"../../components/UserForm/ResetPasswordForm
"
;
//
const StyledContainer = styled(Container)`
//
padding-top: 30px;
//
padding-bottom: 30px;
//
box-shadow: 0 18px 30px 0 rgba(0, 0, 0, 0.6);
//
border-radius: 6px;
//
`;
const
StyledContainer
=
styled
(
Container
)
`
padding-top: 30px;
padding-bottom: 30px;
box-shadow: 0 18px 30px 0 rgba(0, 0, 0, 0.6);
border-radius: 6px;
`
;
//
const StyledTitle = styled(Typography)`
//
text-align: center;
//
font-size: 30px;
//
margin-bottom: 30px;
//
`;
const
StyledTitle
=
styled
(
Typography
)
`
text-align: center;
font-size: 30px;
margin-bottom: 30px;
`
;
//
const ForgottenPassword = () => {
//
const [state, setState] = useState({
//
email: '',
//
redirectUrl: 'http://localhost:3000/passwordreset'
//
});
const
ForgottenPassword
=
()
=>
{
const
[
state
,
setState
]
=
useState
({
email
:
''
,
redirectUrl
:
'http://localhost:3000/passwordreset'
});
//
const dispatch = useDispatch();
//
const { loginError, loading } = useSelector(state => state.users);
//
console.log(loginError)
//
const navigate = useNavigate("/")
const
dispatch
=
useDispatch
();
const
{
loginError
,
loading
}
=
useSelector
(
state
=>
state
.
users
);
console
.
log
(
loginError
)
const
navigate
=
useNavigate
(
"/"
)
//
const inputChangeHandler = (e) => {
//
const { name, value } = e.target;
//
setState((prevState) => {
//
return {
//
...prevState,
//
[name]: value
//
}
//
});
//
};
const
inputChangeHandler
=
(
e
)
=>
{
const
{
name
,
value
}
=
e
.
target
;
setState
((
prevState
)
=>
{
return
{
...
prevState
,
[
name
]:
value
}
});
};
//
const submitHandler = async (e) => {
//
e.preventDefault();
//
await dispatch(loginUser(state, navigate));
//
};
const
submitHandler
=
async
(
e
)
=>
{
e
.
preventDefault
();
await
dispatch
(
loginUser
(
state
,
navigate
));
};
//
return <>
//
<StyledContainer component={"section"} maxWidth={"xs"}>
//
{!!loginError && <Alert color="error">{loginError}</Alert>}
//
<Avatar sx={{ m: "0 auto 30px" }}>
//
<PersonIcon />
//
</Avatar>
//
<StyledTitle variant={"h1"}>
//
Password Reset
//
</StyledTitle>
// <User
Form
//
onSubmit={submitHandler}
//
state={state}
//
onChange={inputChangeHandler}
// buttonText={"Sign In
"}
//
resetPassword={"Forgot your password?"}
//
/>
//
</StyledContainer>
//
<Loader loading={loading} />
//
</>
//
};
return
<>
<
StyledContainer
component
=
{
"section"
}
maxWidth
=
{
"xs"
}
>
{
!!
loginError
&&
<
Alert
color
=
"error"
>
{
loginError
}
<
/Alert>
}
<
Avatar
sx
=
{{
m
:
"0 auto 30px"
}}
>
<
PersonIcon
/>
<
/Avatar
>
<
StyledTitle
variant
=
{
"h1"
}
>
Password
Reset
<
/StyledTitle
>
<
ResetPassword
Form
onSubmit
=
{
submitHandler
}
state
=
{
state
}
onChange
=
{
inputChangeHandler
}
buttonText
=
{
"Submit
"
}
resetPassword
=
{
"Forgot your password?"
}
/
>
<
/StyledContainer
>
<
Loader
loading
=
{
loading
}
/
>
<
/
>
};
// export default ForgottenPassword;
\ No newline at end of file
export
default
ForgottenPassword
;
\ No newline at end of file
planner-front/src/containers/Login/Login.js
View file @
9b487731
...
...
@@ -62,7 +62,7 @@ const Login = () => {
state
=
{
state
}
onChange
=
{
inputChangeHandler
}
buttonText
=
{
"Sign In"
}
//
resetPassword={"Forgot your password?"}
resetPassword
=
{
"Forgot your password?"
}
/
>
<
/StyledContainer
>
<
Loader
loading
=
{
loading
}
/
>
...
...
planner-front/src/containers/Register/Register.js
View file @
9b487731
...
...
@@ -26,7 +26,7 @@ const Register = () => {
name
:
''
,
surname
:
""
,
email
:
""
,
number
:
""
,
//
number: "",
password
:
''
,
// avatar: "",
});
...
...
planner-front/src/store/actions/usersActions.js
View file @
9b487731
...
...
@@ -49,7 +49,25 @@ const logoutUserFailure = (error) => {
export
const
loginUser
=
(
userData
,
navigate
)
=>
{
return
async
(
dispatch
)
=>
{
try
{
console
.
log
(
userData
)
const
response
=
await
axios
.
post
(
"users/sessions"
,
userData
);
console
.
log
(
response
)
dispatch
(
loginUserSuccess
(
response
.
data
));
navigate
(
"/"
)
}
catch
(
e
)
{
dispatch
(
loginUserFailure
(
e
?.
response
?.
data
?.
err
))
}
}
}
export
const
forgottenPassword
=
(
userData
,
navigate
)
=>
{
return
async
(
dispatch
)
=>
{
try
{
console
.
log
(
userData
)
const
response
=
await
axios
.
post
(
"users/requestPasswordReset"
,
userData
);
// if (userData.email === response.data.email) {
// }
dispatch
(
loginUserSuccess
(
response
.
data
));
navigate
(
"/"
)
}
catch
(
e
)
{
...
...
planner-front/src/store/reducers/usersReducer.js
View file @
9b487731
import
{
REGISTER_USER_REQUEST
,
REGISTER_USER_SUCCESS
,
REGISTER_USER_FAILURE
,
LOGIN_USER_SUCCESS
,
LOGIN_USER_FAILURE
,
LOGOUT_USER_SUCCESS
}
from
"../actionTypes/actionTypes"
;
const
initialState
=
{
user
:
{
name
:
'Ivan'
,
surname
:
'Petrov'
,
email
:
'test@gmail.com'
,
role
:
'user'
},
user
:
null
,
registerError
:
null
,
loginError
:
null
,
loading
:
false
};
const
usersRedu
s
er
=
(
state
=
initialState
,
action
)
=>
{
const
usersRedu
c
er
=
(
state
=
initialState
,
action
)
=>
{
switch
(
action
.
type
)
{
case
REGISTER_USER_REQUEST
:
return
{...
state
,
loading
:
true
};
...
...
@@ -21,8 +16,10 @@ const usersReduser = (state = initialState, action) => {
case
REGISTER_USER_FAILURE
:
return
{...
state
,
loading
:
false
,
registerError
:
action
.
error
};
case
LOGIN_USER_SUCCESS
:
console
.
log
(
"action.user"
+
action
.
user
)
return
{...
state
,
user
:
action
.
user
};
case
LOGIN_USER_FAILURE
:
console
.
log
(
"action.error"
+
action
.
error
)
return
{...
state
,
loginError
:
action
.
error
};
case
LOGOUT_USER_SUCCESS
:
return
{...
state
,
user
:
null
};
...
...
@@ -31,4 +28,4 @@ const usersReduser = (state = initialState, action) => {
}
};
export
default
usersRedu
s
er
;
export
default
usersRedu
c
er
;
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