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
Hide whitespace changes
Inline
Side-by-side
client/src/Components/Chat.js
View file @
cb575cad
import
React
,
{
useEffect
,
useState
}
from
'
react
'
;
import
{
Form
,
Button
,
Row
}
from
'
react-bootstrap
'
;
// import axios from "axios";
function
Chat
(
props
)
{
// 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
)
{
e
.
preventDefault
()
...
...
@@ -17,26 +18,30 @@ function Chat(props) {
props
.
sendMsg
(
e
)
}
// async function getLoginedUser() { //email로 db에서 찾아오기
// const saveChange = (e) => {
// const { name, value } = e.target
// setNewName({ ...newName, [name]: value })
// }
//
const
userid = localStorage.getItem('user')
//
const response = await axios.post(`/users/${userid}`, { 'email': userid }
)
// set
Username(response.data.usernam
e)
// const
handleSubmit = (e) => {
//
e.preventDefault(
)
// set
State(tru
e)
// }
// useEffect(() => {
// getLoginedUser()
// console.log('Chat에서 useEffect', username)
// })
return
(
<
div
className
=
"
chat
"
id
=
"
chat
"
style
=
{{
border
:
"
2px solid
"
,
height
:
"
300%
"
,
margin
:
"
1%
"
,
borderColor
:
"
#BDBDBD
"
}}
>
<
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
>
{
props
.
chatmsg
.
map
((
value
,
index
)
=>
(
<
Row
key
=
{
index
}
className
=
'
ml-3
'
>
{
props
.
roomName
}
에서
{
user
name
}
님이
보낸
메세지
:
{
value
}
{
props
.
roomName
}
에서
{
default
name
}
님이
보낸
메세지
:
{
value
}
<
/Row
>
))}
...
...
client/src/Components/Menu.js
View file @
cb575cad
...
...
@@ -6,7 +6,7 @@ import { handleLogout } from '../utils/auth';
function
Menu
()
{
const
name
=
local
Storage
.
getItem
(
'
name
'
);
const
name
=
session
Storage
.
getItem
(
'
name
'
);
return
(
<
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
import
catchErrors
from
'
../utils/catchErrors
'
import
{
Link
,
Redirect
}
from
'
react-router-dom
'
import
{
handleLogin
}
from
'
../utils/auth
'
// import Menu from '../Components/Menu';
const
INIT_USER
=
{
email
:
''
,
...
...
client/src/utils/auth.js
View file @
cb575cad
...
...
@@ -2,18 +2,18 @@ import axios from "axios"
//자동으로 localstorage에 login이 생성됨
export
function
handleLogin
(
data
)
{
local
Storage
.
setItem
(
'
userId
'
,
data
.
user
.
_id
)
local
Storage
.
setItem
(
'
name
'
,
data
.
user
.
username
)
session
Storage
.
setItem
(
'
userId
'
,
data
.
user
.
_id
)
session
Storage
.
setItem
(
'
name
'
,
data
.
user
.
username
)
}
export
async
function
handleLogout
()
{
local
Storage
.
clear
();
session
Storage
.
clear
();
await
axios
.
get
(
'
/auth/logout
'
)
}
export
function
isAuthenticated
()
{
const
userId
=
local
Storage
.
getItem
(
'
userId
'
)
const
userId
=
session
Storage
.
getItem
(
'
userId
'
)
if
(
userId
)
{
return
userId
}
else
{
...
...
server/controllers/auth.controller.js
View file @
cb575cad
...
...
@@ -7,22 +7,13 @@ import config from "../config.js"
//sign validation해야됨
const
login
=
async
(
req
,
res
)
=>
{
const
{
email
,
password
}
=
req
.
body
//req.body를 구조분해하여 각각 보이게함 -> 모든정보들이 한줄에 보임
console
.
log
(
email
,
password
)
try
{
// 1) 사용자 확인
const
user
=
await
User
.
findOne
({
email
}).
select
(
'
+password
'
)
// 2) 이메일 사용자가 없으면 에러 반환
if
(
!
user
)
{
return
res
.
status
(
404
).
send
(
`
${
email
}
을 사용하는 사용자가 없습니다`
)
}
// 3) 비밀번호 일치 확인
const
passwordMatch
=
await
bcrypt
.
compare
(
password
,
user
.
password
)
// 4) 비밀번호가 맞으면 토큰 생성 후 쿠키에 저장
if
(
passwordMatch
)
{
//토큰 생성
const
token
=
jwt
.
sign
({
userId
:
user
.
_id
},
config
.
jwtSecret
,
{
expiresIn
:
'
7d
'
})
...
...
@@ -46,13 +37,12 @@ const login = async (req, res) => {
// 5) 비밀번호가 틀리면 에러 반환
res
.
status
(
401
).
send
(
'
비밀번호가 일치하지 않습니다
'
)
}
}
catch
(
error
)
{
//알수없는 모든 에러발생시 처리
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
로그인 에러가 발생하였습니다
'
)
}
}
const
logout
=
(
req
,
res
)
=>
{
...
...
server/models/Chat.js
View file @
cb575cad
import
mongoose
from
'
mongoose
'
const
{
String
}
=
mongoose
.
Schema
.
Types
const
{
String
}
=
mongoose
.
Schema
.
Types
const
ChatSchema
=
new
mongoose
.
Schema
({
name
:
{
type
:
String
,
room
:
{
type
:
ObjectId
,
required
:
true
,
ref
:
'
Room
'
,
},
interest
:
{
username
:
{
type
:
String
,
required
:
true
,
select
:
false
ref
:
'
User
'
,
},
isOpen
:
{
type
:
String
,
required
:
true
,
default
:
'
user
'
,
enum
:
[
'
user
'
,
'
admin
'
,
'
root
'
]
}
message
:
String
,
},
{
timestamps
:
true
})
export
default
mongoose
.
models
.
ChatSchema
||
mongoose
.
model
(
'
chat
'
,
ChatSchema
)
\ No newline at end of file
export
default
mongoose
.
models
.
ChatSchema
||
mongoose
.
model
(
'
Chat
'
,
ChatSchema
)
\ 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