김건희

[Update] Register Files

This diff is collapsed. Click to expand it.
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
9 "cors": "^2.8.5", 9 "cors": "^2.8.5",
10 "express": "^4.18.1", 10 "express": "^4.18.1",
11 "http-proxy-middleware": "^2.0.6", 11 "http-proxy-middleware": "^2.0.6",
12 + "mongoose": "^6.3.4",
12 "nodemon": "^2.0.16", 13 "nodemon": "^2.0.16",
13 "react": "^18.1.0", 14 "react": "^18.1.0",
14 "react-dom": "^18.1.0", 15 "react-dom": "^18.1.0",
...@@ -19,7 +20,8 @@ ...@@ -19,7 +20,8 @@
19 "start": "react-scripts start", 20 "start": "react-scripts start",
20 "build": "react-scripts build", 21 "build": "react-scripts build",
21 "test": "react-scripts test", 22 "test": "react-scripts test",
22 - "eject": "react-scripts eject" 23 + "eject": "react-scripts eject",
24 + "server": "node server.js"
23 }, 25 },
24 "eslintConfig": { 26 "eslintConfig": {
25 "extends": [ 27 "extends": [
......
...@@ -2,9 +2,14 @@ let express = require('express'); ...@@ -2,9 +2,14 @@ let express = require('express');
2 let bodyParser = require('body-parser'); 2 let bodyParser = require('body-parser');
3 let mongoose = require('mongoose'); 3 let mongoose = require('mongoose');
4 4
5 +let cors = require('cors');
5 let app = express(); 6 let app = express();
7 +app.use(cors());
8 +
6 let logid=null; 9 let logid=null;
7 -const uri = 'mongodb+srv://sjieu17:tjrwls147714@cluster0.lc6pe.mongodb.net/weather_briefing?retryWrites=true&w=majority'; 10 +//const uri = 'mongodb+srv://sjieu17:tjrwls147714@cluster0.lc6pe.mongodb.net/weather_briefing?retryWrites=true&w=majority';
11 +const uri = 'mongodb+srv://tahmkench:dkrldnsl7@cluster0.vzipl.mongodb.net/?retryWrites=true&w=majority';
12 +
8 let db = mongoose.connect(uri, (err) => { 13 let db = mongoose.connect(uri, (err) => {
9 if (err) { 14 if (err) {
10 console.log(err.message); 15 console.log(err.message);
...@@ -16,8 +21,8 @@ let db = mongoose.connect(uri, (err) => { ...@@ -16,8 +21,8 @@ let db = mongoose.connect(uri, (err) => {
16 var UserSchema = new mongoose.Schema({ 21 var UserSchema = new mongoose.Schema({
17 name: String, 22 name: String,
18 id: String, 23 id: String,
19 - password: String, 24 + password: String,
20 - gender:Number 25 + gender:String
21 }); 26 });
22 27
23 var Users = mongoose.model('users', UserSchema); 28 var Users = mongoose.model('users', UserSchema);
...@@ -25,25 +30,33 @@ var Users = mongoose.model('users', UserSchema); ...@@ -25,25 +30,33 @@ var Users = mongoose.model('users', UserSchema);
25 app.use(bodyParser.json()); 30 app.use(bodyParser.json());
26 app.use(bodyParser.urlencoded({ limit: '1gb', extended: false })); 31 app.use(bodyParser.urlencoded({ limit: '1gb', extended: false }));
27 32
28 -app.post('/signup', (req, res) => { 33 +app.post('/api/register', (req, res) => {
29 - Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => { 34 +
30 - if (err) return res.status(500).json({ message: '에러가 발생하였습니다.' }); 35 + const new_user = new Users(req.body);
31 - else if (user){
32 - res.send('이미 존재하는 사용자입니다.');
33 - }
34 - else{
35 - var new_user = new Users(req.body);
36 36
37 - new_user.save((err) => { 37 + new_user.save((err) => {
38 - if (err) return res.status(500).json({ message: '회원가입에 실패하였습니다.' }); 38 + if (err) return res.status(500).json({ registerSuccess: false});
39 - else return res.status(200).json({ message: '회원가입이 완료되었습니다.', data: new_user }); 39 + else return res.status(200).json({ registerSuccess: true});
40 - }); 40 + })
41 +
42 + /*Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => {
43 + if (err) return res.status(500).json({ registerSuccess: '-1'});
44 + else if (user){
45 + res.json({ registerSuccess: '0'});
41 } 46 }
42 - }); 47 + else{
48 + const new_user = new Users(req.body);
49 +
50 + new_user.save((err) => {
51 + if (err) return res.status(500).json({ registerSuccess: '-1'});
52 + else return res.status(200).json({ registerSuccess: '1'});
53 + });
54 + }
55 + });*/
43 56
44 }); 57 });
45 58
46 -app.post('/signin', (req, res) => { 59 +app.post('/api/login', (req, res) => {
47 Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => { 60 Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => {
48 if (err) return res.status(500).json({ message: '에러가 발생하였습니다.' }); 61 if (err) return res.status(500).json({ message: '에러가 발생하였습니다.' });
49 else if (user){ 62 else if (user){
...@@ -53,8 +66,10 @@ app.post('/signin', (req, res) => { ...@@ -53,8 +66,10 @@ app.post('/signin', (req, res) => {
53 else return res.status(404).json({ message: '아이디와 비밀번호를 다시 확인해주세요.' }); 66 else return res.status(404).json({ message: '아이디와 비밀번호를 다시 확인해주세요.' });
54 }); 67 });
55 }); 68 });
56 -app.post('/logout',(req,res)=>{ 69 +
70 +app.post('/api/logout',(req,res)=>{
57 logid=null; 71 logid=null;
58 res.send('로그아웃 되었습니다.'); 72 res.send('로그아웃 되었습니다.');
59 }); 73 });
74 +
60 app.listen(4000, () => console.log('Server On 4000')); 75 app.listen(4000, () => console.log('Server On 4000'));
...\ No newline at end of file ...\ No newline at end of file
......