Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
messenger
Commits
6bcffb88
Commit
6bcffb88
authored
Jan 18, 2021
by
우지원
Browse files
roomId수정
parents
35b35878
43ee14e5
Changes
5
Show whitespace changes
Inline
Side-by-side
client/src/Pages/HomePage.js
View file @
6bcffb88
...
@@ -9,9 +9,6 @@ import Menu from '../Components/Menu';
...
@@ -9,9 +9,6 @@ import Menu from '../Components/Menu';
import
catchErrors
from
'
../utils/catchErrors
'
;
import
catchErrors
from
'
../utils/catchErrors
'
;
import
{
io
}
from
"
socket.io-client
"
;
//모듈 가져오기
import
{
io
}
from
"
socket.io-client
"
;
//모듈 가져오기
import
Chat
from
"
../Components/Chat
"
;
import
Chat
from
"
../Components/Chat
"
;
import
{
customAlphabet
}
from
'
nanoid
'
;
import
{
Redirect
}
from
'
react-router-dom
'
;
const
socket
=
io
();
const
socket
=
io
();
const
INIT_ROOM
=
{
const
INIT_ROOM
=
{
...
@@ -31,7 +28,7 @@ function Home() {
...
@@ -31,7 +28,7 @@ function Home() {
const
[
singleChat
,
setSingleChat
]
=
useState
(
''
)
const
[
singleChat
,
setSingleChat
]
=
useState
(
''
)
const
[
roomName
,
setRoomName
]
=
useState
(
''
)
const
[
roomName
,
setRoomName
]
=
useState
(
''
)
const
[
success
,
setSuccess
]
=
useState
(
false
)
//
const [success, setSuccess] = useState(false)
const
handleClose
=
()
=>
setShow
(
false
);
const
handleClose
=
()
=>
setShow
(
false
);
const
handleShow
=
()
=>
setShow
(
true
);
const
handleShow
=
()
=>
setShow
(
true
);
...
@@ -41,8 +38,6 @@ function Home() {
...
@@ -41,8 +38,6 @@ function Home() {
const
handleShow2
=
()
=>
setShow2
(
true
);
const
handleShow2
=
()
=>
setShow2
(
true
);
const
moderator
=
sessionStorage
.
getItem
(
'
userId
'
);
const
moderator
=
sessionStorage
.
getItem
(
'
userId
'
);
const
nanoid
=
customAlphabet
(
'
1234567890abcdef
'
,
10
)
const
roomId
=
nanoid
()
useEffect
(()
=>
{
useEffect
(()
=>
{
const
isRoom
=
Object
.
values
(
room
).
every
(
el
=>
Boolean
(
el
))
const
isRoom
=
Object
.
values
(
room
).
every
(
el
=>
Boolean
(
el
))
...
@@ -51,22 +46,22 @@ function Home() {
...
@@ -51,22 +46,22 @@ function Home() {
function
handleChange
(
event
)
{
function
handleChange
(
event
)
{
const
{
name
,
value
}
=
event
.
target
const
{
name
,
value
}
=
event
.
target
setRoom
({
...
room
,
[
name
]:
value
,
moderator
,
roomId
})
setRoom
({
...
room
,
[
name
]:
value
,
moderator
})
//console.log(room)
//console.log(room)
}
}
console
.
log
(
room
)
console
.
log
(
room
)
console
.
log
(
room
.
roomId
)
async
function
handleSubmit
(
event
)
{
async
function
handleSubmit
(
event
)
{
event
.
preventDefault
()
event
.
preventDefault
()
try
{
try
{
setError
(
''
)
setError
(
''
)
await
axios
.
post
(
'
/room/makeRoom
'
,
room
)
let
res
=
await
axios
.
post
(
'
/room/makeRoom
'
,
room
)
// await axios.patch('/user/signup', { joinroom: `${room.roomId}`})
console
.
log
(
res
.
data
.
roomId
)
// await axios.post(`/user/${moderator}`, room.roomId)
const
Id
=
res
.
data
.
roomId
setSuccess
(
true
)
alert
(
`방암호는
${
Id
}
입니다`
)
// setSuccess(true)
// setRoom(INIT_ROOM)
// setRoom(INIT_ROOM)
setShow
(
false
)
setShow
(
false
)
}
catch
(
error
)
{
}
catch
(
error
)
{
...
@@ -96,13 +91,6 @@ function Home() {
...
@@ -96,13 +91,6 @@ function Home() {
})
})
},
[
singleChat
])
},
[
singleChat
])
// console.log(room.roomId)
if
(
success
)
{
// console.log(room.roomId)
alert
(
`방암호는
${
room
.
roomId
}
입니다`
)
// return <Redirect to='/home' />
}
return
(
return
(
<>
<>
<
Menu
/>
<
Menu
/>
...
...
server/controllers/room.controller.js
View file @
6bcffb88
import
Room
from
"
../models/Room.js
"
import
Room
from
"
../models/Room.js
"
//
import { customAlphabet } from 'nanoid'
import
{
customAlphabet
}
from
'
nanoid
'
import
isLength
from
'
validator/lib/isLength.js
'
import
isLength
from
'
validator/lib/isLength.js
'
//
const nanoid = customAlphabet('1234567890abcdef', 10)
const
nanoid
=
customAlphabet
(
'
1234567890abcdef
'
,
10
)
const
makeRoom
=
async
(
req
,
res
)
=>
{
const
makeRoom
=
async
(
req
,
res
)
=>
{
console
.
log
(
req
.
body
)
console
.
log
(
req
.
body
)
const
{
roomName
,
interest
,
isOpen
,
moderator
,
roomId
}
=
req
.
body
;
const
{
roomName
,
interest
,
isOpen
,
moderator
}
=
req
.
body
;
console
.
log
(
roomName
,
interest
,
isOpen
,
moderator
,
roomId
)
console
.
log
(
roomName
,
interest
,
isOpen
,
moderator
)
//
const roomId = nanoid()
const
roomId
=
nanoid
()
//
const room = await Room.findOne({ roomId })
const
room
=
await
Room
.
findOne
({
roomId
})
//
while (room) {
while
(
room
)
{
//
roomId = nanoid()
roomId
=
nanoid
()
//
room = await Room.findOne({ roomId })
room
=
await
Room
.
findOne
({
roomId
})
//
}
}
try
{
try
{
if
(
!
isLength
(
roomName
,
{
min
:
3
,
max
:
20
}))
{
if
(
!
isLength
(
roomName
,
{
min
:
3
,
max
:
20
}))
{
...
...
server/controllers/user.controller.js
View file @
6bcffb88
...
@@ -61,12 +61,14 @@ const changenick = async (req, res) => {
...
@@ -61,12 +61,14 @@ const changenick = async (req, res) => {
}
}
}
}
// const saveroom = async (req, res) => {
const
loginNavbar
=
async
(
req
,
res
)
=>
{
// const roomId = room.roomId
try
{
// if (!isLength(roomId, { min: 11 })) {
let
user
=
await
User
.
findOne
(
req
.
body
).
select
(
'
username
'
).
exec
()
// return res.status(422).send('방아이디 저장에 오류가 발생하였습니다.')
return
res
.
json
(
user
)
// }
}
catch
(
error
)
{
// }
alert
(
'
올바르지 못한 접근입니다.
'
)
}
}
export
default
{
signup
,
logineduser
,
changenick
}
export
default
{
signup
,
logineduser
,
changenick
,
loginNavbar
}
// {} : 객체로 return함
// {} : 객체로 return
함
server/models/Room.js
View file @
6bcffb88
...
@@ -13,10 +13,10 @@ const RoomSchema = new mongoose.Schema({
...
@@ -13,10 +13,10 @@ const RoomSchema = new mongoose.Schema({
select
:
false
select
:
false
},
},
isOpen
:
{
isOpen
:
{
type
:
String
,
type
:
Boolean
,
required
:
true
,
required
:
true
,
default
:
'
user
'
,
default
:
'
user
'
,
enum
:
[
'
true
'
,
'
false
'
]
enum
:
[
'
user
'
,
'
admin
'
,
'
root
'
]
},
},
moderator
:
{
moderator
:
{
type
:
String
,
type
:
String
,
...
...
server/routes/user.routes.js
View file @
6bcffb88
...
@@ -12,8 +12,6 @@ router.route(`/users/:userId`)
...
@@ -12,8 +12,6 @@ router.route(`/users/:userId`)
.
put
(
userCtrl
.
changenick
)
.
put
(
userCtrl
.
changenick
)
.
get
(
userCtrl
.
loginNavbar
)
.
get
(
userCtrl
.
loginNavbar
)
router
.
route
(
`users/:name`
)
.
post
(
userCtrl
.
saveroom
)
// router.param('userId', userCtrl.userById)
// router.param('userId', userCtrl.userById)
...
...
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