김건희

[Update] Register Files

This diff is collapsed. Click to expand it.
......@@ -9,6 +9,7 @@
"cors": "^2.8.5",
"express": "^4.18.1",
"http-proxy-middleware": "^2.0.6",
"mongoose": "^6.3.4",
"nodemon": "^2.0.16",
"react": "^18.1.0",
"react-dom": "^18.1.0",
......@@ -19,7 +20,8 @@
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"eject": "react-scripts eject",
"server": "node server.js"
},
"eslintConfig": {
"extends": [
......
......@@ -2,9 +2,14 @@ let express = require('express');
let bodyParser = require('body-parser');
let mongoose = require('mongoose');
let cors = require('cors');
let app = express();
app.use(cors());
let logid=null;
const uri = 'mongodb+srv://sjieu17:tjrwls147714@cluster0.lc6pe.mongodb.net/weather_briefing?retryWrites=true&w=majority';
//const uri = 'mongodb+srv://sjieu17:tjrwls147714@cluster0.lc6pe.mongodb.net/weather_briefing?retryWrites=true&w=majority';
const uri = 'mongodb+srv://tahmkench:dkrldnsl7@cluster0.vzipl.mongodb.net/?retryWrites=true&w=majority';
let db = mongoose.connect(uri, (err) => {
if (err) {
console.log(err.message);
......@@ -16,8 +21,8 @@ let db = mongoose.connect(uri, (err) => {
var UserSchema = new mongoose.Schema({
name: String,
id: String,
password: String,
gender:Number
password: String,
gender:String
});
var Users = mongoose.model('users', UserSchema);
......@@ -25,25 +30,33 @@ var Users = mongoose.model('users', UserSchema);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ limit: '1gb', extended: false }));
app.post('/signup', (req, res) => {
Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => {
if (err) return res.status(500).json({ message: '에러가 발생하였습니다.' });
else if (user){
res.send('이미 존재하는 사용자입니다.');
}
else{
var new_user = new Users(req.body);
app.post('/api/register', (req, res) => {
const new_user = new Users(req.body);
new_user.save((err) => {
if (err) return res.status(500).json({ message: '회원가입에 실패하였습니다.' });
else return res.status(200).json({ message: '회원가입이 완료되었습니다.', data: new_user });
});
new_user.save((err) => {
if (err) return res.status(500).json({ registerSuccess: false});
else return res.status(200).json({ registerSuccess: true});
})
/*Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => {
if (err) return res.status(500).json({ registerSuccess: '-1'});
else if (user){
res.json({ registerSuccess: '0'});
}
});
else{
const new_user = new Users(req.body);
new_user.save((err) => {
if (err) return res.status(500).json({ registerSuccess: '-1'});
else return res.status(200).json({ registerSuccess: '1'});
});
}
});*/
});
app.post('/signin', (req, res) => {
app.post('/api/login', (req, res) => {
Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => {
if (err) return res.status(500).json({ message: '에러가 발생하였습니다.' });
else if (user){
......@@ -53,8 +66,10 @@ app.post('/signin', (req, res) => {
else return res.status(404).json({ message: '아이디와 비밀번호를 다시 확인해주세요.' });
});
});
app.post('/logout',(req,res)=>{
app.post('/api/logout',(req,res)=>{
logid=null;
res.send('로그아웃 되었습니다.');
});
app.listen(4000, () => console.log('Server On 4000'));
\ No newline at end of file
......