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
62f25d08
Commit
62f25d08
authored
Nov 11, 2022
by
Ibadullina Inabat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
реализовано соединение бэка и фронта на регистрацию и логин
parent
1c5e08c3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
347 additions
and
23 deletions
+347
-23
package-lock.json
planner-api/package-lock.json
+294
-18
package.json
planner-api/package.json
+3
-0
.gitignore
planner-api/public/uploads/.gitignore
+11
-0
config.ts
planner-api/src/config.ts
+12
-0
users.ts
planner-api/src/routers/users.ts
+21
-2
Register.js
planner-front/src/containers/Register/Register.js
+2
-1
usersActions.js
planner-front/src/store/actions/usersActions.js
+2
-1
usersReducer.js
planner-front/src/store/reducers/usersReducer.js
+2
-1
No files found.
planner-api/package-lock.json
View file @
62f25d08
This diff is collapsed.
Click to expand it.
planner-api/package.json
View file @
62f25d08
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
"license"
:
"ISC"
,
"license"
:
"ISC"
,
"devDependencies"
:
{
"devDependencies"
:
{
"@faker-js/faker"
:
"^7.6.0"
,
"@faker-js/faker"
:
"^7.6.0"
,
"@types/multer"
:
"^1.4.7"
,
"@types/node"
:
"^18.11.8"
,
"@types/node"
:
"^18.11.8"
,
"@typescript-eslint/eslint-plugin"
:
"^5.41.0"
,
"@typescript-eslint/eslint-plugin"
:
"^5.41.0"
,
"@typescript-eslint/parser"
:
"^5.41.0"
,
"@typescript-eslint/parser"
:
"^5.41.0"
,
...
@@ -34,7 +35,9 @@
...
@@ -34,7 +35,9 @@
"cors"
:
"^2.8.5"
,
"cors"
:
"^2.8.5"
,
"express"
:
"^4.18.2"
,
"express"
:
"^4.18.2"
,
"mongoose"
:
"^6.7.0"
,
"mongoose"
:
"^6.7.0"
,
"multer"
:
"^1.4.5-lts.1"
,
"nanoid"
:
"^3.3.4"
,
"nanoid"
:
"^3.3.4"
,
"path"
:
"^0.12.7"
,
"pg"
:
"^8.8.0"
,
"pg"
:
"^8.8.0"
,
"reflect-metadata"
:
"^0.1.13"
,
"reflect-metadata"
:
"^0.1.13"
,
"typeorm"
:
"^0.3.10"
"typeorm"
:
"^0.3.10"
...
...
planner-api/public/uploads/.gitignore
0 → 100644
View file @
62f25d08
*
!.gitignore
!_ACzV5N3r69BCMdpyqmGC.png
!lDmNHjGy5I2g1mWMR-n_c.png
!ExATi9O98uKnHxJ_wqUS2.png
!Aqvv8P8AgL_1xfC93CLKp.png
!NqUZ1Tq8pxbVptmhZPKcd.png
!46AlFQI4qKG2GpuJGdKbG.png
!ip5KgNCs30o3djHb8V_GR.png
!1tlFOumiL3MmH89O8OO6H.png
!nTVRV1ZePPe7tTIdGKKfX.png
\ No newline at end of file
planner-api/src/config.ts
0 → 100644
View file @
62f25d08
import
path
=
require
(
'path'
);
const
rootPath
=
__dirname
;
export
const
config
=
{
rootPath
,
uploadPath
:
path
.
join
(
rootPath
,
"public"
,
"uploads"
),
db
:
{
url
:
"mongodb://localhost/"
,
name
:
"planner"
}
};
planner-api/src/routers/users.ts
View file @
62f25d08
...
@@ -2,10 +2,25 @@ import express,{Router, Request, Response} from 'express';
...
@@ -2,10 +2,25 @@ import express,{Router, Request, Response} from 'express';
import
{
User
}
from
'../models/User'
;
import
{
User
}
from
'../models/User'
;
import
{
myDataSource
}
from
'../app-data-source'
;
import
{
myDataSource
}
from
'../app-data-source'
;
import
{
nanoid
}
from
'nanoid'
;
import
{
nanoid
}
from
'nanoid'
;
import
multer
=
require
(
'multer'
);
import
path
=
require
(
"path"
);
import
{
config
}
from
"../config"
const
router
:
Router
=
express
.
Router
();
const
router
:
Router
=
express
.
Router
();
const
dataSource
=
myDataSource
;
const
dataSource
=
myDataSource
;
const
storage
=
multer
.
diskStorage
({
destination
:
(
req
,
file
,
cb
)
=>
{
cb
(
null
,
config
.
uploadPath
);
},
filename
:
(
req
,
file
,
cb
)
=>
{
cb
(
null
,
nanoid
()
+
path
.
extname
(
file
.
originalname
));
}
})
const
upload
=
multer
({
storage
})
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
object
>
=>
{
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
object
>
=>
{
const
users
=
await
dataSource
const
users
=
await
dataSource
.
getRepository
(
User
)
.
getRepository
(
User
)
...
@@ -15,9 +30,10 @@ return res.send({users})
...
@@ -15,9 +30,10 @@ return res.send({users})
})
})
router
.
post
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
object
>
=>
{
router
.
post
(
'/'
,
upload
.
single
(
"avatar"
),
async
(
req
:
Request
,
res
:
Response
):
Promise
<
object
>
=>
{
console
.
log
(
req
.
body
)
const
{
name
,
surname
,
password
,
email
,
role
}
=
req
.
body
;
const
{
name
,
surname
,
password
,
email
,
role
}
=
req
.
body
;
console
.
log
(
req
.
body
)
const
displayName
=
surname
+
' '
+
name
[
0
]
+
'.'
const
displayName
=
surname
+
' '
+
name
[
0
]
+
'.'
const
user
=
new
User
();
const
user
=
new
User
();
user
.
name
=
name
;
user
.
name
=
name
;
...
@@ -27,10 +43,13 @@ router.post('/', async (req : Request, res : Response):Promise<object> => {
...
@@ -27,10 +43,13 @@ router.post('/', async (req : Request, res : Response):Promise<object> => {
user
.
email
=
email
;
user
.
email
=
email
;
user
.
role
=
role
;
user
.
role
=
role
;
user
.
generateToken
()
user
.
generateToken
()
console
.
log
(
"user "
+
user
)
await
user
.
save
();
await
user
.
save
();
console
.
log
(
"saved"
)
const
userToFront
:
User
|
null
=
await
dataSource
.
manager
.
findOneBy
(
User
,
{
const
userToFront
:
User
|
null
=
await
dataSource
.
manager
.
findOneBy
(
User
,
{
email
:
user
.
email
email
:
user
.
email
})
})
console
.
log
(
"userToFront "
+
userToFront
)
return
res
.
send
({
userToFront
})
return
res
.
send
({
userToFront
})
})
})
...
...
planner-front/src/containers/Register/Register.js
View file @
62f25d08
...
@@ -62,9 +62,10 @@ const Register = () => {
...
@@ -62,9 +62,10 @@ const Register = () => {
const
formData
=
new
FormData
();
const
formData
=
new
FormData
();
Object
.
keys
(
state
).
forEach
(
key
=>
{
Object
.
keys
(
state
).
forEach
(
key
=>
{
formData
.
append
(
key
,
state
[
key
]);
formData
.
append
(
key
,
state
[
key
]);
console
.
log
(
"key "
+
key
+
"state "
+
state
[
key
])
})
})
await
dispatch
(
registerUser
(
formData
,
navigate
));
await
dispatch
(
registerUser
(
formData
,
navigate
));
await
dispatch
(
loginUser
(
state
,
navigate
))
//
dispatch(loginUser(state, navigate))
};
};
const
getFieldError
=
(
fieldname
)
=>
{
const
getFieldError
=
(
fieldname
)
=>
{
...
...
planner-front/src/store/actions/usersActions.js
View file @
62f25d08
...
@@ -18,6 +18,7 @@ export const registerUser = (userData, navigate) => {
...
@@ -18,6 +18,7 @@ export const registerUser = (userData, navigate) => {
return
async
(
dispatch
)
=>
{
return
async
(
dispatch
)
=>
{
dispatch
(
registerUserRequest
());
dispatch
(
registerUserRequest
());
try
{
try
{
console
.
log
(
"register "
+
userData
)
const
response
=
await
axios
.
post
(
"/users"
,
userData
);
const
response
=
await
axios
.
post
(
"/users"
,
userData
);
dispatch
(
registerUserSuccess
())
dispatch
(
registerUserSuccess
())
navigate
(
"/"
)
navigate
(
"/"
)
...
@@ -52,7 +53,7 @@ export const loginUser = (userData, navigate) => {
...
@@ -52,7 +53,7 @@ export const loginUser = (userData, navigate) => {
console
.
log
(
userData
)
console
.
log
(
userData
)
const
response
=
await
axios
.
post
(
"users/sessions"
,
userData
);
const
response
=
await
axios
.
post
(
"users/sessions"
,
userData
);
console
.
log
(
response
)
console
.
log
(
response
)
dispatch
(
loginUserSuccess
(
response
.
data
));
dispatch
(
loginUserSuccess
(
response
.
data
.
user
));
navigate
(
"/"
)
navigate
(
"/"
)
}
catch
(
e
)
{
}
catch
(
e
)
{
dispatch
(
loginUserFailure
(
e
?.
response
?.
data
?.
err
))
dispatch
(
loginUserFailure
(
e
?.
response
?.
data
?.
err
))
...
...
planner-front/src/store/reducers/usersReducer.js
View file @
62f25d08
...
@@ -12,11 +12,12 @@ const usersReducer = (state = initialState, action) => {
...
@@ -12,11 +12,12 @@ const usersReducer = (state = initialState, action) => {
case
REGISTER_USER_REQUEST
:
case
REGISTER_USER_REQUEST
:
return
{...
state
,
loading
:
true
};
return
{...
state
,
loading
:
true
};
case
REGISTER_USER_SUCCESS
:
case
REGISTER_USER_SUCCESS
:
console
.
log
(
"register.user "
+
action
)
return
{...
state
,
loading
:
false
};
return
{...
state
,
loading
:
false
};
case
REGISTER_USER_FAILURE
:
case
REGISTER_USER_FAILURE
:
return
{...
state
,
loading
:
false
,
registerError
:
action
.
error
};
return
{...
state
,
loading
:
false
,
registerError
:
action
.
error
};
case
LOGIN_USER_SUCCESS
:
case
LOGIN_USER_SUCCESS
:
console
.
log
(
"action.user
"
+
action
.
user
)
console
.
log
(
"action.user
"
+
action
)
return
{...
state
,
user
:
action
.
user
};
return
{...
state
,
user
:
action
.
user
};
case
LOGIN_USER_FAILURE
:
case
LOGIN_USER_FAILURE
:
console
.
log
(
"action.error"
+
action
.
error
)
console
.
log
(
"action.error"
+
action
.
error
)
...
...
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