Showing
4 changed files
with
88 additions
and
10 deletions
1 | import React, { useState } from 'react'; | 1 | import React, { useState } from 'react'; |
2 | import { Card, CardBody, CardTitle, CardText, CardImg, CardFooter, Button } from 'reactstrap'; | 2 | import { Card, CardBody, CardTitle, CardText, CardImg, CardFooter, Button } from 'reactstrap'; |
3 | -import { Modal, ModalHeader, ModalBody, ModalFooter, Container } from 'reactstrap'; | 3 | +import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; |
4 | import Map from './Map'; | 4 | import Map from './Map'; |
5 | import './MealCard.css'; | 5 | import './MealCard.css'; |
6 | import { faAngleRight } from "@fortawesome/free-solid-svg-icons" | 6 | import { faAngleRight } from "@fortawesome/free-solid-svg-icons" | ... | ... |
1 | -import React from 'react'; | 1 | +import React, {useState} from 'react'; |
2 | import { Button, Form, FormGroup, Label, Input} from 'reactstrap'; | 2 | import { Button, Form, FormGroup, Label, Input} from 'reactstrap'; |
3 | 3 | ||
4 | -import {FacebookLoginButton} from 'react-social-login-buttons'; | ||
5 | 4 | ||
6 | const SigninPage = (props) => { | 5 | const SigninPage = (props) => { |
6 | + const [username, setUsername] = useState(''); | ||
7 | + const [password, setPassword] = useState(''); | ||
8 | + const [passwordCheck, setPasswordCheck] = useState(''); | ||
9 | + | ||
10 | + const onSubmit = (e) => { | ||
11 | + e.preventDefault(); | ||
12 | + | ||
13 | + // 비밀번호가 6자이상인지 검사 | ||
14 | + if(password.length < 6 || passwordCheck.length < 6) { | ||
15 | + return alert('비밀번호는 6자이상이어야 합니다.') | ||
16 | + } | ||
17 | + | ||
18 | + // 비밀번호와 비밀번호 체크가 다를 경우를 검사 | ||
19 | + if(password !== passwordCheck){ | ||
20 | + return alert('비밀번호가 일치하지 않습니다.'); | ||
21 | + } | ||
22 | + | ||
23 | + const signupInfo = { | ||
24 | + "username": username, | ||
25 | + "password": password | ||
26 | + }; | ||
27 | + | ||
28 | + const signup_info = { | ||
29 | + method: "POST", | ||
30 | + body: JSON.stringify(signupInfo), | ||
31 | + headers: { | ||
32 | + "Content-Type": "application/json" | ||
33 | + } | ||
34 | + }; | ||
35 | + | ||
36 | + if( username && password ) { | ||
37 | + fetch("http://localhost:3000/api/signup", signup_info) | ||
38 | + .then(response => response.json()) | ||
39 | + .then(json => { | ||
40 | + if(json.code === 200) { | ||
41 | + alert('회원가입에 성공했습니다.'); | ||
42 | + props.history.push('/signin'); | ||
43 | + } | ||
44 | + else if(json.code === 400) { | ||
45 | + alert('회원가입에 실패했습니다.'); | ||
46 | + } | ||
47 | + }) | ||
48 | + } | ||
49 | + }; | ||
50 | + | ||
51 | + const onChangeUsername = (e) => { | ||
52 | + setUsername(e.target.value); | ||
53 | + }; | ||
54 | + | ||
55 | + const onChangePassword = (e) => { | ||
56 | + setPassword(e.target.value); | ||
57 | + }; | ||
58 | + | ||
59 | + const onChangePasswordCheck = (e) => { | ||
60 | + setPasswordCheck(e.target.value); | ||
61 | + }; | ||
62 | + | ||
7 | return ( | 63 | return ( |
8 | <> | 64 | <> |
9 | - <Form style={{ | 65 | + <Form onSubmit={onSubmit} |
66 | + style={{ | ||
10 | width:'100%', | 67 | width:'100%', |
11 | maxWidth:'330px', | 68 | maxWidth:'330px', |
12 | padding:'15px', | 69 | padding:'15px', |
... | @@ -21,18 +78,18 @@ const SigninPage = (props) => { | ... | @@ -21,18 +78,18 @@ const SigninPage = (props) => { |
21 | <h2 className="text-center"><br/>Sign Up</h2> | 78 | <h2 className="text-center"><br/>Sign Up</h2> |
22 | <FormGroup> | 79 | <FormGroup> |
23 | <Label>Username</Label> | 80 | <Label>Username</Label> |
24 | - <Input required="required" type="name" placeholder="Enter your name"></Input> | 81 | + <Input required="required" value={username} onChange={onChangeUsername} name="username" type="name" placeholder="Enter your name"></Input> |
25 | </FormGroup> | 82 | </FormGroup> |
26 | <FormGroup> | 83 | <FormGroup> |
27 | <Label>Password</Label> | 84 | <Label>Password</Label> |
28 | - <Input required="required" type="password" placeholder="Enter your password"></Input> | 85 | + <Input required="required" type="password" value={password} onChange={onChangePassword} name="password" placeholder="Enter your password (length >= 6)"></Input> |
29 | </FormGroup> | 86 | </FormGroup> |
30 | <FormGroup> | 87 | <FormGroup> |
31 | <Label>Confirm Password</Label> | 88 | <Label>Confirm Password</Label> |
32 | - <Input required="required" type="password" placeholder="Enter your password again"></Input> | 89 | + <Input required="required" type="password" value={passwordCheck} onChange={onChangePasswordCheck} name="confirm_password" placeholder="Enter your password again"></Input> |
33 | </FormGroup> | 90 | </FormGroup> |
34 | <FormGroup> | 91 | <FormGroup> |
35 | - <Button className="btn-lg btn-dark btn-block">Sign up</Button> | 92 | + <Button type="submit" className="btn-lg btn-dark btn-block">Sign up</Button> |
36 | </FormGroup> | 93 | </FormGroup> |
37 | 94 | ||
38 | <div className="text-center mt-3"> | 95 | <div className="text-center mt-3"> | ... | ... |
... | @@ -31,11 +31,33 @@ app.get('/api/hello', (req, res) => { | ... | @@ -31,11 +31,33 @@ app.get('/api/hello', (req, res) => { |
31 | res.send('Hello skrrrr!'); | 31 | res.send('Hello skrrrr!'); |
32 | }); | 32 | }); |
33 | 33 | ||
34 | - | 34 | +// datas 전달 |
35 | app.get('/api/datas', (req, res) => { | 35 | app.get('/api/datas', (req, res) => { |
36 | iconv.extendNodeEncodings(); | 36 | iconv.extendNodeEncodings(); |
37 | res.header("Access-Control-Allow-Origin", "*"); | 37 | res.header("Access-Control-Allow-Origin", "*"); |
38 | res.send(iconv.decode(dataBuffer, 'EUC-KR').toString()); | 38 | res.send(iconv.decode(dataBuffer, 'EUC-KR').toString()); |
39 | }) | 39 | }) |
40 | 40 | ||
41 | +// signup | ||
42 | +app.post('/api/signup', (req, res) => { | ||
43 | + let sql = 'INSERT INTO USER (name, pw) VALUES(?, ?)'; | ||
44 | + const params = [req.body.username, req.body.password]; | ||
45 | + connection.query(sql, params, (err, rows, fields) => { | ||
46 | + if(err){ | ||
47 | + console.log(err); | ||
48 | + res.send({ | ||
49 | + "code":400, | ||
50 | + "message": "error" | ||
51 | + }) | ||
52 | + } | ||
53 | + else { | ||
54 | + res.send({ | ||
55 | + "code":200, | ||
56 | + "message": "success" | ||
57 | + }) | ||
58 | + } | ||
59 | + }) | ||
60 | + | ||
61 | +}) | ||
62 | + | ||
41 | app.listen(port, () => console.log(`Listening on port ${port}`)); | 63 | app.listen(port, () => console.log(`Listening on port ${port}`)); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment