Commit f0e5bcdb authored by 우지원's avatar 우지원
Browse files

Merge remote-tracking branch 'origin/young' into jiweon827

parents e3e80e27 36320a85
...@@ -22,7 +22,7 @@ npm-debug.log* ...@@ -22,7 +22,7 @@ npm-debug.log*
yarn-debug.log* yarn-debug.log*
yarn-error.log* yarn-error.log*
package-lock.json .env
.eslintcache .eslintcache
.package-lock.json
debug.log debug.log
.env
...@@ -3,6 +3,7 @@ import './App.css'; ...@@ -3,6 +3,7 @@ import './App.css';
import Hello from './Hello'; import Hello from './Hello';
function App() { function App() {
console.log()
return ( return (
<Hello name='대기'/> <Hello name='대기'/>
); );
......
import React from 'react'; import React, { useEffect, useState } from 'react';
import { Form, Button } from 'react-bootstrap'; import { Form, Button, Row } from 'react-bootstrap';
import axios from "axios";
function Chat(props) { function Chat(props) {
const [username, setUsername] = useState('')
function handleChange(e) {
e.preventDefault()
props.setInner(e.target.value)
console.log(e.target.value)
}
function sendMsgCH(e) {
props.sendMsg(e)
}
async function getLoginedUser() { //email로 db에서 찾아오기 ㅇㅇㅇㅇㅇ
const userid = localStorage.getItem('user')
const response = await axios.post(`/users/${userid}`, { 'email': userid })
setUsername(response.data.username)
}
useEffect(() => {
getLoginedUser()
console.log('Chat에서 useEffect', username)
})
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>
<h2>현재 {props.roomName} 입니다.</h2>
{ props.chatmsg.map((value, index) => (
<Row key={index} className='ml-3'>
{props.roomName}에서 {username}님이 보낸 메세지 : {value}
</Row>
))}
<Form onSubmit={sendMsgCH}>
<Form.Control name='msg' type='text' onChange={handleChange} />
<Button variant="primary" type="submit">전송</Button>
</Form>
<Form> <Form>
<Form.Group> <Form.Group>
<Form.Control type="text" /> <Form.Control type="text" />
......
import React, { useState } from 'react' import React, { useState } from 'react'
import { ListGroup } from 'react-bootstrap'; import { ListGroup, Row, Col } from 'react-bootstrap';
function ClosedList() { function ClosedList(props) {
const [list, setList] = useState([ const [list, setList] = useState([
{ room: '테스트 방1', memnum: 5, admin: '가영' }, { room: '테스트 방1', memnum: 5, admin: '가영' },
{ room: '테스트 방2', memnum: 4, admin: '수현' }] { room: '테스트 방2', memnum: 4, admin: '수현' }]
); );
function enterChatroomCH(e) {
const roomName = e.target.name
props.enterChatroom(roomName) // 각각의 room으로 들어가도록 설정해야 함
props.setRoomName(roomName)
props.clearChat()
}
return ( return (
<div> <div>
<Row>
{list.map((list, index) => {list.map((list, index) =>
<ListGroup key={index}> <ListGroup key={index}>
<ListGroup.Item action> <ListGroup.Item action onClick={enterChatroomCH} name={list.room}>
<h2>{list.room}</h2> {list.room}
</ListGroup.Item> </ListGroup.Item>
</ListGroup> </ListGroup>
)} )}
</Row>
<Col>
</Col>
</div> </div>
) )
} }
......
...@@ -12,8 +12,8 @@ function Hello(props) { ...@@ -12,8 +12,8 @@ function Hello(props) {
<Navbar.Brand href="/homepage">YDK Messenger</Navbar.Brand> <Navbar.Brand href="/homepage">YDK Messenger</Navbar.Brand>
<div className='ml-1 mr-2' style={{ color: 'white' }}>{userName} 환영합니다</div> <div className='ml-1 mr-2' style={{ color: 'white' }}>{userName} 환영합니다</div>
<Nav className="mr-auto"> <Nav className="mr-auto">
<Nav.Link href="/homepage">Home</Nav.Link> <Nav.Link href="/home">Home</Nav.Link>
<Nav.Link href="/profilepage">Profile</Nav.Link> <Nav.Link href="/profile">Profile</Nav.Link>
<Nav.Link href="/hello">Hello</Nav.Link> <Nav.Link href="/hello">Hello</Nav.Link>
</Nav> </Nav>
{/* <Form inline> {/* <Form inline>
......
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import axios from 'axios'; import { Row, Col, Modal, Button, Navbar, Nav } from 'react-bootstrap';
import { Row, Col, Modal, Button, Form, Alert } from 'react-bootstrap';
import Tabs from 'react-bootstrap/Tabs'; import Tabs from 'react-bootstrap/Tabs';
import Tab from 'react-bootstrap/Tab'; import Tab from 'react-bootstrap/Tab';
import ClosedList from '../Components/ClosedList'; import ClosedList from '../Components/ClosedList';
import OpenList from '../Components/OpenList'; import OpenList from '../Components/OpenList';
import Chat from '../Components/Chat'; import Chat from '../Components/Chat';
import Menu from '../Components/Menu'; import Menu from '../Components/Menu';
import catchErrors from '../utils/catchErrors';
// import styled from 'styled-components'; // import styled from 'styled-components';
import { io } from "socket.io-client"; //모듈 가져오기
// const List = styled.div` // const List = styled.div`
// background: #FFFAFA; // background: #FFFAFA;
// ` // `
const userName = "정연우";
const socket = io();
const INIT_CHATR = {
name: '',
interest: '',
isOpen: false
}
function Home() { function Home() {
const [show, setShow] = useState(false); const [show, setShow] = useState(false);
const [show2, setShow2] = useState(false);
const [chat, setChat] = useState(false); const [chat, setChat] = useState(false);
// const [checkedI, setCheckedI] = useState(false);
const [chatR, setChatR] = useState(INIT_CHATR);
const [disabled, setDisabled] = useState(true);
const [error, setError] = useState('');
const handleClose = () => setShow(false); const handleClose = () => setShow(false);
const handleShow = () => setShow(true); const handleShow = () => setShow(true);
const handleChato = () => setChat(true); const handleChato = () => setChat(true);
const handleChatc = () => setChat(false); const handleChatc = () => setChat(false);
const handleClose2 = () => setShow2(false);
const handleShow2 = () => setShow2(true);
// variant="pills" // variant="pills"
useEffect(() => { const [inner, setInner] = useState([''])
const isChatR = Object.values(chatR).every(el => Boolean(el)) console.log('sendMsg2222', inner)
isChatR ? setDisabled(false) : setDisabled(true) const [chatmsg, setChatmsg] = useState([inner])
}, [chatR]) const [roomName, setRoomName] = useState('dd') //방 선택이 방1을 눌럿다 방2를 누르면 전체로 전송됨
function handleChange(event) { function enterChatroom(roomName) { //방 입장하기
const { name, value } = event.target socket.emit('joinRoom', roomName)
setChatR({ ...chatR, [name]: value }) console.log(`joinRoom : ${roomName} 입장`)
} }
async function handleSubmit(event) { const sendMsg = (e) => {
event.preventDefault() e.preventDefault()
try { console.log('sendMsg', inner)
setError('') console.log(roomName)
// const response = await fetch('chat/makeChat', { socket.emit("chat", {
// method: 'POST', roomName: roomName,
// headers: { msg: inner
// 'Content-Type': 'application/json' });
// },
// body: JSON.stringify(chatR)
// })
//const data = await response.json()
const response = await axios.post('chat/makeChat', chatR)
setChatR(INIT_CHATR)
} catch (error){
catchErrors(error, setError)
} }
function clearChat() {
setChatmsg([])
} }
useEffect(() => {
console.log('useeffect1')
socket.on('broadcast', (msg) => {
console.log('msg', msg)
console.log('inner :', inner)
setChatmsg([...chatmsg, msg])
console.log('useeffect2', chatmsg)
})
console.log('useeffect2', chatmsg)
}, [chatmsg])
return ( return (
<> <>
<Menu /> <Menu />
...@@ -73,7 +71,7 @@ function Home() { ...@@ -73,7 +71,7 @@ function Home() {
<Col className="list" md={5}> <Col className="list" md={5}>
<Tabs defaultActiveKey="closed" id="uncontrolled-tab-example"> <Tabs defaultActiveKey="closed" id="uncontrolled-tab-example">
<Tab eventKey="closed" title="내 채팅" onClick={handleChato} > <Tab eventKey="closed" title="내 채팅" onClick={handleChato} >
<ClosedList /> <ClosedList enterChatroom={enterChatroom} setRoomName={setRoomName} clearChat={clearChat} />
</Tab> </Tab>
<Tab eventKey="open" title="공개방" > <Tab eventKey="open" title="공개방" >
<OpenList /> <OpenList />
...@@ -81,90 +79,22 @@ function Home() { ...@@ -81,90 +79,22 @@ function Home() {
</Tabs> </Tabs>
</Col> </Col>
<Col style={{ padding: "0" }}> <Col style={{ padding: "0" }}>
{chat ? <Chat handleChatc={handleChatc} /> : null} {chat ? <Chat handleChatc={handleChatc} sendMsg={sendMsg} setInner={setInner} chatmsg={chatmsg} roomName={roomName} /> : null}
<div style={{ position: "fixed", bottom: "20px", right: "30px" }}> <Button variant="primary" onClick={handleShow} style={{ position: "fixed", bottom: "10px", right: "10px" }} >
<Button variant="primary" onClick={handleShow} size="lg" block>
생성 생성
</Button> </Button>
<Button variant="secondary" onClick={handleShow2} size="lg" block>
참가
</Button>
</div>
<Modal show={show} onHide={handleClose}> <Modal show={show} onHide={handleClose}>
<Modal.Header closeButton> <Modal.Header closeButton>
<Modal.Title> 생성</Modal.Title> <Modal.Title> 생성</Modal.Title>
</Modal.Header> </Modal.Header>
{error && <Alert variant='danger'> <Modal.Body>여기에 form 입력</Modal.Body>
{error} <Modal.Footer>
</Alert>} <Button variant="primary" onClick={handleClose}>
<Modal.Body> 생성
<Form onSubmit={handleSubmit}> </Button>
<Form.Group as={Row} controlId="chatName"> </Modal.Footer>
<Form.Label column sm={4}> 이름</Form.Label>
<Col>
<Form.Control name='name' type='text' value={chatR.name} onChange={handleChange} />
</Col>
</Form.Group>
<Form.Group as={Row} controlId="chatInterest">
<Form.Label column sm={4}>관심 분야</Form.Label>
<Col>
<Form.Control as="select" defaultValue="Choose..." name='interest' type='text' value={chatR.interest} onChange={handleChange}>
<option>Choose...</option>
<option>과학</option>
<option>수학</option>
<option>예술</option>
<option>언어</option>
<option>취미</option>
</Form.Control>
{/* <Form.Control type="text" /> */}
</Col>
</Form.Group>
<Form.Group as={Row} controlId="chatIsOpen">
<Form.Label column sm={4}>공개방</Form.Label>
<Col>
<Form.Check
type="checkbox"
checked={chatR.isOpen}
name='isOpen'
onChange={() => setChatR({ ...chatR, isOpen: !chatR.isOpen })} />
</Col>
</Form.Group>
{
(chatR.isOpen)
? (<p><b>공개방</b>으로 개설되어 공개방 목록에 공개되며, 코드를 공유하여 참가할 수도 있습니다.</p>)
: (<p><b>비밀방</b>으로 개설되며, 참여자들에게 코드를 공유해야합니다.</p>)
}
<Form.Group as={Row}>
<Col sm={{ span: 5, offset: 4 }}>
<Button type="submit" > 생성</Button>
</Col>
</Form.Group>
</Form>
</Modal.Body>
</Modal>
<Modal show={show2} onHide={handleClose2}>
<Modal.Header closeButton>
<Modal.Title>참여 코드로 채팅 참가</Modal.Title>
</Modal.Header>
<Modal.Body>
<Form onSubmit={() => { console.log('제출') }}>
<Form.Group as={Row} controlId="formCodeE">
<Form.Label column sm={4}>참여 코드</Form.Label>
<Col>
<Form.Control type="text" />
</Col>
</Form.Group>
<Form.Group as={Row}>
<Col sm={{ span: 5, offset: 4 }}>
<Button type="submit">참가</Button>
</Col>
</Form.Group>
</Form>
</Modal.Body>
</Modal> </Modal>
</Col> </Col>
</Row> </Row>
...@@ -173,3 +103,4 @@ function Home() { ...@@ -173,3 +103,4 @@ function Home() {
} }
export default Home; export default Home;
This diff is collapsed.
client/src/Pages/user_default.svg <?xml version="1.0" encoding="iso-8859-1"?>
\ No newline at end of file <!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 53 53" style="enable-background:new 0 0 53 53;" xml:space="preserve">
<path style="fill:#E7ECED;" d="M18.613,41.552l-7.907,4.313c-0.464,0.253-0.881,0.564-1.269,0.903C14.047,50.655,19.998,53,26.5,53
c6.454,0,12.367-2.31,16.964-6.144c-0.424-0.358-0.884-0.68-1.394-0.934l-8.467-4.233c-1.094-0.547-1.785-1.665-1.785-2.888v-3.322
c0.238-0.271,0.51-0.619,0.801-1.03c1.154-1.63,2.027-3.423,2.632-5.304c1.086-0.335,1.886-1.338,1.886-2.53v-3.546
c0-0.78-0.347-1.477-0.886-1.965v-5.126c0,0,1.053-7.977-9.75-7.977s-9.75,7.977-9.75,7.977v5.126
c-0.54,0.488-0.886,1.185-0.886,1.965v3.546c0,0.934,0.491,1.756,1.226,2.231c0.886,3.857,3.206,6.633,3.206,6.633v3.24
C20.296,39.899,19.65,40.986,18.613,41.552z"/>
<g>
<path style="fill:#556080;" d="M26.953,0.004C12.32-0.246,0.254,11.414,0.004,26.047C-0.138,34.344,3.56,41.801,9.448,46.76
c0.385-0.336,0.798-0.644,1.257-0.894l7.907-4.313c1.037-0.566,1.683-1.653,1.683-2.835v-3.24c0,0-2.321-2.776-3.206-6.633
c-0.734-0.475-1.226-1.296-1.226-2.231v-3.546c0-0.78,0.347-1.477,0.886-1.965v-5.126c0,0-1.053-7.977,9.75-7.977
s9.75,7.977,9.75,7.977v5.126c0.54,0.488,0.886,1.185,0.886,1.965v3.546c0,1.192-0.8,2.195-1.886,2.53
c-0.605,1.881-1.478,3.674-2.632,5.304c-0.291,0.411-0.563,0.759-0.801,1.03V38.8c0,1.223,0.691,2.342,1.785,2.888l8.467,4.233
c0.508,0.254,0.967,0.575,1.39,0.932c5.71-4.762,9.399-11.882,9.536-19.9C53.246,12.32,41.587,0.254,26.953,0.004z"/>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
</svg>
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import 'bootstrap/dist/css/bootstrap.min.css';
import './index.css'; import './index.css';
// import App from './App'; // import App from './App';
import SignUpPage from './Pages/SignUpPage'; import SignUpPage from './Pages/SignUpPage';
......
import axios from "axios" import axios from "axios"
//자동으로 localstorage에 login이 생성됨 //자동으로 localstorage에 login이 생성됨
export function handleLogin(userId) { export function handleLogin(props) {
localStorage.setItem('user', userId) localStorage.setItem('user', props.email)
// localStorage.setItem('user', JSON.stringify({email: props.email}))
} }
export async function handleLogout() { export async function handleLogout() {
localStorage.removeItem('user') localStorage.removeItem('user')
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
"main": "index.js", "main": "index.js",
"type": "module", "type": "module",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "dev": "nodemon server/server.js",
"dev": "nodemon server/server.js" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"cors": "^2.8.5", "cors": "^2.8.5",
"express": "^4.17.1", "express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.11.9", "mongoose": "^5.11.9",
"nanoid": "^3.1.20", "nanoid": "^3.1.20",
"nodemon": "^2.0.6", "nodemon": "^2.0.6",
......
import Profile from "../models/profile.js"
import bcrypt from "bcryptjs";
import jwt from 'jsonwebtoken'
import config from "../config.js"
const getimage = async (req, res) => {
const defaultimg = 'https://t1.daumcdn.net/cfile/tistory/2761AA4558A05CBE2A'
// const newImg = await new Profile({
// defaultimg
// //required를 하였기 때문에 이중 하나라도 없으면 에러 발생
// }).save()
}
export default { getimage }
\ No newline at end of file
import User from "../models/User.js" import User from "../models/User.js"
import isLength from 'validator/lib/isLength.js' import isLength from 'validator/lib/isLength.js'
import isEmail from 'validator/lib/isEmail.js' import isEmail from 'validator/lib/isEmail.js'
import bcrypt from 'bcryptjs' import bcrypt from "bcryptjs";
import jwt from 'jsonwebtoken'
import config from "../config.js"
//꼭 js붙여주기!! //꼭 js붙여주기!!
//sign validation해야됨 //sign validation해야됨
...@@ -12,13 +14,13 @@ const signup = async (req, res) => { ...@@ -12,13 +14,13 @@ const signup = async (req, res) => {
console.log(username, nickname, email, password) console.log(username, nickname, email, password)
try { try {
if (!isLength(username, {min: 3, max: 10})){ if (!isLength(username, { min: 3, max: 10 })) {
//이범위를 벗어나면 error발생 //이범위를 벗어나면 error발생
return res.status(422).send('이름은 3-10자 사이입니다') return res.status(422).send('이름은 3-10자 사이입니다')
//422 : 형식이 잘못되었다는 error발생 //422 : 형식이 잘못되었다는 error발생
} else if (!isLength(nickname, {min: 2, max: 10})) { } else if (!isLength(nickname, { min: 2, max: 10 })) {
return res.status(422).send('별명은 2-10자 사이입니다.') return res.status(422).send('별명은 2-10자 사이입니다.')
} else if (!isLength(password, {min: 6})) { } else if (!isLength(password, { min: 6 })) {
return res.status(422).send('비밀번호는 6자 이상입니다.') return res.status(422).send('비밀번호는 6자 이상입니다.')
} else if (!isEmail(email)) { } else if (!isEmail(email)) {
return res.status(422).send('유효하지 않은 이메일 형식입니다') return res.status(422).send('유효하지 않은 이메일 형식입니다')
...@@ -36,8 +38,8 @@ const signup = async (req, res) => { ...@@ -36,8 +38,8 @@ const signup = async (req, res) => {
// } // }
// 기존의 email이 있으면 나오는 error (unique) // 기존의 email이 있으면 나오는 error (unique)
const user = await User.findOne({email}) const user = await User.findOne({ email })
if(user) { if (user) {
return res.status(422).send(`${email}이 이미 사용중입니다.`) return res.status(422).send(`${email}이 이미 사용중입니다.`)
} }
...@@ -61,42 +63,32 @@ const signup = async (req, res) => { ...@@ -61,42 +63,32 @@ const signup = async (req, res) => {
console.log(error) console.log(error)
res.status(500).send('회원가입 에러발생하였습니다.') res.status(500).send('회원가입 에러발생하였습니다.')
} }
//newUSer (객체)를 json형식으로 바꿔서 객체열로 보냄
//res : 응답하는 객체
//응답안할 시 browser에서 빙빙돌다 에러 발생 -> 꼭 붙여줘야됨!
//res는 한번만 실행. 두번하면 에러 발생
} }
const hello = async (req, res) => {
let users = await User.find().select('name nickname email _id').exec()
return res.json(users)
}
const loginNavbar = async (req, res) => {
const logineduser = async (req, res) => {
try { try {
let user = await User.findOne(req.body).select('username').exec() let user = await User.findOne(req.body).select('username email nickname').exec()
return res.json(user) return res.json(user)
} catch (error) { } catch (error) {
alert('올바르지 못한 접근입니다.') alert('올바르지 못한 접근입니다.')
} }
} }
// const loginNavbar = (req, res) => { const changenick = async (req, res) => {
// res.json(req.login) try {
// } const newnick = req.body.nickname
await User.update({ 'username': req.body.username }, { 'nickname': newnick })
// const userById = async (req, res, next, id) => { } catch (error) {
// try { alert('올바르지 못한 접근입니다.')
// const user = await User.findById(id) }
// if (!user) { }
// res.status(404).send('사용자를 찾을 수 없습니다.')
// }
// req.login = user
// //req에 profile을 만들어서 user를 저장해줌
// next()
// //다음 middleware로 이동시킴 / 없으면 멈춤
// } catch (error) {
// console.log(error)
// res.status(500).send('사용자 아이디 검색 실패')
// }
// }
export default { signup ,loginNavbar } export default { signup, hello, logineduser, changenick }
// {} : 객체로 return함 // {} : 객체로 return함
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment