Commit 7de8fc28 authored by Kim, Subin's avatar Kim, Subin
Browse files

교수님 여기요! 11.06.04:00

parent 3ed89fa4
This source diff could not be displayed because it is too large. You can view the blob instead.
// import React from 'react';
// import { Redirect, Route } from "react-router-dom";
// export const AdminPrivateRoute = ({ component: Component, ...rest }) => (
// <Route
// {...rest}
// render={props =>
// (localStorage.getItem("token") !==null) ? (
// <Component {...props} />
// ) : (
// <Redirect to={{
// pathname: "/login",
// state: {match: props.location}
// }} />
// )
// }
// />
// )
\ No newline at end of file
...@@ -73,7 +73,7 @@ function Notice({ card_id, card_index, title, date, content, admin }) { ...@@ -73,7 +73,7 @@ function Notice({ card_id, card_index, title, date, content, admin }) {
})} })}
{admin === "admin" ? ( {admin === "admin" ? (
<div className="d-flex justify-content-end"> <div className="d-flex justify-content-end">
<Button variant="primary" size="sm" as={Link} to={`/write/revise/${card_id}`}>수정</Button> <Button variant="primary" size="sm" as={Link} to={`/modify/${card_id}`}>수정</Button>
<Button variant="danger" size="sm" onClick={() => remove(card_id)}>삭제</Button> <Button variant="danger" size="sm" onClick={() => remove(card_id)}>삭제</Button>
</div>) : null} </div>) : null}
</Text> </Text>
......
...@@ -31,7 +31,6 @@ function Menu() { ...@@ -31,7 +31,6 @@ function Menu() {
axios.get(`/users/${localStorage.getItem('_id')}`, { axios.get(`/users/${localStorage.getItem('_id')}`, {
headers: { authorization: localStorage.getItem('token') }, headers: { authorization: localStorage.getItem('token') },
}).then(res => { }).then(res => {
console.log(res.data)
if (res.data.role == "admin") { if (res.data.role == "admin") {
setUser(res.data) setUser(res.data)
} }
......
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import Menu from '../Components/Menu'; import Menu from '../Components/Menu';
import axios from 'axios'; import axios from 'axios';
import { Link, Redirect } from 'react-router-dom'; import { Redirect } from 'react-router-dom';
import { Container, Table } from 'react-bootstrap'; import { Container, Table } from 'react-bootstrap';
import styled from 'styled-components'; import styled from 'styled-components';
...@@ -20,7 +20,6 @@ const Ta = styled(Table)` ...@@ -20,7 +20,6 @@ const Ta = styled(Table)`
align-items: center; align-items: center;
width: 70px; width: 70px;
}; };
` `
function ACheck(props) { function ACheck(props) {
...@@ -40,7 +39,6 @@ function ACheck(props) { ...@@ -40,7 +39,6 @@ function ACheck(props) {
alert(res.data.error) alert(res.data.error)
setState(true); setState(true);
} }
console.log(res.data);
setReserve(res.data); setReserve(res.data);
}) })
.catch(err => { .catch(err => {
...@@ -81,7 +79,6 @@ function ACheck(props) { ...@@ -81,7 +79,6 @@ function ACheck(props) {
<Container fluid> <Container fluid>
<Ta responsive="lg"> <Ta responsive="lg">
<thead className="thead-light"> <thead className="thead-light">
<tr> <tr>
<th>대표자</th> <th>대표자</th>
<th>날짜</th> <th>날짜</th>
......
...@@ -55,7 +55,6 @@ function Apply(props) { ...@@ -55,7 +55,6 @@ function Apply(props) {
localStorage.clear(); localStorage.clear();
setState({ok:"no"}); setState({ok:"no"});
} }
console.log(res.data);
setUser(res.data); setUser(res.data);
}) })
.catch(err => { .catch(err => {
...@@ -110,7 +109,6 @@ function Apply(props) { ...@@ -110,7 +109,6 @@ function Apply(props) {
} }
alert("신청이 완료되었습니다!"); alert("신청이 완료되었습니다!");
setState({ok:"ok"}); setState({ok:"ok"});
console.log("res.data", res.data)
}) })
.catch(err => { .catch(err => {
alert(err.error) alert(err.error)
...@@ -179,9 +177,9 @@ function Apply(props) { ...@@ -179,9 +177,9 @@ function Apply(props) {
<div className={touched.room && errors.room ? "text-danger" : ""}>강의실</div> <div className={touched.room && errors.room ? "text-danger" : ""}>강의실</div>
<Field as="select" name="room" className="col-6"> <Field as="select" name="room" className="col-6">
<option value="">강의실 선택</option> <option value="">강의실 선택</option>
<option value="9-116">9-116</option> <option value="9-116">9-116 (5)</option>
<option value="7-234">7-234</option> <option value="7-234">7-234 (7)</option>
<option value="25-101">25-101</option> <option value="25-101">25-101 (10)</option>
</Field> </Field>
</div> </div>
...@@ -198,7 +196,7 @@ function Apply(props) { ...@@ -198,7 +196,7 @@ function Apply(props) {
<div className="form-group mb-4"> <div className="form-group mb-4">
<FieldArray name="students"> <FieldArray name="students">
{({ insert, remove, push }) => ( {({ remove, push }) => (
<div> <div>
<div className={touched.date && errors.date ? "text-danger" : ""}>이용자</div> <div className={touched.date && errors.date ? "text-danger" : ""}>이용자</div>
{values.students.map((student, index) => ( {values.students.map((student, index) => (
......
...@@ -8,7 +8,6 @@ import { Container, Button, Navbar, Col } from 'react-bootstrap'; ...@@ -8,7 +8,6 @@ import { Container, Button, Navbar, Col } from 'react-bootstrap';
import styled from 'styled-components'; import styled from 'styled-components';
const Check = styled.div` const Check = styled.div`
& #reCheck::after { & #reCheck::after {
content: '새로운 비밀번호를 다시 입력하세요'; content: '새로운 비밀번호를 다시 입력하세요';
} }
...@@ -26,7 +25,7 @@ function Change(props) { ...@@ -26,7 +25,7 @@ function Change(props) {
if (state) { if (state) {
return <Redirect to="/" />; return <Redirect to="/" />;
} }
// console.log(props)
return ( return (
<div className=""> <div className="">
{(localStorage.getItem("token") !== null) ? ( {(localStorage.getItem("token") !== null) ? (
...@@ -103,13 +102,10 @@ function Change(props) { ...@@ -103,13 +102,10 @@ function Change(props) {
)} )}
</Formik> </Formik>
</Col> </Col>
</Check> </Check>
</Container> </Container>
</div > </div >
); );
} }
export default Change
export default Change; \ No newline at end of file
...@@ -6,7 +6,7 @@ import { Container, Table } from 'react-bootstrap'; ...@@ -6,7 +6,7 @@ import { Container, Table } from 'react-bootstrap';
import styled from 'styled-components'; import styled from 'styled-components';
const Ta = styled(Table)` const Ta = styled(Table)`
margin-top: 0.5em; margin-top: 0.5em;
& th, & td { & th, & td {
padding: 0; padding: 0;
...@@ -49,7 +49,6 @@ function Check(props) { ...@@ -49,7 +49,6 @@ function Check(props) {
localStorage.clear(); localStorage.clear();
setState(true); setState(true);
} }
console.log(res.data);
const reserves = res.data.filter(function(item) { const reserves = res.data.filter(function(item) {
return item !== ''; return item !== '';
}); });
......
...@@ -23,6 +23,7 @@ function Find() { ...@@ -23,6 +23,7 @@ function Find() {
state: { id: localStorage.getItem('_id') }, state: { id: localStorage.getItem('_id') },
}} />; }} />;
} }
return ( return (
<div className="vh-100"> <div className="vh-100">
<Menu expand="md" variant="dark"> <Menu expand="md" variant="dark">
...@@ -111,4 +112,4 @@ function Find() { ...@@ -111,4 +112,4 @@ function Find() {
} }
export default Find; export default Find
\ No newline at end of file
...@@ -45,7 +45,7 @@ function Home() { ...@@ -45,7 +45,7 @@ function Home() {
<p> <p>
<strong>유의사항</strong> <strong>유의사항</strong>
<ul className="pl-4"> <ul className="pl-4">
<li>강의실 대관하는 대표자를 기준으로 최대 6시간까지 대관이 가능합니다.</li> <li>강의실 사용시 최소인원 수에 맞춰서 명단 작성이 필요합니다.</li>
<li>1 대관시 최대 3시간까지 이용이 가능합니다. (1시간 단위로 대관 가능)</li> <li>1 대관시 최대 3시간까지 이용이 가능합니다. (1시간 단위로 대관 가능)</li>
<li><strong style={{ color: "red" }}>대관 시간 이외 강의실을 이용하다 적발될 경우 한달 강의실 이용이 불가합니다.</strong></li> <li><strong style={{ color: "red" }}>대관 시간 이외 강의실을 이용하다 적발될 경우 한달 강의실 이용이 불가합니다.</strong></li>
</ul> </ul>
...@@ -66,4 +66,4 @@ function Home() { ...@@ -66,4 +66,4 @@ function Home() {
) )
} }
export default Home; export default Home
\ No newline at end of file \ No newline at end of file
...@@ -27,7 +27,6 @@ const Col_1 = styled.div` ...@@ -27,7 +27,6 @@ const Col_1 = styled.div`
height : 100%; height : 100%;
width: 100%; width: 100%;
justify-content: space-evenly; justify-content: space-evenly;
} }
& .mob-img { & .mob-img {
...@@ -177,10 +176,8 @@ function Login() { ...@@ -177,10 +176,8 @@ function Login() {
</div> </div>
<Button type="submit" variant="dark" className={mobile ? " w-100" : " w-20"} disabled={isSubmitting}> Login </Button> <Button type="submit" variant="dark" className={mobile ? " w-100" : " w-20"} disabled={isSubmitting}> Login </Button>
</div> </div>
<div><Link to="/find">비밀번호를 잊으셨나요?</Link></div> <div><Link to="/find">비밀번호를 잊으셨나요?</Link></div>
<div><Link to="/signup">회원이 아니신가요?</Link></div> <div><Link to="/signup">회원이 아니신가요?</Link></div>
</form> </form>
</div> </div>
)} )}
...@@ -188,8 +185,7 @@ function Login() { ...@@ -188,8 +185,7 @@ function Login() {
</Col_2> </Col_2>
</Row> </Row>
</Container> </Container>
) )
} }
export default Login; export default Login
\ No newline at end of file \ No newline at end of file
import React, { useState, useEffect } from 'react';
import { Redirect } from 'react-router-dom';
import Menu from '../Components/Menu';
import * as Yup from 'yup';
import axios from 'axios';
import { Container, Row, Col, Button } from 'react-bootstrap';
import { Field, Formik } from 'formik';
function Modify({ match }) {
const [state, setState] = useState(false);
const [modification, setModification] = useState({ title: "", content: "" });
const [isadmin, setIsadmin] = useState({ ok: "" });
const [user, setUser] = useState({ name: "", role: "" })
useEffect(() => {
acheck();
getOne(match.params.id);
}, [])
if (isadmin.ok === "no") return <Redirect to="/" />;
if (state) {
return <Redirect to="/notice" />;
}
function getOne(id) {
if (id) {
axios.get(`/notices/${match.params.id}`)
.then(res => {
if (res.status !== 201) {
alert(res.data.error);
}
setModification({ title: res.data.notice_title, content: res.data.notice_content })
})
.catch(err => {
alert(err.error)
});
}
};
function acheck() {
axios.get(`/users/admin/${localStorage.getItem('_id')}`, {
headers: { authorization: localStorage.getItem('token') },
})
.then(res => {
if (res.status !== 201) {
alert(res.data.error);
setIsadmin({ ok: "no" });
}
setUser({ name: res.data.name, role: res.data.role })
}).catch(err => {
alert(err.error)
});
}
return (
<div>
<Menu />
<Container fluid>
{console.log(modification)}
<Row className="justify-content-center">
<Col md={5} xs={11} className="pt-3" >
<Formik
initialValues={{ name: user.name, title: modification.title, content: modification.content }}
enableReinitialize={true}
validationSchema={Yup.object({
title: Yup.string()
.required('제목을 입력해주세요.'),
content: Yup.string()
.required('내용을 입력해주세요.'),
})}
onSubmit={(values, { setSubmitting }) => {
axios({
method: 'put',
url: `/writes/${match.params.id}`,
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="d-flex flex-column">
<div className="form-group">
<div className={touched.name && errors.name ? "text-danger" : ""}>제목</div>
<input className={(touched.name && errors.name ? 'form-control is-invalid' : "form-control")}
type="text"
title="title"
{...getFieldProps('title')}
disabled />
</div>
<div className="form-group">
<div className={touched.name && errors.name ? "text-danger" : ""}>내용</div>
<Field as="textarea" rows={8} style={{ "min-width": "100%" }}
{...getFieldProps('content')} />
</div>
<Button className="mb-2" variant="dark" type="submit" disabled={isSubmitting}>공지 수정</Button>
</form>
)}
</Formik>
</Col>
</Row>
</Container>
</div>
)
}
export default Modify
\ No newline at end of file
...@@ -67,4 +67,4 @@ function Notice() { ...@@ -67,4 +67,4 @@ function Notice() {
) )
} }
export default Notice; export default Notice
\ No newline at end of file \ No newline at end of file
...@@ -157,8 +157,7 @@ function Signup() { ...@@ -157,8 +157,7 @@ function Signup() {
</Wow> </Wow>
</Container> </Container>
</div > </div >
); );
} }
export default Signup; export default Signup
\ No newline at end of file \ No newline at end of file
...@@ -6,69 +6,46 @@ import axios from 'axios'; ...@@ -6,69 +6,46 @@ import axios from 'axios';
import { Container, Row, Col, Button } from 'react-bootstrap'; import { Container, Row, Col, Button } from 'react-bootstrap';
import { Field, Formik } from 'formik'; import { Field, Formik } from 'formik';
function Write({ match }) { function Write() {
const [state, setState] = useState(false); const [state, setState] = useState(false);
const [revision, setRevision] = useState({ title: '', content: '' }); const [isadmin, setIsadmin] = useState({ ok: "" });
// const [isadmin, setIsadmin] = useState({ok:""}); const [user, setUser] = useState({ name: "" })
// const [user, setUser] = useState({ role: "" })
// if (isadmin.ok==="no") return <Redirect to="/" />;
useEffect(() => { useEffect(() => {
getOne(match.params.id) acheck();
}, []) }, [])
if (isadmin.ok === "no") return <Redirect to="/" />;
if (state) { if (state) {
return <Redirect to="/notice" />; return <Redirect to="/notice" />;
} }
function getOne (id) { function acheck() {
if (id) { axios.get(`/users/admin/${localStorage.getItem('_id')}`, {
axios.get(`/notices/${id}`) headers: { authorization: localStorage.getItem('token') },
})
.then(res => { .then(res => {
if (res.status !== 201) { if (res.status !== 201) {
alert(res.data.error); alert(res.data.error);
console.log(res.data)
setIsadmin({ ok: "no" });
} }
setRevision({ title: res.data.notice_title, content: res.data.notice_content }) setUser({ name: res.data.name })
}) }).catch(err => {
.catch(err => {
alert(err.error) alert(err.error)
}); });
} }
};
// function putData (match, revision) {
// if (!match.params.id) return { title: '', content: '' }
// else return { title: revision.notice_title, content: revision.notice_content }
// };
// function acheck() {
// axios.get(`/users/${localStorage.getItem('_id')}`, {
// headers: { authorization: localStorage.getItem('token') },
// })
// .then(res => {
// if (res.status !== 201) {
// alert(res.data.error);
// localStorage.clear();
// setIsadmin({ok:"no"});
// }
// if (res.data.role == "admin") {
// setUser(res.data)
// }
// }).catch(err => {
// alert(err.error)
// });
// }
return ( return (
<div> <div>
{console.log("revision", revision.title, revision.content)} <Menu />
<Menu/>
<Container fluid> <Container fluid>
<Row className="justify-content-center"> <Row className="justify-content-center">
<Col md={5} xs={11} className="pt-3" > <Col md={5} xs={11} className="pt-3" >
<Formik <Formik
initialValues={{title: revision.title, content: revision.content}} initialValues={{ name: user.name, title: '', content: '' }}
enableReinitialize={true}
validationSchema={Yup.object({ validationSchema={Yup.object({
title: Yup.string() title: Yup.string()
.required('제목을 입력해주세요.'), .required('제목을 입력해주세요.'),
...@@ -76,7 +53,7 @@ function Write({ match }) { ...@@ -76,7 +53,7 @@ function Write({ match }) {
.required('내용을 입력해주세요.'), .required('내용을 입력해주세요.'),
})} })}
onSubmit={(values, { setSubmitting }) => { onSubmit={(values, { setSubmitting }) => {
if (!match.params.id) { console.log(values)
axios({ axios({
method: 'post', method: 'post',
url: '/writes', url: '/writes',
...@@ -89,21 +66,7 @@ function Write({ match }) { ...@@ -89,21 +66,7 @@ function Write({ match }) {
.catch(err => { .catch(err => {
alert(err.error) alert(err.error)
}); });
} else {
axios({
method: 'put',
url: '/writes/${id}',
data: values,
})
.then(res => {
if (res.status === 404) return alert(res.data.error)
alert("공지 수정이 완료되었습니다.")
setState(true);
})
.catch(err => {
alert(err.error)
});
}
setTimeout(() => { setTimeout(() => {
setSubmitting(false); setSubmitting(false);
}, 400); // finish the cycle in handler }, 400); // finish the cycle in handler
...@@ -124,13 +87,12 @@ function Write({ match }) { ...@@ -124,13 +87,12 @@ function Write({ match }) {
{...getFieldProps('title')} {...getFieldProps('title')}
placeholder="제목" /> placeholder="제목" />
</div> </div>
{console.log(revision.title)}
<div className="form-group"> <div className="form-group">
<div className={touched.name && errors.name ? "text-danger" : ""}>내용</div> <div className={touched.name && errors.name ? "text-danger" : ""}>내용</div>
<Field as="textarea" rows={8} style={{ "min-width": "100%" }} <Field as="textarea" rows={8} style={{ "min-width": "100%" }}
{...getFieldProps('content')} /> {...getFieldProps('content')} />
</div> </div>
<Button className="mb-2" variant="dark" type="submit" disabled={isSubmitting}>{match.params.id ? "공지 수정" : "공지 등록"}</Button> <Button className="mb-2" variant="dark" type="submit" disabled={isSubmitting}>공지 등록</Button>
</form> </form>
)} )}
</Formik> </Formik>
......
...@@ -17,6 +17,7 @@ import Check from './Pages/CheckPage'; ...@@ -17,6 +17,7 @@ import Check from './Pages/CheckPage';
import Notice from './Pages/NoticePage'; import Notice from './Pages/NoticePage';
import ACheck from './Pages/ACheckPage'; import ACheck from './Pages/ACheckPage';
import Write from './Pages/WritePage'; import Write from './Pages/WritePage';
import Modify from './Pages/ModifyPage';
axios.defaults.validateStatus = function (status) { axios.defaults.validateStatus = function (status) {
return status < 500; // default return status < 500; // default
...@@ -33,7 +34,7 @@ ReactDOM.render( ...@@ -33,7 +34,7 @@ ReactDOM.render(
<Route path="/change" component={Change} /> <Route path="/change" component={Change} />
<Route path="/apply/:id" component={Apply} /> <Route path="/apply/:id" component={Apply} />
<Route path="/check/:id" component={Check} /> <Route path="/check/:id" component={Check} />
<Route path="/write/revise/:id" component={Write} /> <Route path="/modify/:id" component={Modify} />
<Route path="/write" component={Write} /> <Route path="/write" component={Write} />
<Route path="/notice" component={Notice} /> <Route path="/notice" component={Notice} />
<Route path="/acheck/:id" component={ACheck} /> <Route path="/acheck/:id" component={ACheck} />
......
...@@ -2,7 +2,6 @@ const express = require('express'); ...@@ -2,7 +2,6 @@ const express = require('express');
const User = require('../schemas/user'); const User = require('../schemas/user');
const bcrypt = require("bcrypt"); const bcrypt = require("bcrypt");
const jwt = require('jsonwebtoken'); const jwt = require('jsonwebtoken');
const user = require('../schemas/user');
const router = express.Router(); const router = express.Router();
...@@ -66,4 +65,5 @@ router.post('/find', function (req, res, next) { ...@@ -66,4 +65,5 @@ router.post('/find', function (req, res, next) {
return res.status(404).json({error: '질문을 다시 선택해주세요.'}); return res.status(404).json({error: '질문을 다시 선택해주세요.'});
}) })
}); });
module.exports = router; module.exports = router;
\ No newline at end of file
...@@ -18,7 +18,6 @@ router.get('/', function (req, res, next) { ...@@ -18,7 +18,6 @@ router.get('/', function (req, res, next) {
router.get('/:id', function (req, res, next) { router.get('/:id', function (req, res, next) {
Notice.findOne({ _id: req.params.id }, function (err, notice) { Notice.findOne({ _id: req.params.id }, function (err, notice) {
if (err) return res.status(500).json({ error: err }); if (err) return res.status(500).json({ error: err });
console.log("FindOne", notice)
res.status(201).json(notice); res.status(201).json(notice);
}) })
}); });
......
const express = require('express'); const express = require('express');
const User = require('../schemas/user');
const Reserve = require('../schemas/reserve'); const Reserve = require('../schemas/reserve');
const { verifyToken } = require('./middlewares'); const { verifyToken } = require('./middlewares');
......
...@@ -44,10 +44,11 @@ router.get('/:_id', verifyToken, function (req, res, next) { ...@@ -44,10 +44,11 @@ router.get('/:_id', verifyToken, function (req, res, next) {
router.get('/admin/:_id', function (req, res, next) { router.get('/admin/:_id', function (req, res, next) {
console.log('/admin get req.params', req.params) console.log('/admin get req.params', req.params)
User.findOne({ _id: req.params._id }, 'role', function (err, user) { User.findOne({ _id: req.params._id }, function (err, user) {
if (err) return res.status(500).json({ error: err }); if (err) return res.status(500).json({ error: err });
if (user.role == 'admin') { if (user.role === 'admin') {
next(); res.status(201).json(user);
// next();
} }
else return res.status(404).json({ error: '권한이 없습니다.' }) else return res.status(404).json({ error: '권한이 없습니다.' })
}) })
......
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