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*
yarn-debug.log*
yarn-error.log*
package-lock.json
.env
.eslintcache
.package-lock.json
debug.log
.env
......@@ -3,6 +3,7 @@ import './App.css';
import Hello from './Hello';
function App() {
console.log()
return (
<Hello name='대기'/>
);
......
import React from 'react';
import { Form, Button } from 'react-bootstrap';
import React, { useEffect, useState } from 'react';
import { Form, Button, Row } from 'react-bootstrap';
import axios from "axios";
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 (
<div className="chat" id="chat" style={{ border: "2px solid", height: "300%", margin: "1%", borderColor: "#BDBDBD" }}>
<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.Group>
<Form.Control type="text" />
......
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([
{ room: '테스트 방1', memnum: 5, admin: '가영' },
{ room: '테스트 방2', memnum: 4, admin: '수현' }]
);
function enterChatroomCH(e) {
const roomName = e.target.name
props.enterChatroom(roomName) // 각각의 room으로 들어가도록 설정해야 함
props.setRoomName(roomName)
props.clearChat()
}
return (
<div>
<Row>
{list.map((list, index) =>
<ListGroup key={index}>
<ListGroup.Item action>
<h2>{list.room}</h2>
<ListGroup.Item action onClick={enterChatroomCH} name={list.room}>
{list.room}
</ListGroup.Item>
</ListGroup>
)}
</Row>
<Col>
</Col>
</div>
)
}
......
......@@ -12,8 +12,8 @@ function Hello(props) {
<Navbar.Brand href="/homepage">YDK Messenger</Navbar.Brand>
<div className='ml-1 mr-2' style={{ color: 'white' }}>{userName} 환영합니다</div>
<Nav className="mr-auto">
<Nav.Link href="/homepage">Home</Nav.Link>
<Nav.Link href="/profilepage">Profile</Nav.Link>
<Nav.Link href="/home">Home</Nav.Link>
<Nav.Link href="/profile">Profile</Nav.Link>
<Nav.Link href="/hello">Hello</Nav.Link>
</Nav>
{/* <Form inline>
......
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import { Row, Col, Modal, Button, Form, Alert } from 'react-bootstrap';
import { Row, Col, Modal, Button, Navbar, Nav } from 'react-bootstrap';
import Tabs from 'react-bootstrap/Tabs';
import Tab from 'react-bootstrap/Tab';
import ClosedList from '../Components/ClosedList';
import OpenList from '../Components/OpenList';
import Chat from '../Components/Chat';
import Menu from '../Components/Menu';
import catchErrors from '../utils/catchErrors';
// import styled from 'styled-components';
import { io } from "socket.io-client"; //모듈 가져오기
// const List = styled.div`
// background: #FFFAFA;
// `
const userName = "정연우";
const socket = io();
const INIT_CHATR = {
name: '',
interest: '',
isOpen: false
}
function Home() {
const [show, setShow] = useState(false);
const [show2, setShow2] = 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 handleShow = () => setShow(true);
const handleChato = () => setChat(true);
const handleChatc = () => setChat(false);
const handleClose2 = () => setShow2(false);
const handleShow2 = () => setShow2(true);
// variant="pills"
useEffect(() => {
const isChatR = Object.values(chatR).every(el => Boolean(el))
isChatR ? setDisabled(false) : setDisabled(true)
}, [chatR])
const [inner, setInner] = useState([''])
console.log('sendMsg2222', inner)
const [chatmsg, setChatmsg] = useState([inner])
const [roomName, setRoomName] = useState('dd') //방 선택이 방1을 눌럿다 방2를 누르면 전체로 전송됨
function handleChange(event) {
const { name, value } = event.target
setChatR({ ...chatR, [name]: value })
function enterChatroom(roomName) { //방 입장하기
socket.emit('joinRoom', roomName)
console.log(`joinRoom : ${roomName} 입장`)
}
async function handleSubmit(event) {
event.preventDefault()
try {
setError('')
// const response = await fetch('chat/makeChat', {
// method: 'POST',
// headers: {
// '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)
const sendMsg = (e) => {
e.preventDefault()
console.log('sendMsg', inner)
console.log(roomName)
socket.emit("chat", {
roomName: roomName,
msg: inner
});
}
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 (
<>
<Menu />
......@@ -73,7 +71,7 @@ function Home() {
<Col className="list" md={5}>
<Tabs defaultActiveKey="closed" id="uncontrolled-tab-example">
<Tab eventKey="closed" title="내 채팅" onClick={handleChato} >
<ClosedList />
<ClosedList enterChatroom={enterChatroom} setRoomName={setRoomName} clearChat={clearChat} />
</Tab>
<Tab eventKey="open" title="공개방" >
<OpenList />
......@@ -81,90 +79,22 @@ function Home() {
</Tabs>
</Col>
<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} size="lg" block>
<Button variant="primary" onClick={handleShow} style={{ position: "fixed", bottom: "10px", right: "10px" }} >
생성
</Button>
<Button variant="secondary" onClick={handleShow2} size="lg" block>
참가
</Button>
</div>
<Modal show={show} onHide={handleClose}>
<Modal.Header closeButton>
<Modal.Title> 생성</Modal.Title>
</Modal.Header>
{error && <Alert variant='danger'>
{error}
</Alert>}
<Modal.Body>
<Form onSubmit={handleSubmit}>
<Form.Group as={Row} controlId="chatName">
<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.Body>여기에 form 입력</Modal.Body>
<Modal.Footer>
<Button variant="primary" onClick={handleClose}>
생성
</Button>
</Modal.Footer>
</Modal>
</Col>
</Row>
......@@ -173,3 +103,4 @@ function Home() {
}
export default Home;
// import React, { useState, useEffect } from 'react';
// import ReactDOM from 'react-dom';
// import Menu from '../Components/Menu';
// import { Image, Button, Container, Form, FormControl, Navbar, Nav, Row, Col, Dropdown, Carousel } from 'react-bootstrap';
// import { BrowserRouter as Router, Route, Redirect, Switch, Link } from 'react-router-dom';
// import axios from 'axios'
import React, { useState, useEffect } from 'react';
import ReactDOM from 'react-dom';
import Menu from '../Components/Menu';
import { Image, Button, Container, Form, FormControl, Navbar, Nav, Row, Col, Dropdown, Carousel } from 'react-bootstrap';
import { BrowserRouter as Router, Route, Redirect, Switch, Link } from 'react-router-dom';
import axios from 'axios'
// // import userdefault from './KakaoTalk_20201230_153151693.png'
// import userimg from './KakaoTalk_20201230_153151693.png'
// // import img1 from './img_1.png'
// // import img2 from './img_2.png'
// // import img3 from './img_3.jpg'
// import DropdownItem from 'react-bootstrap/esm/DropdownItem';
import userdefault from './KakaoTalk_20201230_153151693.png'
import img1 from './img_1.png'
import img2 from './img_2.png'
import img3 from './img_3.jpg'
import DropdownItem from 'react-bootstrap/esm/DropdownItem';
// const INIT_USER = {
......@@ -19,168 +18,244 @@
// nickname: ''
// }
// function ProfilePage() {
// const [user, setUser] = useState(INIT_USER)
function ProfilePage() {
const [user, setUser] = useState('')
// // const [userimg, setUserimg] = useState(img2)
// const [defaultImg, setDefaultImg] = useState(true)
// const [hidden, setHidden] = useState(true)
const [userimg, setUserimg] = useState(img2)
const [defaultImg, setDefaultImg] = useState(true)
const [hidden, setHidden] = useState(true)
// async function getLoginedUser() { //email로 db에서 찾아오기 ㅇㅇㅇㅇㅇ
// const userid = localStorage.getItem('user')
// const response = await axios.post(`/users/${userid}`, { 'email': userid })
// setUser(response.data)
// }
async function getLoginedUser() { //email로 db에서 찾아오기 ㅇㅇㅇㅇㅇ
const userid = localStorage.getItem('user')
const response = await axios.post(`/users/${userid}`, { 'email': userid })
setUser(response.data)
}
// function handleSubmit(e) {
// e.preventDefault()
// if (hidden) {
// setHidden(false)
// } else {
// setHidden(true)
// }
// console.log(document.cookie)
// }
// function handleChange(e) {
// setUser({ ...user, 'nickname': e.target.value })
// }
// async function handleNicksave() {
// const userid = localStorage.getItem('user')
// await axios.put(`/users/${userid}`, user)
// }
function handleSubmit(e) {
e.preventDefault()
if (hidden) {
setHidden(false)
} else {
setHidden(true)
}
console.log(document.cookie)
}
function handleChange(e) {
setUser({ ...user, 'nickname': e.target.value })
}
async function handleNicksave() {
const userid = localStorage.getItem('user')
await axios.put(`/users/${userid}`, user)
}
// function setThumbnail(event) { //불러온 사진 <div id='image_container'>에 띄우기
// let reader = new FileReader();
// reader.onload = function (event) {
// let img = document.createElement("img");
// img.setAttribute("src", event.target.result);
// img.setAttribute("id", "profileImg")
// img.setAttribute("style", 'height:300px; width:300px')
// img.setAttribute("class", "mb-3")
// // img.setAttribute("class","d-flex justify-content-center mb-3")
// document.querySelector("div#image_container").appendChild(img);
// };
// reader.readAsDataURL(event.target.files[0]);
// if (defaultImg) { //첫 이미지 업로드(default이미지 지우고 유저가 올린걸로 업로드)
// let del = document.getElementById("defaultImg")
// del.remove()
// setDefaultImg(false)
// }
// else { //기존에 올렸던 사진 지우고 재선택한 사진 업로드
// let del2 = document.getElementById('profileImg')
// del2.remove()
// reader.onload = function (event) {
// let img = document.createElement("img");
// img.setAttribute("src", event.target.result);
// img.setAttribute("id", "profileImg")
// img.setAttribute("style", 'height:300px; width:300px')
// document.querySelector("div#image_container").appendChild(img);
// };
// }
// }
// useEffect(() => {
// if (localStorage.getItem('user')) { //id뿐만아니라 토큰같은거를 확인 못하나 + 이런식으로 확인해도 되는것도 맞나
// getLoginedUser()
// }
// else {
// alert("로그인 후 이용하세요")
// window.location.href = '/login'
// }
// }, [])
// return (
// <div>
// <Menu />
// <Container className="d-flex justify-content-center">
// <div className="mt-5 shadow w-75">
// <h1 className="text-center mt-4 ml-5 mr-5 mb-3">Profile Page</h1>
// <h4 className="text-center mb-5">{user.username}님 환영합니다 !</h4>
// <div className="d-flex justify-content-center mb-3" id="defaultImg">
// <Image src={userimg} width="300px" roundedCircle />
// </div>
// <Row className="d-flex justify-content-center">
// <Form className="d-flex justify-content-center">
// <Form.Group>
// <div id="image_container"></div>
// <Form.File label="프로필 사진 변경" accept="image/*" onChange={setThumbnail} />
// </Form.Group>
// </Form>
// </Row>
// <Row className="d-flex justify-content-center">
// <Dropdown>
// <Dropdown.Toggle variant='success' id='dropdown-basic'>
// 프로필 사진 선택
// </Dropdown.Toggle>
// <Dropdown.Menu>
// <Dropdown.Item as='button'>홈으로</Dropdown.Item>
// <Dropdown.Item href='/'>라이언</Dropdown.Item>
// <Dropdown.Item href='/'>어피치</Dropdown.Item>
// </Dropdown.Menu>
// </Dropdown>
// </Row>
// {/* <Carousel className="d-flex justify-content-center" style={{ width: "300px", height: "300px" }}>
// <Carousel.Item className="d-flex justify-content-center">
// <Image
// className="d-block w-100"
// src={img1}
// />
// <Carousel.Caption>
// <p style={{color : 'black'}}>펭수입니다.</p>
// </Carousel.Caption>
// </Carousel.Item>
// <Carousel.Item>
// <Image
// className="d-block w-100"
// src={img2}
// />
// <Carousel.Caption>
// <p>라이언입니다.</p>
// </Carousel.Caption>
// </Carousel.Item>
// <Carousel.Item>
// <Image
// className="d-block w-100"
// src={img3}
// />
// <Carousel.Caption>
// <p>어피치 입니다.</p>
// </Carousel.Caption>
// </Carousel.Item>
// </Carousel> */}
// <div className="text-center">
// <div className="m-3" style={{ fontWeight: "bold", fontSize: "x-large" }}>이름 : {user.username}</div>
// <div className="m-3" id="nickname">
// <Form className="d-flex justify-content-center" onSubmit={handleSubmit} style={{ fontWeight: "bold", fontSize: "x-large" }}>
// 별명 :
// <div hidden={!hidden}>
// {user.nickname}
// </div>
// <Form.Control defaultValue={user.nickname} style={{ width: "40%" }} size="sm" onChange={handleChange} hidden={hidden} />
// <Button className="ml-3" variant="outline-primary" size="sm" type='submit'>수정</Button>
// </Form>
// </div>
// <div className="m-3" style={{ fontWeight: "bold", fontSize: "x-large" }}>이메일 : {user.email}</div>
// </div>
// <div className="text-center m-5">
// <Form>
// <Button variant="outline-success" size="sm" className="mr-4" onClick={handleNicksave}>저장</Button>
// <Link to='/'>
// <Button variant="outline-success" size="sm" className="ml-4" >홈 화면으로</Button>
// </Link>
// </Form>
// </div>
// </div>
// </Container>
// </div>
// )
// }
function setThumbnail(event) { //불러온 사진 <div id='image_container'>에 띄우기
let reader = new FileReader();
reader.onload = function (event) {
let img = document.createElement("img");
img.setAttribute("src", event.target.result);
img.setAttribute("id", "profileImg")
img.setAttribute("style", 'height:300px; width:300px')
img.setAttribute("class", "mb-3")
// img.setAttribute("class","d-flex justify-content-center mb-3")
document.querySelector("div#image_container").appendChild(img);
};
reader.readAsDataURL(event.target.files[0]);
if (defaultImg) { //첫 이미지 업로드(default이미지 지우고 유저가 올린걸로 업로드)
let del = document.getElementById("defaultImg")
del.remove()
setDefaultImg(false)
}
else { //기존에 올렸던 사진 지우고 재선택한 사진 업로드
let del2 = document.getElementById('profileImg')
del2.remove()
reader.onload = function (event) {
let img = document.createElement("img");
img.setAttribute("src", event.target.result);
img.setAttribute("id", "profileImg")
img.setAttribute("style", 'height:300px; width:300px')
document.querySelector("div#image_container").appendChild(img);
};
}
}
useEffect(() => {
if (localStorage.getItem('user')) { //id뿐만아니라 토큰같은거를 확인 못하나 + 이런식으로 확인해도 되는것도 맞나
getLoginedUser()
}
else {
alert("로그인 후 이용하세요")
window.location.href = '/login'
}
}, [])
return (
<div>
<Menu />
<Container>
<Row><h1>ProfilePage</h1></Row>
<Row><h2>{user.username} 환영합니다 !</h2></Row>
</Container>
<Container className="mt-5 shadow w-75">
<Row>
<Col sm={4}>
<Row>
<div className="d-flex justify-content-center mb-3" id="defaultImg">
<Image src={userimg} width="300px" roundedCircle />
</div>
</Row>
<Row>
<Form className="d-flex justify-content-center">
<Form.Group>
<div id="image_container"></div>
<Form.File label="프로필 사진 변경" accept="image/*" onChange={setThumbnail} />
</Form.Group>
</Form>
</Row>
<Row className="d-flex justify-content-center">
<Dropdown>
<Dropdown.Toggle variant='success' id='dropdown-basic'>
프로필 사진 선택
</Dropdown.Toggle>
<Dropdown.Menu>
<Dropdown.Item as='button'>홈으로</Dropdown.Item>
<Dropdown.Item href='/'>라이언</Dropdown.Item>
<Dropdown.Item href='/'>어피치</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
</Row>
</Col>
<Col sm={8}>
<Row className="m-3 justify-content-flex-start" style={{ fontWeight: "bold", fontSize: "x-large" }}>
<Col sm={2.5}>이름 :</Col>
<Col sm={8}>{user.username}</Col>
</Row>
<Row className="m-3 justify-content-flex-start" id="nickname">
<Form className="d-flex" onSubmit={handleSubmit} style={{ fontWeight: "bold", fontSize: "x-large" }}>
<Row>
<Col>별명 :</Col>
<Col hidden={!hidden}>
{user.nickname}
</Col>
<Col hidden={hidden}>
<Form.Control defaultValue={user.nickname} style={{width : "110%"}} onChange={handleChange} />
</Col>
<Col>
<Button className="ml-3 d-flex justify-content-end" variant="outline-primary" size="sm" type='submit'>수정</Button>
</Col>
</Row>
</Form>
</Row>
<Row className="m-3" style={{ fontWeight: "bold", fontSize: "x-large" }}>
<Col sm={2.5}>이메일 : </Col>
<Col sm={8}>{user.email}</Col>
</Row>
<Row className='justify-content-center'>
<Form>
<Button variant="outline-success" size="sm" className="mr-4" onClick={handleNicksave}>저장</Button>
<Link to='/'>
<Button variant="outline-success" size="sm" className="ml-4" > 화면으로</Button>
</Link>
</Form>
</Row>
</Col>
</Row>
</Container>
<Container className="d-flex justify-content-center">
<div className="mt-5 shadow w-75">
<h1 className="text-center mt-4 ml-5 mr-5 mb-3">Profile Page</h1>
<h4 className="text-center mb-5">{user.username} 환영합니다 !</h4>
<div className="d-flex justify-content-center mb-3" id="defaultImg">
<Image src={userimg} width="300px" roundedCircle />
</div>
<Row className="d-flex justify-content-center">
<Form className="d-flex justify-content-center">
<Form.Group>
<div id="image_container"></div>
<Form.File label="프로필 사진 변경" accept="image/*" onChange={setThumbnail} />
</Form.Group>
</Form>
</Row>
<Row className="d-flex justify-content-center">
<Dropdown>
<Dropdown.Toggle variant='success' id='dropdown-basic'>
프로필 사진 선택
</Dropdown.Toggle>
<Dropdown.Menu>
<Dropdown.Item as='button'>홈으로</Dropdown.Item>
<Dropdown.Item href='/'>라이언</Dropdown.Item>
<Dropdown.Item href='/'>어피치</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
</Row>
{/* <Carousel className="d-flex justify-content-center" style={{ width: "300px", height: "300px" }}>
<Carousel.Item className="d-flex justify-content-center">
<Image
className="d-block w-100"
src={img1}
/>
<Carousel.Caption>
<p style={{color : 'black'}}>펭수입니다.</p>
</Carousel.Caption>
</Carousel.Item>
<Carousel.Item>
<Image
className="d-block w-100"
src={img2}
/>
<Carousel.Caption>
<p>라이언입니다.</p>
</Carousel.Caption>
</Carousel.Item>
<Carousel.Item>
<Image
className="d-block w-100"
src={img3}
/>
<Carousel.Caption>
<p>어피치 입니다.</p>
</Carousel.Caption>
</Carousel.Item>
</Carousel> */}
<div className="text-center">
<div className="m-3" style={{ fontWeight: "bold", fontSize: "x-large" }}>이름 : {user.username}</div>
<div className="m-3" id="nickname">
<Form className="d-flex justify-content-center" onSubmit={handleSubmit} style={{ fontWeight: "bold", fontSize: "x-large" }}>
별명 :
<div hidden={!hidden}>
{user.nickname}
</div>
<Form.Control defaultValue={user.nickname} style={{ width: "40%" }} size="sm" onChange={handleChange} hidden={hidden} />
<Button className="ml-3" variant="outline-primary" size="sm" type='submit'>수정</Button>
</Form>
</div>
<div className="m-3" style={{ fontWeight: "bold", fontSize: "x-large" }}>이메일 : {user.email}</div>
</div>
<div className="text-center m-5">
<Form>
<Button variant="outline-success" size="sm" className="mr-4" onClick={handleNicksave}>저장</Button>
<Link to='/'>
<Button variant="outline-success" size="sm" className="ml-4" > 화면으로</Button>
</Link>
</Form>
</div>
</div>
</Container>
</div>
)
}
// export default ProfilePage
\ No newline at end of file
export default ProfilePage
client/src/Pages/user_default.svg
\ No newline at end of file
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- 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 ReactDOM from 'react-dom';
import 'bootstrap/dist/css/bootstrap.min.css';
import './index.css';
// import App from './App';
import SignUpPage from './Pages/SignUpPage';
......
import axios from "axios"
//자동으로 localstorage에 login이 생성됨
export function handleLogin(userId) {
localStorage.setItem('user', userId)
// localStorage.setItem('user', JSON.stringify({email: props.email}))
export function handleLogin(props) {
localStorage.setItem('user', props.email)
}
export async function handleLogout() {
localStorage.removeItem('user')
......
......@@ -5,8 +5,8 @@
"main": "index.js",
"type": "module",
"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": {
"type": "git",
......@@ -21,7 +21,6 @@
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.11.9",
"nanoid": "^3.1.20",
"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 isLength from 'validator/lib/isLength.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붙여주기!!
//sign validation해야됨
......@@ -12,13 +14,13 @@ const signup = async (req, res) => {
console.log(username, nickname, email, password)
try {
if (!isLength(username, {min: 3, max: 10})){
if (!isLength(username, { min: 3, max: 10 })) {
//이범위를 벗어나면 error발생
return res.status(422).send('이름은 3-10자 사이입니다')
//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자 사이입니다.')
} else if (!isLength(password, {min: 6})) {
} else if (!isLength(password, { min: 6 })) {
return res.status(422).send('비밀번호는 6자 이상입니다.')
} else if (!isEmail(email)) {
return res.status(422).send('유효하지 않은 이메일 형식입니다')
......@@ -36,8 +38,8 @@ const signup = async (req, res) => {
// }
// 기존의 email이 있으면 나오는 error (unique)
const user = await User.findOne({email})
if(user) {
const user = await User.findOne({ email })
if (user) {
return res.status(422).send(`${email}이 이미 사용중입니다.`)
}
......@@ -61,42 +63,32 @@ const signup = async (req, res) => {
console.log(error)
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 {
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)
} catch (error) {
alert('올바르지 못한 접근입니다.')
}
}
// const loginNavbar = (req, res) => {
// res.json(req.login)
// }
// const userById = async (req, res, next, id) => {
// try {
// 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('사용자 아이디 검색 실패')
// }
// }
const changenick = async (req, res) => {
try {
const newnick = req.body.nickname
await User.update({ 'username': req.body.username }, { 'nickname': newnick })
} catch (error) {
alert('올바르지 못한 접근입니다.')
}
}
export default { signup ,loginNavbar }
export default { signup, hello, logineduser, changenick }
// {} : 객체로 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