Commit c61f522c authored by kusang96's avatar kusang96
Browse files

merge into jaeyeon

parents a5f0af34 791c9a51
BROWSER=none
PORT=4000
MONGO_URI=mongodb://localhost/
\ No newline at end of file
MONGO_URI=mongodb://localhost/shopping-mall
\ No newline at end of file
......@@ -38,5 +38,6 @@
"last 1 firefox version",
"last 1 safari version"
]
}
},
"proxy":"http://localhost:3001"
}
......@@ -7,6 +7,7 @@ import option from '../option.svg';
function MainNav() {
function handleClick() {
alert('로그아웃이 완료되었습니다.')
window.location.href="/home"
}
return (
......
......@@ -22,7 +22,7 @@ function SubNav() {
}
return (
<Navbar sticky="top" className="flex-nowrap" style={{ top: "62px", paddingTop: "0", paddingBottom: "0", backgroundColor: "#fff" }}>
<Navbar sticky="top" className="flex-nowrap" style={{ top: "62px", paddingTop: "0", paddingBottom: "0", backgroundColor: "#fff", overflowX: "auto" }}>
<style type="text/css">
{`
.nav-link, .nav-link:hover, .nav-link:active {
......
......@@ -10,8 +10,7 @@ function Login(){
const handleSubmit=(e)=>{
const form =e.currentTarget;
console.log(form)
if(form.checkValidity() === false){
if(form.checkValidity() === false){ //checkValidity 는 입력 요소에 유효한 데이터가 포함되어 있는지 확인
e.preventDefault();
e.stopPropagation();
}
......
......@@ -2,78 +2,61 @@ import React, { useState, useEffect, useRef } from 'react';
import { Redirect } from 'react-router-dom';
import Nav1 from '../Components/MainNav';
import Nav2 from '../Components/SubNav';
import { Form, Col, Container, Button, Row } from 'react-bootstrap';
import DaumPostcode from "react-daum-postcode";
import { Form, Col, Container, Button, Row, Alert } from 'react-bootstrap'
import FormCheckInput from 'react-bootstrap/esm/FormCheckInput';
const INIT_USER = {
name: '',
number: '',
id: '',
password: '',
password2: '',
tel: ''
}
function Signup() {
const [address,setAddress] =useState("")
const handleComplete = (data) => {
let fullAddress = data.address;
let extraAddress = "";
console.log(data)
if (data.addressType === "R") {
if (data.bname !== "") {
extraAddress += data.bname;
console.log(extraAddress)
}
if (data.buildingName !== "") {
extraAddress +=
extraAddress !== "" ? `, ${data.buildingName}` : data.buildingName;
}
fullAddress += extraAddress !== "" ? ` (${extraAddress})` : "";
}
setAddress({full: fullAddress, zone: data.zonecode});
console.log(fullAddress);
}
const Postcode = () => {
return (
<DaumPostcode
onComplete={handleComplete}
/>
);
}
const [post, setPost] = useState([]);
function postClick() {
if (post.length !== 0) {
setPost([])
} else {
setPost(
<div>
<DaumPostcode style={postCodeStyle} onComplete={handleComplete} />
</div>
)
const [user, setUser] = useState(true)
//const [disabled, setDisabled] = useState(true)
const [error, setError] = useState('')
//useEffect(() => {
// const isUser = Object.values(user).every(el => Boolean(el))
// isUser ? setDisabled(false) : setDisabled(true)
//}, user)
function handleChange(event) {
const { name, value } = event.target
setUser({ ...user, [name]: value })
}
}
const postCodeStyle = {
position: "absolute",
width: "400px",
height: "500px",
padding: "7px",
};
const [validated, setValidated] = useState(false);
const handleSubmit = (e) => {
const form = e.currentTarget;
async function handleSubmit(event) {
event.preventDefault()
const form = event.currentTarget;
console.log(form)
if (form.checkValidity() === false) {
e.preventDefault();
e.stopPropagation();
event.preventDefault();
event.stopPropagation();
}
setValidated(true);
console.log(user)
try {
setError('')
const response = await fetch('/api/users/signup', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(user)
})
const data = await response.json()
console.log(data)
} catch (error) {
console.log(error)
setError('다시 시도하세요.')
}
}
return (
......@@ -81,32 +64,50 @@ function Signup() {
<Nav1 />
<Nav2 />
<Container className="my-5">
{error && <Alert variant='danger'>
{error}
</Alert>}
<Row className="justify-content-center">
<Col md={6} xs={10} className="border" style={{ background: '#F7F3F3' }}>
<h2 className="text-center mt-5">Sign Up</h2>
<Form noValidate validated={validated} onSubmit={handleSubmit} className="p-5">
<Form
noValidate validated={validated}
onSubmit={handleSubmit}
className="p-5">
<Form.Group controlId="formBasicName">
<Form.Row>
<Form.Label for="name"> </Form.Label>
<Col>
<Form.Control
required
type="text" id="name"
size="sm" placeholder="" className="mx-sm-3">
</Form.Control>
<Col sm={4} xs={6} as={Form.Label} for="id"> </Col>
<Col sm={8} xs={12} as={Form.Control}
required type="text"
name="name"
placeholder="Name"
style={{ width: '160px' }}
value={user.name}
onChange={handleChange} />
<Form.Control.Feedback type="invalid">이름을 입력하세요. </Form.Control.Feedback>
</Col>
</Form.Row>
</Form.Group>
<Form.Group controlId="formBasicNumber">
<Form.Row>
<Form.Label for="number">주민등록번호</Form.Label>
<Col as={Row}>
<Form.Control required type="text" id="number1" size="sm" maxlength="6" className="mx-sm-3" style={{ width: '120px' }}></Form.Control>
<Col sm={4} xs={6} as={Form.Label} for="number">주민등록번호</Col>
<Col as={Row} sm={8} xs={10} >
<Form.Control
required type="text"
name="number1"
maxlength="6"
className="mx-2" style={{ width: '17 0px' }}
value={user.number1}
onChange={handleChange}>
</Form.Control>
-
<Form.Control required type="text" id="number2" size="sm" maxlength="1" className="mx-sm-3" style={{ width: '25px' }}></Form.Control>
<Form.Control
required type="text"
name="number2"
maxlength="1" className="mx-3"
style={{ width: '50px' }}
value={user.number2}
onChange={handleChange}>
</Form.Control>
******
<Form.Control.Feedback type="invalid">주민등록번호를 입력하세요.</Form.Control.Feedback>
</Col>
......@@ -114,64 +115,66 @@ function Signup() {
</Form.Group>
<Form.Group controlId="formBasicId">
<Form.Row>
<Form.Label for="id">아이디</Form.Label>
<Col>
<Form.Control required type="text" id="id" size="sm" placeholder="ID" className="mx-sm-3"></Form.Control>
<Col sm={4} xs={6} as={Form.Label} for="id">아이디</Col>
<Col sm={8} xs={12} as={Form.Control}
required
type="text"
name="id"
placeholder="ID"
style={{ width: '160px' }}
value={user.id}
onChange={handleChange} />
<Form.Control.Feedback type="invalid"> 아이디를 입력하세요.</Form.Control.Feedback>
</Col>
</Form.Row>
</Form.Group>
<Form.Group controlId="formBasicPassword">
<Form.Row>
<Form.Label for="password">비밀번호</Form.Label>
<Col>
<Form.Control required type="password" id="password" size="sm" placeholder="Password" aria-describedby="passwordHelpBlock" className="mx-sm-3"></Form.Control>
<Form.Text id="password" muted> 8-15자로 입력해주세요.</Form.Text>
<Form.Control.Feedback type="invalid"> 비밀번호를 입력하세요.
<Col sm={4} xs={6} as={Form.Label} for="password">비밀번호</Col>
<Col sm={8} xs={12} as={Form.Control}
type="password"
name="password"
placeholder="Password"
style={{ width: '160px' }}
value={user.password}
required
onChange={handleChange} />
<Form.Control.Feedback className="text-center" type="invalid">
비밀번호를 입력하세요.
</Form.Control.Feedback>
</Col>
</Form.Row>
</Form.Group>
<Form.Group controlId="formBasicPassword2">
<Form.Row>
<Form.Label for="password2">비밀번호 확인</Form.Label>
<Col>
<Form.Control required type="password" id="password2" size="sm" placeholder="" className="mx-sm-3"></Form.Control>
<Col sm={4} xs={6} as={Form.Label} for="password">비밀번호 확인</Col>
<Col sm={8} xs={12} as={Form.Control}
type="password"
name="password2"
placeholder="Password"
style={{ width: '160px' }}
value={user.password2}
required
onChange={handleChange} />
<Form.Control.Feedback type="invalid"> 비밀번호를 한번 입력하세요.
</Form.Control.Feedback>
</Col>
</Form.Row>
</Form.Group>
<Form.Group controlId="formBasicTel">
<Form.Row>
<Form.Label for="tel">휴대전화</Form.Label>
<Col>
<Form.Control required type="text" id="tel" size="sm" placeholder="" className="mx-sm-3"></Form.Control>
<Col sm={4} xs={6} as={Form.Label} for="tel">휴대전화</Col>
<Col sm={8} xs={12} as={Form.Control}
required
type="text"
name="tel"
size="sm" style={{ width: '160px' }}
value={user.tel}
onChange={handleChange} />
<Form.Control.Feedback type="invalid"> 휴대전화를 입력하세요. </Form.Control.Feedback>
</Col>
</Form.Row>
</Form.Group>
<Form.Group controlId="formBasicAdd">
<Form.Row>
{console.log("address=", address)}
<Form.Label className="mx-3"> </Form.Label>
<Form.Control required type="text" id="add" size="sm " style={{ width: '120px' }} value={address.zone} disabled={(address.zone == null) ? false : true} ></Form.Control>
<Button size="sm" style={{ background: '#91877F', borderColor: '#91877F' }} className="mx-3" type="button" onClick={postClick}>주소 찾기</Button>
{post}
<Form.Control required type="text" id="add" size="sm " value={address.full} disabled={(address.zone == null) ? false : true} className="mx-3"style={{width:'330px'}}></Form.Control>
<Form.Control required type="text" id="add2" size="sm" placeholder="상세주소" className="mx-sm-3"></Form.Control>
<Form.Control.Feedback type="invalid" > 상세 주소를 입력하세요. </Form.Control.Feedback>
</Form.Row>
</Form.Group>
<Button style={{ background: '#91877F', borderColor: '#91877F' }} type="submit" block>Sign Up</Button>
<Button
style={{ background: '#91877F', borderColor: '#91877F' }} type="submit" block>
Sign Up
</Button>
</Form>
</Col>
</Row>
......
......@@ -33,7 +33,7 @@ app.use(express.json());
// app.listen(port, () => console.log(port));
app.listen(3001, () => console.log('Listenning'));
app.use(userRouter)
app.use('/api/users',userRouter)
// catch 404 and forward to error handler
// app.use(function(req, res, next) {
......
......@@ -2,7 +2,7 @@ const config = {
env: process.env.NODEENV || 'development',
port: process.env.PORT || 3001,
jwtSecret: process.env.JWT_SECRET || 'My_Secret_Key',
mongoDbUri: process.env.MONGEDB_URI || 'mongodb://localhost/'
mongoDbUri: process.env.MONGEDB_URI || 'mongodb://localhost/shopping-mall'
}
export default config
\ No newline at end of file
import User from "../models/User.js";
import isLength from 'validator/lib/isLength.js'
const signup = async (req, res) => {
const { name, email, password } = req.body
console.log(req.body)
console.log('req.body.name=', req.body.name)
const { name, number1, number2, id, password, password2, tel } = req.body
try {
if(!isLength(password,{min:8, max:15})){
return res.status(422).json({message: '비밀번호는 8-15자리로 입력해주세요.'})
}
const newUser = await new User ({
name,
email,
password
number1,
number2,
id,
password,
password2,
tel
}).save()
console.log(newUser)
res.json(newUser)
} catch (error) {
console.log(error)
res.status(500).send('죄송합니다. 다시 입력해 주십시오.')
res.status(500).json({message:'죄송합니다. 다시 입력해 주십시오.'})
}
}
......
......@@ -5,9 +5,9 @@ const { String } = mongoose.Schema.Types
const UserSchema = new mongoose.Schema({
name: {
type: String,
required: true,
required: true, // 꼭 필요한 값
},
email: {
id: {
type: String,
required: true,
unique: true,
......@@ -15,7 +15,21 @@ const UserSchema = new mongoose.Schema({
password: {
type: String,
required: true,
select: true,
},
number1:{
type:String,
required:true,
unique:true
},
number2:{
type:String,
required:true,
unique:true
},
tel:{
type:String,
required:true,
unique:true
},
role: {
type: String,
......
......@@ -5,6 +5,7 @@
"type": "module",
"main": "app.js",
"scripts": {
"dev": "nodemon app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
......
......@@ -3,7 +3,7 @@ import userCtrl from '../controllers/user.controller.js';
const router = express.Router()
router.route('/api/users/signup')
router.route('/signup')
.post(userCtrl.signup)
.get(userCtrl.hello)
......
......@@ -4,9 +4,9 @@ import config from '../config.js';
const connection = {}
async function connectDb() {
// if (connection.isConnection) {
// return
// }
if (connection.isConnection) {
return
}
const db = await mongoose.connect(config.mongoDbUri, {
useNewUrlParser: true,
......
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