Skip to content
Snippets Groups Projects
Commit 514e3b9c authored by LeeYongJae's avatar LeeYongJae
Browse files

Merge branch 'buy_with_email' into 'master'

Buy with email

See merge request !18
parents ba43b423 fc8bcd0e
No related branches found
No related tags found
1 merge request!18Buy with email
...@@ -11,6 +11,7 @@ var FileStore = require("session-file-store")(session); ...@@ -11,6 +11,7 @@ var FileStore = require("session-file-store")(session);
var bookRouter = require("./routes/books"); var bookRouter = require("./routes/books");
var loginRouter = require("./routes/login"); var loginRouter = require("./routes/login");
var emailRouter = require("./routes/emails"); var emailRouter = require("./routes/emails");
var transactionRouter = require("./routes/transaction");
var app = express(); var app = express();
...@@ -49,6 +50,7 @@ app.use(express.static(path.join(__dirname, "public"))); ...@@ -49,6 +50,7 @@ app.use(express.static(path.join(__dirname, "public")));
app.use("/api/books", bookRouter); app.use("/api/books", bookRouter);
app.use("/api/login", loginRouter); app.use("/api/login", loginRouter);
app.use("/api/emails", emailRouter); app.use("/api/emails", emailRouter);
app.use("/api/transaction", transactionRouter);
// catch 404 and forward to error handler // catch 404 and forward to error handler
app.use(function(req, res, next) { app.use(function(req, res, next) {
......
...@@ -4,9 +4,10 @@ var autoInc = require("mongoose-auto-increment"); ...@@ -4,9 +4,10 @@ var autoInc = require("mongoose-auto-increment");
const TransactionSchema = new Schema({ const TransactionSchema = new Schema({
_id: Number, _id: Number,
buyerid: { type: String }, bookTitle: { type: String },
sellerid: { type: String }, buyerId: { type: String },
ontransaction: { type: Boolean } sellerId: { type: String },
on_transaction: { type: Boolean }
}); });
autoInc.initialize(mongoose.connection); autoInc.initialize(mongoose.connection);
......
...@@ -9,7 +9,7 @@ var userSchema = new Schema({ ...@@ -9,7 +9,7 @@ var userSchema = new Schema({
id: String, id: String,
password: String, password: String,
email: String, email: String,
isLoggedIn: Boolean, phonenumber: String,
create_date: { type: Date, default: Date.now } create_date: { type: Date, default: Date.now }
}); });
......
...@@ -43,7 +43,7 @@ router.post("/", function(req, res) { ...@@ -43,7 +43,7 @@ router.post("/", function(req, res) {
}); });
}); });
// 책 판매 // 책 구매 및 판매
router.post("/:id", function(req, res) { router.post("/:id", function(req, res) {
Book.findById(req.params.id, function(err, book) { Book.findById(req.params.id, function(err, book) {
if (err) { if (err) {
...@@ -51,6 +51,19 @@ router.post("/:id", function(req, res) { ...@@ -51,6 +51,19 @@ router.post("/:id", function(req, res) {
return; return;
} }
console.log(req.body.userId); console.log(req.body.userId);
if (req.body.isBuyer === true) {
// var soldbook = book.seller.shift();
// book.stock--;
// book.save();
console.log(book.seller);
var temp = book.seller.find(element => element.on_transaction === false);
// book.seller.find(
// element => element.on_transaction === false
// ).on_transaction = true;
// book.save();
res.json({ result: temp });
return;
}
book.seller.push({ seller_id: req.body.userId, on_transaction: false }); book.seller.push({ seller_id: req.body.userId, on_transaction: false });
book.stock++; book.stock++;
book.save(); book.save();
......
const express = require('express'); const express = require("express");
const nodemailer = require('nodemailer'); const nodemailer = require("nodemailer");
const router = express.Router(); const router = express.Router();
router.get("", function(req, res, next){ router.post("/", function(req, res, next) {
let email = "hj950000@ajou.ac.kr" console.log("email backend start");
let sellerEmail = req.body.sellerEmail;
let bookTitle = req.body.bookTitle;
let buyerPhoneNumber = req.body.buyerPhoneNumber;
let transporter = nodemailer.createTransport({ let transporter = nodemailer.createTransport({
service: 'gmail', service: "gmail",
auth: { auth: {
user: 'majorbook202@gmail.com', // gmail 계정 아이디를 입력 user: "majorbook202@gmail.com", // gmail 계정 아이디를 입력
pass: 'dnjfdydlf' // gmail 계정의 비밀번호를 입력 pass: "dnjfdydlf" // gmail 계정의 비밀번호를 입력
} }
}); });
let mailOptions = { let mailOptions = {
from: 'majorbook202@gmail.com', // 발송 메일 주소 (위에서 작성한 gmail 계정 아이디) from: "majorbook202@gmail.com", // (위에서 작성한 gmail 계정 아이디)
to: "hj950000@ajou.ac.kr", // 수신 메일 주소 to: sellerEmail, // selleremail
subject: 'MajorBook구매요청이 들어왔습니다.', // 제목 subject: "MajorBook구매요청이 들어왔습니다.", // 제목
text: '올리신 책 ~~에 대한 구매요청이 도착했습니다. 해당 구매자의 전화번호는 ~~입니다.' // 내용 text:
"올리신 책" +
bookTitle +
"에 대한 구매요청이 도착했습니다. 해당 구매자의 전화번호는" +
buyerPhoneNumber +
"입니다." // 내용
}; };
transporter.sendMail(mailOptions, function(error, info){ transporter.sendMail(mailOptions, function(error, info) {
if (error) { if (error) {
console.log(error); console.log(error);
} } else {
else { console.log("Email sent: " + info.response);
console.log('Email sent: ' + info.response);
} }
}); });
}) });
module.exports = router; module.exports = router;
\ No newline at end of file
...@@ -8,7 +8,7 @@ router.post("/signUp", function(req, res, next) { ...@@ -8,7 +8,7 @@ router.post("/signUp", function(req, res, next) {
user.password = req.body.user.password; user.password = req.body.user.password;
user.name = req.body.user.name; user.name = req.body.user.name;
user.email = req.body.user.email; user.email = req.body.user.email;
user.isLoggedIn = req.body.user.isLoggedIn; user.phonenumber = req.body.user.phonenumber;
user.save(function(err) { user.save(function(err) {
if (err) { if (err) {
...@@ -68,4 +68,19 @@ router.get("/getUserId", function(req, res) { ...@@ -68,4 +68,19 @@ router.get("/getUserId", function(req, res) {
} }
}); });
router.post("/getUserInfo", function(req, res) {
console.log("getUserInfo start");
var getInfoId = req.body.userId;
console.log(getInfoId);
User.findOne({ id: getInfoId }, function(err, user) {
if (err) {
res.send(err);
}
if (!user) {
return res.status(404).json({ error: "user not found" });
}
res.json(user);
});
});
module.exports = router; module.exports = router;
const express = require("express");
const router = express.Router();
const Transaction = require("../models/transaction");
router.get("/", function(req, res) {
console.log("Get transaction start");
Transaction.find({}, function(err, transactions) {
if (err) {
res.json({ result: false, message: "Not found transactions" });
return;
}
res.json(transactions);
});
});
router.post("/", function(req, res) {
console.log("Post transaction start");
var transaction = new Transaction();
transaction.buyerId = req.body.buyerId;
console.log(req.body.buyerId);
transaction.sellerId = req.body.sellerId;
console.log(req.body.sellerId);
transaction.bookTitle = req.body.bookTitle;
transaction.on_transaction = true;
transaction.save(function(err) {
if (err) {
console.error(err);
res.json({ result: 0 });
return;
}
res.json({ result: 1 });
});
});
module.exports = router;
...@@ -22,8 +22,7 @@ ...@@ -22,8 +22,7 @@
color="#999" color="#999"
style="float: left; marginLeft: 1%; width: 2%; marginTop:0.1%" style="float: left; marginLeft: 1%; width: 2%; marginTop:0.1%"
v-on:click="Search" v-on:click="Search"
>검색</md-button >검색</md-button>
>
<!-- ==================================================================== --> <!-- ==================================================================== -->
<div v-if="SearchResult === true "> <div v-if="SearchResult === true ">
...@@ -38,10 +37,7 @@ ...@@ -38,10 +37,7 @@
<br /> <br />
<br /> <br />
</div> </div>
<div <div class="md-subhead" style="text-align:left;font-weight: bold;">
class="md-subhead"
style="text-align:left;font-weight: bold;"
>
# 학년: {{ Book.grade }} # 학년: {{ Book.grade }}
<br /> <br />
# 전공: {{ Book.major }} # 전공: {{ Book.major }}
...@@ -57,22 +53,15 @@ ...@@ -57,22 +53,15 @@
</md-card-media> </md-card-media>
</md-card-header> </md-card-header>
<md-card-actions> <md-card-actions>
<md-button <md-button class="md-raised md-accent" v-on:click="goSellPage(Book._id)">Sell</md-button>
class="md-raised md-accent" <md-button class="md-raised md-primary" v-on:click="goBuyPage(Book._id)">Buy Now</md-button>
v-on:click="goSellPage(Book._id)"
>Sell</md-button
>
<md-button class="md-raised md-primary">Buy Now</md-button>
</md-card-actions> </md-card-actions>
</md-card> </md-card>
</div> </div>
</div> </div>
<!-- ============================================= --> <!-- ============================================= -->
<div> <div>
<md-speed-dial <md-speed-dial :class="bottomPosition" style="marginRight:20%; marginBottom:8%">
:class="bottomPosition"
style="marginRight:20%; marginBottom:8%"
>
<md-button class="md-fab md-primary" v-on:click="active = true"> <md-button class="md-fab md-primary" v-on:click="active = true">
<img src="../assets/icon-add.svg" /> <img src="../assets/icon-add.svg" />
</md-button> </md-button>
...@@ -80,10 +69,7 @@ ...@@ -80,10 +69,7 @@
</div> </div>
<!-- ============= 판매도서 submit 양식 ================== --> <!-- ============= 판매도서 submit 양식 ================== -->
<div> <div>
<md-dialog <md-dialog :md-active.sync="active" style="width : 500px; height: 1000px ">
:md-active.sync="active"
style="width : 500px; height: 1000px "
>
<md-dialog-title>판매도서 등록</md-dialog-title> <md-dialog-title>판매도서 등록</md-dialog-title>
<md-field class="select"> <md-field class="select">
<label>책제목</label> <label>책제목</label>
...@@ -102,9 +88,7 @@ ...@@ -102,9 +88,7 @@
<md-input v-model="submit.src"></md-input> <md-input v-model="submit.src"></md-input>
</md-field> </md-field>
<md-dialog-actions> <md-dialog-actions>
<md-button class="md-primary" v-on:click="active = false" <md-button class="md-primary" v-on:click="active = false">Close</md-button>
>Close</md-button
>
<md-button class="md-primary" v-on:click="Register">Submit</md-button> <md-button class="md-primary" v-on:click="Register">Submit</md-button>
</md-dialog-actions> </md-dialog-actions>
</md-dialog> </md-dialog>
...@@ -168,6 +152,9 @@ export default { ...@@ -168,6 +152,9 @@ export default {
}); });
this.active = false; this.active = false;
}, },
goBuyPage(bookId) {
this.$router.push({ name: "BookSearchPageBuy", params: { id: bookId } });
},
goSellPage(bookId) { goSellPage(bookId) {
this.$router.push({ name: "BookSearchPageSell", params: { id: bookId } }); this.$router.push({ name: "BookSearchPageSell", params: { id: bookId } });
} }
......
<template>
<div>
<md-card
style="width: 50%; margin: 4px; marginTop:100px; display: inline-block; vertical-align: top;"
>
<md-card-header>
<md-card-header-text>
<div class="md-title">
{{ book.title }}
<br />
<br />
</div>
<div class="md-subhead" style="text-align:left; font-weight:bold;">
# 학년: {{ book.grade }}
<br />
# 전공: {{ book.major }}
<br />
# 세부사항: {{ book.type }}
<br />
# 매물: {{ book.stock }}
<br />
</div>
</md-card-header-text>
<md-card-media md-medium>
<img v-bind:src="book.src" />
</md-card-media>
</md-card-header>
</md-card>
<md-card
style="width: 50%; margin: 4px; marginTop:100px; display: inline-block; vertical-align: top;"
>
<md-card-header>
<div class="md-title">이 책을 구매하시겠습니까?</div>
</md-card-header>
<md-card-actions>
<md-button class="md-raised md-primary" v-on:click="buyBook">구매</md-button>
</md-card-actions>
</md-card>
</div>
</template>
<script>
import Vue from "vue";
import VueMaterial from "vue-material";
import Multiselect from "vue-multiselect";
import "vue-material/dist/vue-material.min.css";
import "vue-material/dist/theme/default.css";
Vue.use(VueMaterial);
export default {
data() {
return {
buyer: {},
seller: {},
book: {},
userId: "",
sellerId: ""
};
},
created() {
var id = this.$route.params.id;
this.$http.get(`/api/books/${id}`).then(response => {
this.book = response.data;
});
},
methods: {
buyBook() {
this.$http.get("/api/login/getUserId").then(response => {
console.log("rd" + response.data);
this.userId = response.data;
var id = this.$route.params.id;
console.log("user:" + this.userId);
this.$http
.post(`/api/books/${id}`, {
userId: this.userId,
isBuyer: true
})
.then(
res => {
console.log(res.data);
this.sellerId = res.data.result.seller_id;
this.$http
.post("/api/transaction", {
buyerId: this.userId,
sellerId: this.sellerId,
bookTitle: this.book.title
})
.then(response => {
console.log("buy.vue-transaction post");
alert("구매에 성공하였습니다. 판매자에게 메일을 보냅니다.");
this.sendEmail();
});
},
error => {
alert(error.response.data.error);
}
)
.catch(error => {
alert(error);
});
});
},
sendEmail() {
console.log("sendEmail start");
this.$http
.post("/api/login/getUserInfo", {
userId: this.userId // buyer
})
.then(response => {
this.buyer = response.data;
});
this.$http
.post("/api/login/getUserInfo", {
userId: this.sellerId
})
.then(response => {
this.seller = response.data;
});
this.$http
.post("/api/emails", {
sellerEmail: this.seller.email,
bookTitle: this.book.title,
buyerPhoneNumber: this.buyer.phonenumber
})
.then(response => {
alert("이메일 전송 완료");
}),
error => {
alert(error.response.data.error);
};
}
}
};
</script>
\ No newline at end of file
...@@ -31,14 +31,10 @@ ...@@ -31,14 +31,10 @@
style="width: 50%; margin: 4px; marginTop:100px; display: inline-block; vertical-align: top;" style="width: 50%; margin: 4px; marginTop:100px; display: inline-block; vertical-align: top;"
> >
<md-card-header> <md-card-header>
<div class="md-title"> <div class="md-title">이 책을 판매하시겠습니까?</div>
이 책을 판매하시겠습니까?
</div>
</md-card-header> </md-card-header>
<md-card-actions> <md-card-actions>
<md-button class="md-raised md-primary" v-on:click="sellBook" <md-button class="md-raised md-primary" v-on:click="sellBook">판매</md-button>
>판매</md-button
>
</md-card-actions> </md-card-actions>
</md-card> </md-card>
</div> </div>
...@@ -64,38 +60,31 @@ export default { ...@@ -64,38 +60,31 @@ export default {
this.$http.get(`/api/books/${id}`).then(response => { this.$http.get(`/api/books/${id}`).then(response => {
this.book = response.data; this.book = response.data;
}); });
// this.$http.get("/api/login/getUserId").then(response => {
// console.log("getUserIDstart");
// this.userId = response.data;
// });
}, },
methods: { methods: {
getId() { sellBook() {
this.$http.get("/api/login/getUserId").then(response => { this.$http.get("/api/login/getUserId").then(response => {
console.log("rd" + response.data); console.log("rd" + response.data);
this.userId = response.data; this.userId = response.data;
var id = this.$route.params.id;
console.log("user:" + this.userId);
this.$http
.post(`/api/books/${id}`, {
userId: this.userId
})
.then(
response => {
alert("판매 대기열에 등록하였습니다.");
//this.$router.push("home");
},
error => {
alert(error.response.data.error);
}
)
.catch(error => {
alert(error);
});
}); });
},
sellBook() {
var id = this.$route.params.id;
this.getId();
console.log("user:" + this.userId);
this.$http
.post(`/api/books/${id}`, {
userId: this.userId
})
.then(
response => {
alert("판매 대기열에 등록하였습니다.");
//this.$router.push("home");
},
error => {
alert(error.response.data.error);
}
)
.catch(error => {
alert(error);
});
} }
} }
}; };
......
...@@ -23,12 +23,13 @@ ...@@ -23,12 +23,13 @@
<md-input name="email" v-model="user.email" /> <md-input name="email" v-model="user.email" />
</md-field> </md-field>
<md-button class="md-raised md-primary" v-on:click="signUp" <md-field class="select">
>Sign Up</md-button <label for="phonenumber">Phone Number</label>
> <md-input name="phonenumber" v-model="user.phonenumber" />
<md-button class="md-primary" v-on:click="active = false" </md-field>
>Close</md-button
> <md-button class="md-raised md-primary" v-on:click="signUp">Sign Up</md-button>
<md-button class="md-primary" v-on:click="active = false">Close</md-button>
</md-dialog> </md-dialog>
</div> </div>
</template> </template>
...@@ -60,7 +61,7 @@ export default { ...@@ -60,7 +61,7 @@ export default {
password: "", password: "",
name: "", name: "",
email: "", email: "",
isLoggedIn: false phonenumber: ""
}, },
sending: false, sending: false,
active: false active: false
...@@ -79,7 +80,7 @@ export default { ...@@ -79,7 +80,7 @@ export default {
this.active = false; this.active = false;
} }
if (response.data.result === 1) { if (response.data.result === 1) {
alert("Success"); alert("Success Sign Up !");
this.active = false; this.active = false;
} }
}) })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment