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
cb575cad
Commit
cb575cad
authored
Jan 15, 2021
by
Choi Ga Young
Browse files
aa
parent
1c9e6868
Changes
17
Show whitespace changes
Inline
Side-by-side
client/src/Components/Chat.js
View file @
cb575cad
import
React
,
{
useEffect
,
useState
}
from
'
react
'
;
import
React
,
{
useEffect
,
useState
}
from
'
react
'
;
import
{
Form
,
Button
,
Row
}
from
'
react-bootstrap
'
;
import
{
Form
,
Button
,
Row
}
from
'
react-bootstrap
'
;
// import axios from "axios";
function
Chat
(
props
)
{
function
Chat
(
props
)
{
// const [username, setUsername] = useState('')
// const [username, setUsername] = useState('')
const
username
=
localStorage
.
getItem
(
'
name
'
);
let
defaultname
=
sessionStorage
.
getItem
(
'
name
'
);
// const [newName, setNewName] = useState({ username: '' });
// const [state, setState] = useState(false);
function
handleChange
(
e
)
{
function
handleChange
(
e
)
{
e
.
preventDefault
()
e
.
preventDefault
()
...
@@ -17,26 +18,30 @@ function Chat(props) {
...
@@ -17,26 +18,30 @@ function Chat(props) {
props
.
sendMsg
(
e
)
props
.
sendMsg
(
e
)
}
}
// async function getLoginedUser() { //email로 db에서 찾아오기
// const saveChange = (e) => {
// const { name, value } = e.target
// const userid = localStorage.getItem('user')
// setNewName({ ...newName, [name]: value })
// const response = await axios.post(`/users/${userid}`, { 'email': userid })
// setUsername(response.data.username)
// }
// }
//
useEffect((
) => {
//
const handleSubmit = (e
) => {
//
getLoginedUser
()
//
e.preventDefault
()
//
console.log('Chat에서 useEffect', usernam
e)
//
setState(tru
e)
// }
)
// }
return
(
return
(
<
div
className
=
"
chat
"
id
=
"
chat
"
style
=
{{
border
:
"
2px solid
"
,
height
:
"
300%
"
,
margin
:
"
1%
"
,
borderColor
:
"
#BDBDBD
"
}}
>
<
div
className
=
"
chat
"
id
=
"
chat
"
style
=
{{
border
:
"
2px solid
"
,
height
:
"
300%
"
,
margin
:
"
1%
"
,
borderColor
:
"
#BDBDBD
"
}}
>
<
Button
variant
=
"
light
"
onClick
=
{
props
.
handleChatc
}
>
{
`<`
}
<
/Button
>
<
Button
variant
=
"
light
"
onClick
=
{
props
.
handleChatc
}
>
{
`<`
}
<
/Button
>
<
Form
onSubmit
=
{
handleSubmit
}
>
<
Form
.
Control
name
=
'
newname
'
type
=
'
text
'
onChange
=
{
saveChange
}
/
>
<
Button
variant
=
"
primary
"
type
=
"
submit
"
>
전송
<
/Button
>
<
/Form
>
<
h2
>
현재
{
props
.
roomName
}
입니다
.
<
/h2
>
<
h2
>
현재
{
props
.
roomName
}
입니다
.
<
/h2
>
{
props
.
chatmsg
.
map
((
value
,
index
)
=>
(
{
props
.
chatmsg
.
map
((
value
,
index
)
=>
(
<
Row
key
=
{
index
}
className
=
'
ml-3
'
>
<
Row
key
=
{
index
}
className
=
'
ml-3
'
>
{
props
.
roomName
}
에서
{
user
name
}
님이
보낸
메세지
:
{
value
}
{
props
.
roomName
}
에서
{
default
name
}
님이
보낸
메세지
:
{
value
}
<
/Row
>
<
/Row
>
))}
))}
...
...
client/src/Components/Menu.js
View file @
cb575cad
...
@@ -6,7 +6,7 @@ import { handleLogout } from '../utils/auth';
...
@@ -6,7 +6,7 @@ import { handleLogout } from '../utils/auth';
function
Menu
()
{
function
Menu
()
{
const
name
=
local
Storage
.
getItem
(
'
name
'
);
const
name
=
session
Storage
.
getItem
(
'
name
'
);
return
(
return
(
<
Navbar
bg
=
"
dark
"
variant
=
"
dark
"
>
<
Navbar
bg
=
"
dark
"
variant
=
"
dark
"
>
...
...
client/src/
P
ages/KakaoTalk_20201230_153151693.png
→
client/src/
Im
ages/KakaoTalk_20201230_153151693.png
View file @
cb575cad
File moved
client/src/
P
ages/img1.png
→
client/src/
Im
ages/img1.png
View file @
cb575cad
File moved
client/src/
P
ages/img2.jpg
→
client/src/
Im
ages/img2.jpg
View file @
cb575cad
File moved
client/src/
P
ages/img_1.png
→
client/src/
Im
ages/img_1.png
View file @
cb575cad
File moved
client/src/
P
ages/img_2.png
→
client/src/
Im
ages/img_2.png
View file @
cb575cad
File moved
client/src/
P
ages/img_3.jpg
→
client/src/
Im
ages/img_3.jpg
View file @
cb575cad
File moved
client/src/
P
ages/rion.png
→
client/src/
Im
ages/rion.png
View file @
cb575cad
File moved
client/src/
P
ages/user_default.png
→
client/src/
Im
ages/user_default.png
View file @
cb575cad
File moved
client/src/
P
ages/user_default.svg
→
client/src/
Im
ages/user_default.svg
View file @
cb575cad
File moved
client/src/Pages/LogInPage.js
View file @
cb575cad
...
@@ -4,7 +4,6 @@ import { Button, Form, Container, Navbar, Spinner, Alert } from 'react-bootstrap
...
@@ -4,7 +4,6 @@ import { Button, Form, Container, Navbar, Spinner, Alert } from 'react-bootstrap
import
catchErrors
from
'
../utils/catchErrors
'
import
catchErrors
from
'
../utils/catchErrors
'
import
{
Link
,
Redirect
}
from
'
react-router-dom
'
import
{
Link
,
Redirect
}
from
'
react-router-dom
'
import
{
handleLogin
}
from
'
../utils/auth
'
import
{
handleLogin
}
from
'
../utils/auth
'
// import Menu from '../Components/Menu';
const
INIT_USER
=
{
const
INIT_USER
=
{
email
:
''
,
email
:
''
,
...
...
client/src/utils/auth.js
View file @
cb575cad
...
@@ -2,18 +2,18 @@ import axios from "axios"
...
@@ -2,18 +2,18 @@ import axios from "axios"
//자동으로 localstorage에 login이 생성됨
//자동으로 localstorage에 login이 생성됨
export
function
handleLogin
(
data
)
{
export
function
handleLogin
(
data
)
{
local
Storage
.
setItem
(
'
userId
'
,
data
.
user
.
_id
)
session
Storage
.
setItem
(
'
userId
'
,
data
.
user
.
_id
)
local
Storage
.
setItem
(
'
name
'
,
data
.
user
.
username
)
session
Storage
.
setItem
(
'
name
'
,
data
.
user
.
username
)
}
}
export
async
function
handleLogout
()
{
export
async
function
handleLogout
()
{
local
Storage
.
clear
();
session
Storage
.
clear
();
await
axios
.
get
(
'
/auth/logout
'
)
await
axios
.
get
(
'
/auth/logout
'
)
}
}
export
function
isAuthenticated
()
{
export
function
isAuthenticated
()
{
const
userId
=
local
Storage
.
getItem
(
'
userId
'
)
const
userId
=
session
Storage
.
getItem
(
'
userId
'
)
if
(
userId
)
{
if
(
userId
)
{
return
userId
return
userId
}
else
{
}
else
{
...
...
server/controllers/auth.controller.js
View file @
cb575cad
...
@@ -7,22 +7,13 @@ import config from "../config.js"
...
@@ -7,22 +7,13 @@ import config from "../config.js"
//sign validation해야됨
//sign validation해야됨
const
login
=
async
(
req
,
res
)
=>
{
const
login
=
async
(
req
,
res
)
=>
{
const
{
email
,
password
}
=
req
.
body
const
{
email
,
password
}
=
req
.
body
//req.body를 구조분해하여 각각 보이게함 -> 모든정보들이 한줄에 보임
console
.
log
(
email
,
password
)
try
{
try
{
// 1) 사용자 확인
const
user
=
await
User
.
findOne
({
email
}).
select
(
'
+password
'
)
const
user
=
await
User
.
findOne
({
email
}).
select
(
'
+password
'
)
// 2) 이메일 사용자가 없으면 에러 반환
if
(
!
user
)
{
if
(
!
user
)
{
return
res
.
status
(
404
).
send
(
`
${
email
}
을 사용하는 사용자가 없습니다`
)
return
res
.
status
(
404
).
send
(
`
${
email
}
을 사용하는 사용자가 없습니다`
)
}
}
// 3) 비밀번호 일치 확인
const
passwordMatch
=
await
bcrypt
.
compare
(
password
,
user
.
password
)
const
passwordMatch
=
await
bcrypt
.
compare
(
password
,
user
.
password
)
// 4) 비밀번호가 맞으면 토큰 생성 후 쿠키에 저장
if
(
passwordMatch
)
{
if
(
passwordMatch
)
{
//토큰 생성
//토큰 생성
const
token
=
jwt
.
sign
({
userId
:
user
.
_id
},
config
.
jwtSecret
,
{
expiresIn
:
'
7d
'
})
const
token
=
jwt
.
sign
({
userId
:
user
.
_id
},
config
.
jwtSecret
,
{
expiresIn
:
'
7d
'
})
...
@@ -52,7 +43,6 @@ const login = async (req, res) => {
...
@@ -52,7 +43,6 @@ const login = async (req, res) => {
console
.
log
(
error
)
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
로그인 에러가 발생하였습니다
'
)
res
.
status
(
500
).
send
(
'
로그인 에러가 발생하였습니다
'
)
}
}
}
}
const
logout
=
(
req
,
res
)
=>
{
const
logout
=
(
req
,
res
)
=>
{
...
...
server/models/Chat.js
View file @
cb575cad
import
mongoose
from
'
mongoose
'
import
mongoose
from
'
mongoose
'
const
{
String
}
=
mongoose
.
Schema
.
Types
const
{
String
}
=
mongoose
.
Schema
.
Types
const
ChatSchema
=
new
mongoose
.
Schema
({
const
ChatSchema
=
new
mongoose
.
Schema
({
name
:
{
room
:
{
type
:
String
,
type
:
ObjectId
,
required
:
true
,
required
:
true
,
ref
:
'
Room
'
,
},
},
interest
:
{
username
:
{
type
:
String
,
type
:
String
,
required
:
true
,
required
:
true
,
select
:
false
ref
:
'
User
'
,
},
},
isOpen
:
{
message
:
String
,
type
:
String
,
required
:
true
,
default
:
'
user
'
,
enum
:
[
'
user
'
,
'
admin
'
,
'
root
'
]
}
},
{
},
{
timestamps
:
true
timestamps
:
true
})
})
export
default
mongoose
.
models
.
ChatSchema
||
mongoose
.
model
(
'
chat
'
,
ChatSchema
)
export
default
mongoose
.
models
.
ChatSchema
||
mongoose
.
model
(
'
Chat
'
,
ChatSchema
)
\ No newline at end of file
\ No newline at end of file
server/models/Room.js
0 → 100644
View file @
cb575cad
import
mongoose
from
'
mongoose
'
const
{
String
}
=
mongoose
.
Schema
.
Types
const
RoomSchema
=
new
mongoose
.
Schema
({
name
:
{
type
:
String
,
required
:
true
,
},
interest
:
{
type
:
String
,
required
:
true
,
select
:
false
},
isOpen
:
{
type
:
String
,
required
:
true
,
default
:
'
user
'
,
enum
:
[
'
user
'
,
'
admin
'
,
'
root
'
]
}
},
{
timestamps
:
true
})
export
default
mongoose
.
models
.
RoomSchema
||
mongoose
.
model
(
'
Room
'
,
RoomSchema
)
\ No newline at end of file
server/models/profile.js
deleted
100644 → 0
View file @
1c9e6868
import
mongoose
from
'
mongoose
'
const
{
String
}
=
mongoose
.
Schema
.
Types
const
ProfileSchema
=
new
mongoose
.
Schema
({
defaultImg
:
{
type
:
String
,
required
:
true
,
},
},
{
timestamps
:
true
})
export
default
mongoose
.
models
.
ProfileSchema
||
mongoose
.
model
(
'
profile
'
,
ProfileSchema
)
\ No newline at end of file
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