Commit 1919dcb1 authored by KangMin An's avatar KangMin An
Browse files

Merge branch 'who' into premaster

parents a8483c18 97d250a5
...@@ -64,6 +64,7 @@ body { ...@@ -64,6 +64,7 @@ body {
.form-group .form-control { .form-group .form-control {
border-radius: 40px; border-radius: 40px;
} }
#formbtn { #formbtn {
width: 100%; width: 100%;
border-radius: 40px; border-radius: 40px;
......
import axios from 'axios'; import axios from 'axios';
import { checkCookies } from './CheckDB';
export function handleLogin({ userId, role, name, tel, email }) { export function handleLogin({ userId, role, name, tel, email }) {
localStorage.setItem('id', userId) localStorage.setItem('id', userId)
...@@ -15,7 +16,7 @@ export async function handleLogout() { ...@@ -15,7 +16,7 @@ export async function handleLogout() {
} }
export function isLogined() { export function isLogined() {
const userId = localStorage.getItem('nickname') const userId = checkCookies()
if (userId) { if (userId) {
return userId return userId
} else { } else {
......
import React from 'react' import axios from 'axios';
import { Swal } from 'sweetalert2'; import { Swal } from 'sweetalert2';
export async function callUserInfo() {
const res = await axios.get("/api/user-info")
return res.data.user_info
}
export function checkCookies() { export function checkCookies() {
const acctoken_cookies = document.cookie.split('=')[1]; const acctoken_cookies = document.cookie.split('=')[1];
return acctoken_cookies; return acctoken_cookies;
} }
export function deleteCookie (name) { export function deleteCookie(name) {
document.cookie = name + '=; expires=Thu, 01 Jan 1999 00:00:10 GMT;'; document.cookie = name + '=; expires=Thu, 01 Jan 1999 00:00:10 GMT;';
Swal.fire({ Swal.fire({
title: '로그아웃 성공!', title: '로그아웃 성공!',
......
...@@ -3,6 +3,7 @@ import '../App.css' ...@@ -3,6 +3,7 @@ import '../App.css'
import { Form, Button, Row, Col, Card } from 'react-bootstrap'; import { Form, Button, Row, Col, Card } from 'react-bootstrap';
import axios from 'axios'; import axios from 'axios';
import Swal from 'sweetalert2' import Swal from 'sweetalert2'
import { callUserInfo } from '../utils/CheckDB';
function LocCodeChange() { function LocCodeChange() {
...@@ -22,7 +23,7 @@ function LocCodeChange() { ...@@ -22,7 +23,7 @@ function LocCodeChange() {
const inboxstyled = { const inboxstyled = {
display: 'flex', display: 'flex',
flexDirection: 'column', flexDirection: 'column',
maxWidth: '80%', maxWidth: '90%',
justifyContent: 'center', justifyContent: 'center',
margin: 'auto', margin: 'auto',
padding: '0.5em', padding: '0.5em',
...@@ -47,9 +48,19 @@ function LocCodeChange() { ...@@ -47,9 +48,19 @@ function LocCodeChange() {
const sggSelect = document.getElementById('select-sgg') const sggSelect = document.getElementById('select-sgg')
const emdSelect = document.getElementById('select-emd') const emdSelect = document.getElementById('select-emd')
const saveCodeEmd = localStorage.getItem('code_emd')
function handleClickLoc() { async function handleClickLoc() {
if (doeSelect.options[doeSelect.selectedIndex].text !== '' && sggSelect.options[sggSelect.selectedIndex].text !== '시군구' && emdSelect.options[emdSelect.selectedIndex].text !== '읍면동') { if (doeSelect.options[doeSelect.selectedIndex].text !== '' && sggSelect.options[sggSelect.selectedIndex].text !== '시군구' && emdSelect.options[emdSelect.selectedIndex].text !== '읍면동') {
await axios.post('/api/edit-profile', { loc_code: saveCodeEmd })
.then(function (response) {
console.log('loc', response);
})
callUserInfo().then((res) => {
console.log('11', res[0])
})
localStorage.setItem('code_doe', doeSelect.value) localStorage.setItem('code_doe', doeSelect.value)
localStorage.setItem('name_doe', doeSelect.options[doeSelect.selectedIndex].text) localStorage.setItem('name_doe', doeSelect.options[doeSelect.selectedIndex].text)
localStorage.setItem('code_sgg', sggSelect.value) localStorage.setItem('code_sgg', sggSelect.value)
...@@ -57,37 +68,38 @@ function LocCodeChange() { ...@@ -57,37 +68,38 @@ function LocCodeChange() {
localStorage.setItem('code_emd', emdSelect.value) localStorage.setItem('code_emd', emdSelect.value)
localStorage.setItem('name_emd', emdSelect.options[emdSelect.selectedIndex].text) localStorage.setItem('name_emd', emdSelect.options[emdSelect.selectedIndex].text)
if (localStorage.getItem('name_emd')) { // if (localStorage.getItem('name_emd')) {
Swal.fire({ // Swal.fire({
title: '변경되었습니다.', // title: '변경되었습니다.',
text: '축하드립니다!👏', // text: '축하드립니다!👏',
icon: 'success', // icon: 'success',
customClass: 'swal-wide', // customClass: 'swal-wide',
confirmButtonText: '확인', // confirmButtonText: '확인',
}).then((res) => { // }).then((res) => {
if (res.isConfirmed) { // if (res.isConfirmed) {
window.location.reload() // window.location.reload()
} // }
else { // else {
window.location.reload() // window.location.reload()
} // }
}) // })
} // }
}
else {
Swal.fire({
title: '실패',
text: '전부 선택해주세요',
icon: 'error',
customClass: 'swal-wide',
confirmButtonText: '확인'
})
} }
// else {
// Swal.fire({
// title: '실패',
// text: '전부 선택해주세요',
// icon: 'error',
// customClass: 'swal-wide',
// confirmButtonText: '확인'
// })
// }
} }
async function getLocCode() { async function getLocCode() {
const res = await axios.get("http://localhost:4500/api/data/loccode") const res = await axios.get("/api/data/loccode")
const local_codes = res.data.locCodes const local_codes = res.data.locCodes
setDoes(local_codes.DOE) setDoes(local_codes.DOE)
...@@ -107,9 +119,12 @@ function LocCodeChange() { ...@@ -107,9 +119,12 @@ function LocCodeChange() {
} }
}) })
emds.map(function (emdvalue) { emds.map(function (emdvalue) {
if (sggSelect.value == emdvalue['code_sgg']) { if (sggSelect.value == emdvalue['code_sgg'] && doeSelect.value == emdvalue['code_doe']) {
setEmdsArray(emdvalue['emd']) setEmdsArray(emdvalue['emd'])
} }
else {
return false
}
}) })
} }
...@@ -126,10 +141,10 @@ function LocCodeChange() { ...@@ -126,10 +141,10 @@ function LocCodeChange() {
</Card.Subtitle> </Card.Subtitle>
<hr /> <hr />
<Card.Text className='m-0'> <Card.Text className='m-0'>
<Form style={inboxstyled}> <Form style={inboxstyled} onChange={selectLocal}>
<Row md={12} xs={12} className='m-auto w-100 d-flex justify-content-center' style={{ padding: '0', display: 'flex', justifyContent: 'center', width: '100%' }}> <Row md={12} xs={12} className='m-auto w-100 d-flex justify-content-center' style={{ padding: '0', display: 'flex', justifyContent: 'center', width: '100%' }}>
<Form.Group className='m-auto w-100' style={btnstyled2}> <Form.Group className='m-auto w-100' style={btnstyled2}>
<Row className='m-auto pb-3' onChange={selectLocal}> <Row className='m-auto pb-3'>
<Col md={4} xs={4} style={{ padding: '2px' }}> <Col md={4} xs={4} style={{ padding: '2px' }}>
<Form.Control as='select' size="sm" id='select-doe'> <Form.Control as='select' size="sm" id='select-doe'>
......
...@@ -48,8 +48,16 @@ function LoginComp() { ...@@ -48,8 +48,16 @@ function LoginComp() {
function addressUrl() { function addressUrl() {
const afterAt = localStorage.getItem('login_email_Address').split('@')[1] const afterAt = localStorage.getItem('login_email_Address').split('@')[1]
const newLink = 'https://www.' + afterAt; if (afterAt == ('naver.com' || 'gmail.com' || 'daum.net')) {
window.open(newLink); const newLink = 'https://www.' + afterAt;
window.open(newLink);
}
if (afterAt == 'korea.ac.kr' ) {
window.open('https://www.gmail.com');
}
else {
window.open();
}
} }
function handleChange(event) { function handleChange(event) {
...@@ -100,7 +108,6 @@ function LoginComp() { ...@@ -100,7 +108,6 @@ function LoginComp() {
<Form style={inboxstyled} onSubmit={handleSubmit}> <Form style={inboxstyled} onSubmit={handleSubmit}>
<FloatingLabel <FloatingLabel
controlId="floatingInput"
label="Email" label="Email"
> >
<Form.Control type="email" placeholder="Email" onChange={handleChange} /> <Form.Control type="email" placeholder="Email" onChange={handleChange} />
......
...@@ -5,9 +5,8 @@ import '../App.css' ...@@ -5,9 +5,8 @@ import '../App.css'
import UserInfo from './UserInfo'; import UserInfo from './UserInfo';
import { kakaoLogout } from '../utils/Oauth'; import { kakaoLogout } from '../utils/Oauth';
import axios from 'axios'; import axios from 'axios';
import { Swal } from 'sweetalert2'; import { callUserInfo, deleteCookie } from '../utils/CheckDB';
import { deleteCookie } from '../utils/Cookies'; import { checkCookies } from '../utils/CheckDB';
import { checkCookies } from './../utils/Cookies';
function MainLayer() { function MainLayer() {
...@@ -37,25 +36,39 @@ function MainLayer() { ...@@ -37,25 +36,39 @@ function MainLayer() {
} }
const logined = localStorage.getItem('nickname')
const [airUsing, setAirUsing] = useState(false) const [airUsing, setAirUsing] = useState(false)
function aircondiCheck() {
setAirUsing(!airUsing)
localStorage.setItem('using-aircondition', !airUsing);
}
useEffect(() => { useEffect(() => {
const airUsingLocal = localStorage.getItem('using-aircondition') callUserInfo().then((res) => {
if (airUsingLocal === 'true') { if (res !== []) {
return setAirUsing(true) console.log(res[0])
} }
else { else {
return setAirUsing(false) console.log(res)
} }
}); })
}, [])
async function airChange() {
setAirUsing(!airUsing)
await axios.post('/api/edit-profile', { using_aircon: !airUsing })
.then(function (response) {
console.log('res', response);
callUserInfo().then((res) => {
if (res !== []) {
console.log(res[0])
}
else {
console.log(res)
}
})
})
.catch(function (error) {
console.log('err', error);
});
}
return ( return (
...@@ -77,7 +90,7 @@ function MainLayer() { ...@@ -77,7 +90,7 @@ function MainLayer() {
type='switch' type='switch'
id='airconditioner' id='airconditioner'
label='에어컨 사용중' label='에어컨 사용중'
onChange={aircondiCheck} onChange={airChange}
checked={airUsing} checked={airUsing}
/> />
</Form> </Form>
...@@ -85,9 +98,11 @@ function MainLayer() { ...@@ -85,9 +98,11 @@ function MainLayer() {
<Row className='d-flex justify-content-center align-items-center my-2 mx-auto w-100'> <Row className='d-flex justify-content-center align-items-center my-2 mx-auto w-100'>
<ButtonGroup vertical className='m-auto' style={{ width: '100%', flexDirection: 'column' }}> <ButtonGroup vertical className='m-auto' style={{ width: '100%', flexDirection: 'column' }}>
{checkCookies() ? {checkCookies() ?
//true //true
<Button variant='light' style={btnstyled} onClick={kakaoLogout || deleteCookie('acs_token')}> <Button variant='light' style={btnstyled} onClick={kakaoLogout}>
{/* || deleteCookie('acs_token') */}
로그아웃 로그아웃
</Button> </Button>
: :
...@@ -98,6 +113,7 @@ function MainLayer() { ...@@ -98,6 +113,7 @@ function MainLayer() {
</Link> </Link>
</Button> </Button>
} }
{!checkCookies() && {!checkCookies() &&
<Button variant='light' style={btnstyled}> <Button variant='light' style={btnstyled}>
<Link to='/signup' id='btnlink'> <Link to='/signup' id='btnlink'>
......
import React, { useEffect } from 'react' import axios from 'axios';
import React, { useEffect, useState } from 'react'
import { Row, Card, Col, Form, Button, FloatingLabel } from 'react-bootstrap'; import { Row, Card, Col, Form, Button, FloatingLabel } from 'react-bootstrap';
import { callUserInfo } from '../utils/CheckDB';
function NicknameChange() { function NicknameChange() {
...@@ -25,18 +27,25 @@ function NicknameChange() { ...@@ -25,18 +27,25 @@ function NicknameChange() {
color: 'black' color: 'black'
} }
const exNick = localStorage.getItem('nickname') const [inputname, setInputname] = useState('')
console.log(exNick)
function handleChange ({ target: { value } }) { function handleChange({ target: { value } }) {
localStorage.setItem('nickname', value) setInputname(value)
} }
console.log(inputname)
function handleSubmit(event) { async function handleSubmit(event) {
event.preventDefault(); event.preventDefault();
window.location.reload(); await axios.post('/api/edit-profile', { nick_name: inputname })
}; .then(function (response) {
console.log(response);
})
callUserInfo().then((res) => {
console.log('11', res[0])
})
// window.location.reload();
};
return ( return (
<Row className='text-center w-100 my-2'> <Row className='text-center w-100 my-2'>
...@@ -47,25 +56,19 @@ function NicknameChange() { ...@@ -47,25 +56,19 @@ function NicknameChange() {
<Card.Subtitle style={{ fontWeight: 'lighter' }}> <Card.Subtitle style={{ fontWeight: 'lighter' }}>
새로운 닉네임으로 변경해보세요 새로운 닉네임으로 변경해보세요
</Card.Subtitle> </Card.Subtitle>
<hr /> <hr />
<Card.Text className='m-0'>
<Card.Text className='m-0'>
<Form style={inboxstyled} onSubmit={handleSubmit}> <Form style={inboxstyled} onSubmit={handleSubmit}>
<FloatingLabel <FloatingLabel label="Nickname">
controlId="floatingInput"
label="Nickname"
>
<Form.Control type="text" placeholder="닉네임 변경" id='nickname' onChange={handleChange} /> <Form.Control type="text" placeholder="닉네임 변경" id='nickname' onChange={handleChange} />
</FloatingLabel> </FloatingLabel>
<Button variant='light' className='mt-3' id='formbtn' type='submit'> <Button variant='light' className='mt-3' id='formbtn' type='submit'>
</Button> </Button>
</Form> </Form>
</Card.Text> </Card.Text>
</Card> </Card>
</Row> </Row>
) )
......
import React, { useState } from 'react' import React, { useEffect, useState } from 'react'
import '../App.css' import '../App.css'
import { Form, Button, Row, Col, Card, Alert, FloatingLabel } from 'react-bootstrap'; import { Form, Button, Row, Col, Card, Alert, FloatingLabel } from 'react-bootstrap';
import { LoginWithKakao } from '../utils/Oauth'; import { LoginWithKakao } from '../utils/Oauth';
import axios from 'axios'; import axios from 'axios';
import { callUserInfo } from '../utils/CheckDB';
function SignupComp() { function SignupComp() {
...@@ -34,9 +35,6 @@ function SignupComp() { ...@@ -34,9 +35,6 @@ function SignupComp() {
} }
const [formValues, setFormValues] = useState(initValues) const [formValues, setFormValues] = useState(initValues)
const [validated, setValidated] = useState(false)
const [emailSubm, setEmailSubm] = useState(false)
const [userExist, setUserExist] = useState(false) const [userExist, setUserExist] = useState(false)
const [alertShow, setAlertShow] = useState(false) const [alertShow, setAlertShow] = useState(false)
...@@ -45,13 +43,32 @@ function SignupComp() { ...@@ -45,13 +43,32 @@ function SignupComp() {
const { name, value } = event.target const { name, value } = event.target
setFormValues({ ...formValues, [name]: value }) setFormValues({ ...formValues, [name]: value })
} }
console.log('???', formValues) // console.log('???', formValues)
async function handleSubmit(event) { async function handleSubmit(event) {
event.preventDefault(); event.preventDefault();
await axios.post("/api/signup", formValues) await axios.post("/api/signup", formValues)
} }
const [userInfo, setUserInfo] = useState([])
function CheckUserExist() {
setUserInfo(callUserInfo())
setAlertShow(true)
if (userInfo) {
setUserExist(true)
// 기존회원
}
if (callUserInfo() === undefined) {
setUserExist(false)
// 신규회원
}
}
console.log(callUserInfo())
console.log(userExist)
return ( return (
<Row className='text-center w-100 my-2'> <Row className='text-center w-100 my-2'>
...@@ -88,7 +105,6 @@ function SignupComp() { ...@@ -88,7 +105,6 @@ function SignupComp() {
<Form style={inboxstyled} onSubmit={handleSubmit}> <Form style={inboxstyled} onSubmit={handleSubmit}>
<FloatingLabel <FloatingLabel
controlId="floatingInput"
label="Nickname" label="Nickname"
className='mb-3' className='mb-3'
> >
...@@ -101,7 +117,6 @@ function SignupComp() { ...@@ -101,7 +117,6 @@ function SignupComp() {
/> />
</FloatingLabel> </FloatingLabel>
<FloatingLabel <FloatingLabel
controlId="floatingInput"
label="Email Address" label="Email Address"
> >
<Form.Control <Form.Control
...@@ -113,8 +128,7 @@ function SignupComp() { ...@@ -113,8 +128,7 @@ function SignupComp() {
/> />
</FloatingLabel> </FloatingLabel>
<Button variant='light' className='mt-3' id='formbtn' type='submit'> <Button variant='light' className='mt-3' id='formbtn' type='submit' onClick={CheckUserExist}>
{/* onClick={CheckUserExist} */}
Sign Up Sign Up
</Button> </Button>
</Form> </Form>
......
import React, { useState } from 'react' import React, { useState, useEffect } from 'react'
import { Row, Card, Button, Col, Modal } from 'react-bootstrap'; import { Row, Card, Button, Col } from 'react-bootstrap';
import '../App.css' import '../App.css'
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { checkCookies } from './../utils/Cookies'; import { callUserInfo, checkCookies } from '../utils/CheckDB';
import axios from 'axios';
function UserInfo() { function UserInfo() {
const nickname = localStorage.getItem('nickname')
const localname_doe = localStorage.getItem('name_doe')
const localname_sgg = localStorage.getItem('name_sgg')
const localname_emd = localStorage.getItem('name_emd')
const cardstyled = { const cardstyled = {
margin: 'auto', margin: 'auto',
padding: '1em 0.5em 1em 0.5em', padding: '1em 0.5em 1em 0.5em',
// paddingTop: '1em',
// paddingBottom: '1em',
display: 'flex', display: 'flex',
justifyContent: 'center', justifyContent: 'center',
width: '100%', width: '100%',
borderWidth: '3px', borderWidth: '3px',
borderRadius: '20px', borderRadius: '20px',
borderColor: 'rgba(195, 195, 195, 0.753)', borderColor: 'rgba(195, 195, 195, 0.753)',
// color: '#04AB70'
color: 'rgb(110, 189, 142)', color: 'rgb(110, 189, 142)',
...@@ -40,61 +34,111 @@ function UserInfo() { ...@@ -40,61 +34,111 @@ function UserInfo() {
width: '50%' width: '50%'
} }
const localname_doe = localStorage.getItem('name_doe')
const localname_sgg = localStorage.getItem('name_sgg')
const localname_emd = localStorage.getItem('name_emd')
const localcode_emd = localStorage.getItem('code_emd')
const [userNick, setUserNick] = useState('')
const [createdTime, setCreatedTime] = useState('')
useEffect(() => {
callUserInfo().then((res) => {
if (res !== []) {
setUserNick(res[0]['nick_name'])
const dateStr = res[0]['created_at'].split('T')[0].split('-')
console.log(dateStr)
const now = new Date();
const year = now.getFullYear(); // 년
const month = now.getMonth() + 1; // 월 0부터 시작
const day = now.getDate(); // 일
const stDate = new Date(dateStr[0], dateStr[1], dateStr[2])
console.log(stDate)
const endDate = new Date(year, month, day)
console.log(endDate)
const btMs = endDate.getTime() - stDate.getTime() // 주어진 날짜 사이의 경과 시간 (밀리 초)
console.log(btMs / 1000)
const btDay = btMs / (1000 * 60 * 60 * 24)
console.log(btDay)
setCreatedTime(btDay)
}
else {
console.log('Not Logined')
}
})
}, [])
return ( return (
<Col className='text-center pt-3 pb-2 px-0'> <Col className='text-center pt-3 pb-2 px-0'>
<Card style={cardstyled} id='localName'> <Card style={cardstyled} id='localName'>
<Card.Title> <Card.Title>
<strong> <strong>
{checkCookies() ? {checkCookies() ?
<h2> <h3>
{`${nickname}`} {`${userNick}`}
</h2> </h3>
: :
<h2> <h3>
GUEST GUEST
</h2> </h3>
}
</strong>
<p style={{ fontWeight: '300', margin: '0' }}>
환영합니다
</p>
</Card.Title>
<hr />
<Row style={{ alignItems: 'center', margin: 'auto', justifyContent: 'center' }}>
<Card.Subtitle>
{localname_emd ?
<p className='mb-2'>
{`${localname_doe}`}
<br />
{`${localname_sgg}`}
<br />
{`${localname_emd}`}
</p>
:
<p className='mb-2'>
로그인 이용 가능합니다
</p>
}
</Card.Subtitle>
{checkCookies() &&
<Button variant='light' className='m-auto d-flex' style={btnstyled2}>
<Link to='/edit' className='w-100' style={{ textDecoration: 'none', color: 'rgb(110, 189, 142)' }}>
변경
</Link>
</Button>
} }
</Row> </strong>
{checkCookies() && <p style={{ fontWeight: '300', margin: '0' }}>
<p className='w-100 justify-content-center m-auto'> 환영합니다
<hr /> </p>
</Card.Title>
<hr />
<Row style={{ alignItems: 'center', margin: 'auto', justifyContent: 'center' }}>
<Card.Subtitle>
{localname_emd ?
<p className='mb-2'>
환경을 향한 노력 <br /> {`${localname_doe}`}
<strong>OOO </strong> <br />
</p> {`${localname_sgg}`}
<br />
{`${localname_emd}`}
</p>
:
<p className='mb-2'>
로그인 이용 가능합니다
</p>
}
</Card.Subtitle>
{checkCookies() &&
<Button variant='light' className='m-auto d-flex' style={btnstyled2}>
<Link to='/edit' className='w-100' style={{ textDecoration: 'none', color: 'rgb(110, 189, 142)' }}>
변경
</Link>
</Button>
} }
</Card> </Row>
</Col> {checkCookies() &&
<Card.Text>
<hr />
<Row style={{ color: 'black' }}>
<p style={{ fontWeight: '300', margin: '0' }}>
환경을 향한 노력
</p>
<h3 style={{ fontWeight: '300', color: '#2b90d9', margin: '0' }}>
{createdTime}일차
</h3>
</Row>
</Card.Text>
}
</Card>
</Col>
) )
} }
export default UserInfo; export default UserInfo;
\ No newline at end of file
...@@ -7,7 +7,7 @@ import EueSuggest from '../components/EueSuggest'; ...@@ -7,7 +7,7 @@ import EueSuggest from '../components/EueSuggest';
import ChartLine from '../components/ChartLine'; import ChartLine from '../components/ChartLine';
import ChartDoughnut from '../components/ChartDoughnut'; import ChartDoughnut from '../components/ChartDoughnut';
import Donation from '../components/Donation'; import Donation from '../components/Donation';
import axios from 'axios';
function Home() { function Home() {
...@@ -32,11 +32,6 @@ function Home() { ...@@ -32,11 +32,6 @@ function Home() {
padding: '0' padding: '0'
} }
async function test() {
const res = await axios.get("/api/user-info", { withCredentials: true })
console.log("@@@@", res)
}
test()
return ( return (
<Container className='m-auto d-flex position-relative' <Container className='m-auto d-flex position-relative'
......
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