Commit 57b2d398 authored by Ha YeaJin's avatar Ha YeaJin
Browse files

login, signup css 끝. noticePage db 연결

parent f10c71ec
......@@ -8,6 +8,7 @@ const indexRouter = require('./routes/index');
const usersRouter = require('./routes/users');
const loginRouter = require('./routes/login');
const reserveRouter = require('./routes/reserves');
const noticeRouter = require('./routes/notices');
const connect = require('./schemas');
const app = express();
......@@ -33,6 +34,7 @@ app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/login', loginRouter);
app.use('/reserves', reserveRouter);
app.use('/notices', noticeRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
......
......@@ -4,7 +4,7 @@ import styled from 'styled-components';
const Nav = styled.nav`
background-color: #7B031D;
max-height : 50px;
height: 6vh;
a {
color: #ffffff;
......@@ -35,6 +35,7 @@ function Menu() {
<Link to="/notice" className="nav-link">공지사항</Link>
</li>
<li className="nav-item">
{console.log(name)}
<Link to="/home" className="nav-link">대관 현황</Link>
</li>
<li className="nav-item">
......
import React, { useState, useEffect, useRef } from 'react';
import React, { useState, useEffect } from 'react';
import styled from 'styled-components';
import { Link, Redirect } from 'react-router-dom';
import { Formik } from 'formik';
......@@ -18,7 +18,7 @@ const Asd = styled.div`
&.mobile {
height : 20vh;
display : flex;
padding:0;
}
& .mob-head {
......@@ -26,14 +26,13 @@ const Asd = styled.div`
flex-direction: row;
height : 100%;
width: 100%;
justify-content: center;
align-content: center;
justify-content: space-evenly;
}
& .mob-img {
max-width:100%;
max-height:100%;
}
max-width: 30vw;
}
`
const Asdf = styled.div`
......@@ -45,7 +44,6 @@ const Asdf = styled.div`
&.mob-formik {
height : 80vh;
width: 100%;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
......@@ -59,12 +57,16 @@ const Asdf = styled.div`
}
& .mobb {
height: 30vh;
height: 35vh;
display: flex;
flex-direction: column;
justify-content: space-around;
}
& .webb {
flex-direction: column;
}
& .qwer {
display: flex;
justify-content: space-between;
......@@ -77,8 +79,8 @@ const Asdf = styled.div`
width: 80%;
justify-content: space-between;
align-content: space-around;
display: flex;
flex-direction: column;
display: flex;
}
& .mob-input-form {
......@@ -102,16 +104,16 @@ function Login() {
return <Redirect to="/home" />;
}
return (
<div className="row vw-100 vh-100">
<Asd className={"col-md-4 px-0" + (mobile ? " mobile" : " web")}>
<div className={mobile ? " mob-head" : ""}>
<img className={mobile ? " mob-img" : "img-fluid"} src={Logo} />
<div className="d-flex justify-content-center">
<h1 className="font-weight-bold text-white align-self-center">고려대학교<br />대관 서비스</h1>
<div className="row vw-100 vh-100 m-0">
<Asd className={"col-md-4 col-12" + (mobile ? " mobile" : " web")}>
<div className={mobile ? "mob-head" : ""}>
<img className={mobile ? "mob-img" : "img-fluid"} src={Logo} />
<div className={"d-flex " + (mobile ? "align-items-center" : "justify-content-center")}>
<h1 className="font-weight-bold text-white">고려대학교<br />대관 서비스</h1>
</div>
</div>
</Asd>
<Asdf className={"col-md-8 col-12" + (mobile ? " mob-formik" : " web-formik")}>
<Asdf className={"col-md-8 col-12" + (mobile ? " mob-formik p-0" : " web-formik")}>
<Formik
initialValues={{ id: '', password: '' }}
validationSchema={Yup.object({
......@@ -131,6 +133,7 @@ function Login() {
localStorage.setItem('token', res.data.token);
localStorage.setItem('id', res.data.users._id);
localStorage.setItem('name', res.data.users.name);
setState(true);
})
.catch(err => {
......@@ -149,10 +152,10 @@ function Login() {
getFieldProps, // contain values, handleChange, handleBlur
isSubmitting,
}) => (
<form onSubmit={handleSubmit} className={mobile ? "w-90 h-50vh" : ""}>
<form onSubmit={handleSubmit} className={mobile ? "w-75 h-50vh" : "d-flex webb"}>
<div className={mobile ? "mobb" : "qwer"}>
<div className={(mobile ? "mob-" : "web-") + "input-form"}>
<div className={"form-group m-0" + (mobile ? " mb-3" : "")}>
<div className={"form-group m-0" + (mobile ? " mb-2" : "")}>
<input
className={(touched.id && errors.id ? 'form-control is-invalid' : "form-control")}
type="number"
......@@ -171,17 +174,15 @@ function Login() {
/>
</div>
</div>
<button type="submit" className={"btn btn-dark" + (mobile ? " w-100" : " w-20")} disabled={isSubmitting}>
Login
</button>
<button><Link to="/home"></Link></button>
<div></div>
<Link to="/find">비밀번호를 잊으셨나요?</Link>
<div></div>
<Link to="/signup">회원이 아니신가요?</Link>
<button type="submit" className={"btn btn-dark" + (mobile ? " w-100" : " w-20")} disabled={isSubmitting}> Login </button>
</div>
<div><Link to="/find">비밀번호를 잊으셨나요?</Link></div>
<div><Link to="/signup">회원이 아니신가요?</Link></div>
</form>
)}
</Formik>
</Asdf>
</div >
......
import React, { useState, useEffect } from 'react';
import Menu from '../Components/Menu';
import axios from 'axios';
function Notice() {
const [notices, setNotices] = useState([]);
useEffect(() => {
getNotice();
}, []);
function getNotice() {
axios.get(`/notices`)
.then(res => {
if (res.status !== 201) {
alert(res.data.error);
}
console.log(res.data);
setNotices(res.data);
})
.catch(err => {
alert(err.error)
});
}
return (
<div>
<Menu />
<div className="container">notice
<div className="container">
<div className="row">
<div className="col-12">
{notices.map((notice) => <div>{notice.notice_title}</div>)}
</div>
</div>
</div>
</div>
)
......
......@@ -4,139 +4,183 @@ import * as Yup from 'yup';
import axios from 'axios';
import 'bootstrap/dist/css/bootstrap.css';
import { Link, Redirect } from 'react-router-dom';
import styled from 'styled-components';
const Nav = styled.nav`
background-color: #7B031D;
height: 10vh;
a {
color: #ffffff;
}
`
const Wow = styled.div`
height: 90vh;
& #reCheck::after {
content: '비밀번호를 다시 입력하세요';
}
& #reCheck:not(.right) {
content: '비밀번호가 다릅니다.';
color: red;
}
& .asd {
display: flex;
flex-direction: column;
}
`
function Signup() {
const [state, setState] = useState(false);
const [checkPw, setCheckPw] = useState(true);
if (state) {
return <Redirect to="/login" />;
}
return (
<div className="d-flex flex-column justify-content-between vh-100">
<Formik
initialValues={{ name: '', id: '', password: '', password2: '', question: '', answer: '' }}
validationSchema={Yup.object({
name: Yup.string()
.required('이름을 입력해주세요.'),
id: Yup.string()
.required('학번을 입력해주세요.'),
password: Yup.string()
.required('비밀번호를 입력해주세요.')
.min(8, '8자 이상 입력해주세요.'),
password2: Yup.string()
.required('비밀번호를 다시 입력해주세요.')
.min(8, '8자 이상 입력해주세요.')
.oneOf([Yup.ref("password"), null], '비밀번호가 일치하지 않습니다.'),
answer: Yup.string()
.required('답변을 입력해주세요.'),
})}
onSubmit={(values, { setSubmitting }) => {
axios({
method: 'post',
url: '/users',
data: values,
}).then(res => {
if (res.status === 404) return alert(res.data.error)
alert("회원가입이 완료되었습니다!")
setState(true);
})
.catch(err => {
alert(err.error)
});
setTimeout(() => {
setSubmitting(false);
}, 400); // finish the cycle in handler
}}
>
{({
errors,
touched,
handleSubmit,
getFieldProps, // contain values, handleChange, handleBlur
isSubmitting,
}) => (
<div className="row justify-content-center align-items-center">
<form onSubmit={handleSubmit} className="col-sm-3">
<div className="form-group mb-4">
<input
className={(touched.name && errors.name ? 'form-control is-invalid' : "form-control")}
type="text"
name="name"
{...getFieldProps('name')}
placeholder="이름" />
{touched.name && errors.name ? (
<div className="invalid-feedback text-left">{errors.name}</div>
) : null}
</div>
<div className="form-group mb-4">
<input
className={(touched.id && errors.id ? 'form-control is-invalid' : "form-control")}
type="text"
name="id"
{...getFieldProps('id')}
placeholder="학번/교번"
/>
{touched.id && errors.id ? (
<div className="invalid-feedback text-left">{errors.id}</div>
) : null}
</div>
<div className="form-group mb-4">
<input
className={(touched.password && errors.password ? 'form-control is-invalid' : "form-control")}
type="password"
name="password"
{...getFieldProps('password')}
placeholder="비밀번호"
/>
{touched.password && errors.password ? (
<div className="invalid-feedback text-left">{errors.password}</div>
) : null}
</div>
<div className="form-group mb-4">
<input
className={(touched.password2 && errors.password2 ? 'form-control is-invalid' : "form-control")}
type="password"
name="password2"
{...getFieldProps('password2')}
placeholder="비밀번호 확인"
/>
{touched.password2 && errors.password2 ? (
<div className="invalid-feedback text-left">{errors.password2}</div>
) : null}
</div>
<div className="form-group mb-4">
<label>본인 확인 질문</label>
<Field as="select" name="question">
<option value="">질문을 선택하세요</option>
<option value="life">자신의 인생 좌우명은?</option>
<option value="school">자신이 다녔던 초등학교의 이름은?</option>
<option value="place">기억에 남는 추억의 장소는?</option>
</Field>
</div>
<div className="form-group mb-4">
<input
className={(touched.answer && errors.answer ? 'form-control is-invalid' : "form-control")}
type="text"
name="answer"
{...getFieldProps('answer')}
placeholder="Input answer" />
{touched.answer && errors.answer ? (
<div className="invalid-feedback text-left">{errors.answer}</div>
) : null}
</div>
<button type="submit" className="btn btn-dark" disabled={isSubmitting}>
Sign Up
</button>
<button class="btn btn-light"><Link to="/login">로그인</Link></button>
<button class="btn btn-light"><Link to="/"></Link></button>
</form>
</div>
)}
</Formik>
</div>
<div className="vh-100">
<Nav className="navbar sticky-top navbar-expand-md">
<a class="navbar-brand" href="#">회원가입</a>
</Nav>
<div className="container-fluid">
<Wow className="row justify-content-center rrooww">
<div className="col-md-4 col-12 d-flex align-items-center h-100">
<Formik
initialValues={{ name: '', id: '', password: '', password2: '', question: '', answer: '' }}
validationSchema={Yup.object({
name: Yup.string()
.required('이름을 입력해주세요.'),
id: Yup.string()
.required('학번을 입력해주세요.'),
password: Yup.string()
.required('비밀번호를 입력해주세요.')
.min(8, '8자 이상 입력해주세요.'),
password2: Yup.string()
.required('비밀번호를 다시 입력해주세요.')
.min(8, '8자 이상 입력해주세요.')
.oneOf([Yup.ref("password"), null], '비밀번호가 일치하지 않습니다.'),
answer: Yup.string()
.required('답변을 입력해주세요.'),
})}
onSubmit={(values, { setSubmitting }) => {
axios({
method: 'post',
url: '/users',
data: values,
}).then(res => {
if (res.status === 404) return alert(res.data.error)
alert("회원가입이 완료되었습니다!")
setState(true);
})
.catch(err => {
alert(err.error)
});
setTimeout(() => {
setSubmitting(false);
}, 400); // finish the cycle in handler
}}
>
{({
errors,
touched,
handleSubmit,
getFieldProps, // contain values, handleChange, handleBlur
isSubmitting,
}) => (
< form onSubmit={handleSubmit} className="asd">
{/* col-sm-3 */}
<div className="form-group ">
{/* mb-4 */}
<div className={touched.name && errors.name ? "text-danger" : ""}>이름을 입력하세요</div>
<input
className={(touched.name && errors.name ? 'form-control is-invalid' : "form-control")}
type="text"
name="name"
{...getFieldProps('name')}
placeholder="이름" />
</div>
<div className="form-group">
{/* mb-4 */}
<div className={touched.id && errors.id ? "text-danger" : ""}>학번을 입력하세요</div>
<input
className={(touched.id && errors.id ? 'form-control is-invalid' : "form-control")}
type="text"
name="id"
{...getFieldProps('id')}
placeholder="학번/교번"
/>
{/* {touched.id && errors.id ? (
<div className="invalid-feedback text-left">{errors.id}</div>
) : null} */}
</div>
<div className="form-group">
{/* mb-4 */}
<div className={touched.password && errors.password ? "text-danger" : ""}>비밀번호를 입력하세요(8자리 이상)</div>
<input
className={(touched.password && errors.password ? 'form-control is-invalid' : "form-control")}
type="password"
name="password"
{...getFieldProps('password')}
placeholder="비밀번호"
/>
{/* {touched.password && errors.password ? (
<div className="invalid-feedback text-left">{errors.password}</div>
) : null} */}
</div>
<div className="form-group">
{/* mb-4 */}
{touched.password2 && errors.password2 ? setCheckPw(false) : null}
<div id="reCheck" className={checkPw ? "right" : "err"}></div>
<input
className={touched.password2 && errors.password2 ? "form-control is-invalid" : "form-control"}
type="password"
name="password2"
{...getFieldProps('password2')}
placeholder="비밀번호 확인"
/>
</div>
<div className="form-group">
{/* mb-4 */}
<label>본인 확인 질문</label>
<Field as="select" name="question">
<option value="">질문을 선택하세요</option>
<option value="life">자신의 인생 좌우명은?</option>
<option value="school">자신이 다녔던 초등학교의 이름은?</option>
<option value="place">기억에 남는 추억의 장소는?</option>
</Field>
</div>
<div className="form-group">
{/* mb-4 */}
<div className={touched.answer && errors.answer ? "text-danger" : ""}>답변을 입력해주세요.</div>
<input
className={(touched.answer && errors.answer ? 'form-control is-invalid' : "form-control")}
type="text"
name="answer"
{...getFieldProps('answer')}
placeholder="Input answer" />
</div>
<button type="submit" className="btn btn-dark" disabled={isSubmitting}>회원가입</button>
<button class="btn btn-light"><Link to="/login">로그인</Link></button>
<button class="btn btn-light"><Link to="/"></Link></button>
</form>
)}
</Formik>
</div>
</Wow>
</div>
</div >
);
}
......
const express = require('express');
const Notice = require('../schemas/notice');
const router = express.Router();
router.get('/', function (req, res, next) {
Notice.find({}).sort({ post_date: -1 })
.then((notices) => {
res.json(notices);
})
.catch((err) => {
console.error(err);
next(err);
});
});
module.exports = router;
\ No newline at end of file
const mongoose = require('mongoose');
const { Schema } = mongoose;
const noticeSchema = new Schema({
notice_img: {
type: Array,
},
notice_title: {
type: String,
required: true,
},
notice_author: {
type: String,
// default: "나야나"
required: true,
},
post_date: {
type: Date,
default: Date.now,
required: true,
},
notice_content: {
type: String,
required: true,
},
});
module.exports = mongoose.model('Notice', noticeSchema);
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