@feardread/fear 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FEAR.js +76 -63
- package/FEARServer.js +290 -20
- package/controllers/address.js +9 -0
- package/controllers/auth/index.js +498 -92
- package/controllers/auth/password.js +237 -0
- package/controllers/order.js +0 -1
- package/controllers/payment.js +5 -142
- package/libs/db/index.js +5 -0
- package/libs/emailer/info.js +22 -34
- package/libs/emailer/smtp.js +511 -65
- package/libs/passport/index.js +137 -0
- package/libs/passport.js +22 -0
- package/libs/paypal/index.js +82 -0
- package/libs/stripe/index.js +306 -0
- package/libs/validator/index.js +2 -2
- package/models/address.js +37 -0
- package/models/blog.js +947 -17
- package/models/brand.js +205 -8
- package/models/category.js +498 -7
- package/models/events.js +1 -0
- package/models/order.js +29 -154
- package/models/payment.js +18 -79
- package/models/user.js +116 -49
- package/package.json +1 -1
- package/routes/address.js +16 -0
- package/routes/auth.js +9 -3
- package/routes/mail.js +10 -165
- package/routes/order.js +7 -4
- package/routes/password.js +17 -0
- package/routes/payment.js +4 -7
- package/routes/paypal.js +12 -0
- package/routes/stripe.js +27 -0
- package/libs/passport/passport.js +0 -109
- /package/routes/{events.js → event.js} +0 -0
package/routes/mail.js
CHANGED
|
@@ -1,170 +1,15 @@
|
|
|
1
|
-
const smtp = require("../libs/emailer/smtp");
|
|
2
|
-
const mailinfo = require("../libs/emailer/info");
|
|
3
|
-
const Mail = new smtp(mailinfo);
|
|
4
1
|
|
|
5
|
-
module.exports = ( fear ) => {
|
|
6
|
-
const router = fear.createRouter();
|
|
7
|
-
|
|
8
|
-
router.get('/', (req, res) => {
|
|
9
|
-
Mail.sendEmail()
|
|
10
|
-
.then((response) => res.send(response.message))
|
|
11
|
-
.catch((error) => res.status(500).send(error.message));
|
|
12
|
-
});
|
|
13
2
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
});
|
|
3
|
+
module.exports = (fear) => {
|
|
4
|
+
const router = fear.createRouter();
|
|
5
|
+
const handler = fear.getHandler();
|
|
6
|
+
const mailer = fear.getMailer();
|
|
19
7
|
|
|
20
|
-
router.post("/project", (req, res) => {
|
|
21
|
-
Mail.sendProjectEmail(req.body)
|
|
22
|
-
.then((response) => res.json({ success: true, message: response.message }))
|
|
23
|
-
.catch((error) => res.status(500).json({ success: false, message: error.message }))
|
|
24
|
-
})
|
|
25
8
|
|
|
9
|
+
router.post("/send", handler.async(mailer.sendEmail))
|
|
10
|
+
router.post("/contact", handler.async(mailer.sendContactEmail))
|
|
11
|
+
router.post("/project", handler.async(mailer.sendProjectEmail))
|
|
12
|
+
router.post("/subscribe", handler.async(mailer.sendSubscriptionEmail))
|
|
13
|
+
router.post("/test", handler.async(mailer.sendTestEmail));
|
|
26
14
|
return router;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/*
|
|
30
|
-
router.get("/mailboxes", async (req, res) => {
|
|
31
|
-
const imapWorker = new imap.Worker(ServerInfo);
|
|
32
|
-
|
|
33
|
-
await imapWorker.listMailboxes()
|
|
34
|
-
.then((response) => { return res.status(200).json(response); })
|
|
35
|
-
.catch((error) => { throw new Error(error); })
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
// REST Endpoint: List Messages
|
|
39
|
-
router.get("/mailboxes/:mailbox", // specify the name of the mailbox to get messages for
|
|
40
|
-
async (inRequest: Request, inResponse: Response) => {
|
|
41
|
-
try {
|
|
42
|
-
const imapWorker: IMAP.Worker = new IMAP.Worker(serverInfo);
|
|
43
|
-
const messages: IMAP.IMessage[] = await imapWorker.listMessages({
|
|
44
|
-
mailbox: inRequest.params.mailbox // access dynamic value after /mailboxes/
|
|
45
|
-
});
|
|
46
|
-
inResponse.status(200);
|
|
47
|
-
inResponse.json(messages);
|
|
48
|
-
} catch (inError) {
|
|
49
|
-
inResponse.status(400);
|
|
50
|
-
inResponse.send("error");
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
// REST Endpoint: Get a Message
|
|
56
|
-
router.get("/messages/:mailbox/:id",
|
|
57
|
-
async (inRequest: Request, inResponse: Response) => {
|
|
58
|
-
try {
|
|
59
|
-
const imapWorker: IMAP.Worker = new IMAP.Worker(serverInfo);
|
|
60
|
-
const messageBody: string = await imapWorker.getMessageBody({
|
|
61
|
-
mailbox: inRequest.params.mailbox, // the name of the mailbox
|
|
62
|
-
id: parseInt(inRequest.params.id, 10) // the ID of the message (str -> int)
|
|
63
|
-
});
|
|
64
|
-
inResponse.status(200);
|
|
65
|
-
inResponse.send(messageBody); // returned as plain text
|
|
66
|
-
} catch (inError) {
|
|
67
|
-
inResponse.status(400);
|
|
68
|
-
inResponse.send("error");
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
// REST Endpoint: Delete a Message
|
|
74
|
-
// the app.delete() method is used to register this endpoint.
|
|
75
|
-
router.delete("/messages/:mailbox/:id",
|
|
76
|
-
async (inRequest: Request, inResponse: Response) => {
|
|
77
|
-
try {
|
|
78
|
-
const imapWorker: IMAP.Worker = new IMAP.Worker(serverInfo);
|
|
79
|
-
await imapWorker.deleteMessage({
|
|
80
|
-
mailbox: inRequest.params.mailbox,
|
|
81
|
-
id: parseInt(inRequest.params.id, 10)
|
|
82
|
-
});
|
|
83
|
-
inResponse.status(200);
|
|
84
|
-
inResponse.send("ok");
|
|
85
|
-
} catch (inError) {
|
|
86
|
-
inResponse.status(400);
|
|
87
|
-
inResponse.send("error");
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
// REST Endpoint: Send a Message
|
|
93
|
-
// app.post() is used to send a message
|
|
94
|
-
// IMAP protocol: retrieving mailboxes and messages
|
|
95
|
-
// SMTP protocol: send messages
|
|
96
|
-
router.post("/messages",
|
|
97
|
-
async (inRequest: Request, inResponse: Response) => {
|
|
98
|
-
try {
|
|
99
|
-
const smtpWorker: SMTP.Worker = new SMTP.Worker(serverInfo);
|
|
100
|
-
await smtpWorker.sendMessage(inRequest.body);
|
|
101
|
-
inResponse.status(201);
|
|
102
|
-
inResponse.send("ok");
|
|
103
|
-
} catch (inError) {
|
|
104
|
-
inResponse.status(400);
|
|
105
|
-
inResponse.send("error");
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
// REST Endpoint: List Contacts
|
|
111
|
-
router.get("/contacts",
|
|
112
|
-
async (inRequest: Request, inResponse: Response) => {
|
|
113
|
-
try {
|
|
114
|
-
const contactsWorker: Contacts.Worker = new Contacts.Worker();
|
|
115
|
-
const contacts: IContact[] = await contactsWorker.listContacts();
|
|
116
|
-
inResponse.status(200);
|
|
117
|
-
inResponse.json(contacts);
|
|
118
|
-
} catch (inError) {
|
|
119
|
-
inResponse.status(400);
|
|
120
|
-
inResponse.send("error");
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
// REST Endpoint: Add Contact
|
|
126
|
-
router.post("/contacts",
|
|
127
|
-
async (inRequest: Request, inResponse: Response) => {
|
|
128
|
-
try {
|
|
129
|
-
const contactsWorker: Contacts.Worker = new Contacts.Worker();
|
|
130
|
-
const contact: IContact = await contactsWorker.addContact(inRequest.body); // contain a unique identifier
|
|
131
|
-
inResponse.status(201);
|
|
132
|
-
inResponse.json(contact);
|
|
133
|
-
} catch (inError) {
|
|
134
|
-
inResponse.status(400);
|
|
135
|
-
inResponse.send("error");
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
// REST Endpoint: Update Contacts
|
|
141
|
-
router.put("/contacts",
|
|
142
|
-
async (inRequest: Request, inResponse: Response) => {
|
|
143
|
-
try {
|
|
144
|
-
const contactsWorker: Contacts.Worker = new Contacts.Worker();
|
|
145
|
-
const contact: IContact = await contactsWorker.updateContact(inRequest.body);
|
|
146
|
-
inResponse.status(202);
|
|
147
|
-
inResponse.json(contact);
|
|
148
|
-
} catch (inError) {
|
|
149
|
-
inResponse.status(400);
|
|
150
|
-
inResponse.send("error");
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
// REST Endpoint: Delete Contact
|
|
156
|
-
router.delete("/contacts/:id",
|
|
157
|
-
async (inRequest: Request, inResponse: Response) => {
|
|
158
|
-
try {
|
|
159
|
-
const contactsWorker: Contacts.Worker = new Contacts.Worker();
|
|
160
|
-
await contactsWorker.deleteContact(inRequest.params.id); // includes the ID of the contact to delete
|
|
161
|
-
inResponse.status(200);
|
|
162
|
-
inResponse.send("ok");
|
|
163
|
-
} catch (inError) {
|
|
164
|
-
inResponse.status(400);
|
|
165
|
-
inResponse.send("error");
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
);
|
|
169
|
-
*/
|
|
170
|
-
|
|
15
|
+
};
|
package/routes/order.js
CHANGED
|
@@ -5,11 +5,14 @@ module.exports = ( fear ) => {
|
|
|
5
5
|
const handler = fear.getHandler();
|
|
6
6
|
const validator = fear.getValidator();
|
|
7
7
|
|
|
8
|
-
router.get("/all", Order.list);
|
|
9
|
-
router.post("/new", Order.create);
|
|
8
|
+
router.get("/all", handler.async(Order.list));
|
|
9
|
+
router.post("/new", handler.async(Order.create));
|
|
10
|
+
router.post("/create", handler.async(Order.create));
|
|
11
|
+
|
|
10
12
|
router.route('/:id')
|
|
11
|
-
.
|
|
12
|
-
.
|
|
13
|
+
.post(handler.async(Order.update))
|
|
14
|
+
.get(handler.async(Order.read))
|
|
15
|
+
.put(handler.async(Order.update));
|
|
13
16
|
|
|
14
17
|
router.get("/myOrders", Order.getMyOrders);
|
|
15
18
|
router.get("/monthly", Order.getMonthWiseOrderIncome);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const Password = require("../controllers/auth/password");
|
|
2
|
+
|
|
3
|
+
module.exports = (fear) => {
|
|
4
|
+
const router = fear.createRouter();
|
|
5
|
+
const handler = fear.getHandler();
|
|
6
|
+
|
|
7
|
+
// Forgot password - sends reset email
|
|
8
|
+
router.post('/forgot-password', Password.forgotPasswordToken);
|
|
9
|
+
// Reset password with token
|
|
10
|
+
router.post('/reset-password/:token', Password.resetPassword);
|
|
11
|
+
// Update password (requires authentication) TODO: Add auth middleware
|
|
12
|
+
router.put('/update-password', Password.updatePassword);
|
|
13
|
+
// Verify reset token validity (optional - for frontend validation)
|
|
14
|
+
router.get('/verify-reset-token/:token', Password.verifyResetToken);
|
|
15
|
+
|
|
16
|
+
return router;
|
|
17
|
+
};
|
package/routes/payment.js
CHANGED
|
@@ -5,13 +5,10 @@ module.exports = (fear) => {
|
|
|
5
5
|
const handler = fear.getHandler();
|
|
6
6
|
const validator = fear.getValidator();
|
|
7
7
|
|
|
8
|
-
router.get("/all", Payment.list);
|
|
9
|
-
router.post("/new", Payment.create);
|
|
10
8
|
|
|
11
|
-
router.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
router.get("/all", handler.async(Payment.list));
|
|
10
|
+
router.post("/new", handler.async(Payment.create));
|
|
11
|
+
router.post("/create", handler.async(Payment.create));
|
|
12
|
+
|
|
16
13
|
return router;
|
|
17
14
|
}
|
package/routes/paypal.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
module.exports = ( fear ) => {
|
|
4
|
+
const router = fear.createRouter();
|
|
5
|
+
const handler = fear.getHandler();
|
|
6
|
+
const paypal = fear.getPaypal();
|
|
7
|
+
|
|
8
|
+
router.post('/order', handler.async(paypal.createPayPalOrder))
|
|
9
|
+
router.post('/capture', handler.async(paypal.capturePayPalOrder))
|
|
10
|
+
|
|
11
|
+
return router;
|
|
12
|
+
}
|
package/routes/stripe.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const Payment = require('../controllers/payment');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
module.exports = (fear) => {
|
|
5
|
+
const router = fear.createRouter();
|
|
6
|
+
const validator = fear.getValidator();
|
|
7
|
+
const handler = fear.getHandler();
|
|
8
|
+
const Stripe = fear.stripe;
|
|
9
|
+
|
|
10
|
+
router.post('/intent', handler.async(Stripe.createPaymentIntent));
|
|
11
|
+
router.get('/intent/:id', handler.async(Stripe.retrievePaymentIntent));
|
|
12
|
+
router.post('/intent/:id/cancel', handler.async(Stripe.cancelPaymentIntent));
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
router.post('/customer', handler.async(stripe.createCustomer));
|
|
16
|
+
router.get('/customer/:id', handler.async(stripe.retrieveCustomer));
|
|
17
|
+
router.get('/customers', handler.async(stripe.listCustomers));
|
|
18
|
+
|
|
19
|
+
router.post('/checkout', handler.async(stripe.createCheckoutSession));
|
|
20
|
+
router.post('/subscription', handler.async(stripe.createSubscription));
|
|
21
|
+
router.post('/subscription/:id/cancel', handler.async(stripe.cancelSubscription));
|
|
22
|
+
router.post('/refund', handler.async(stripe.createRefund));
|
|
23
|
+
|
|
24
|
+
//router.post('/webhook', express.raw({ type: 'application/json' }), handler.async(Payment.handleWebhook);
|
|
25
|
+
*/
|
|
26
|
+
return router;
|
|
27
|
+
};
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
// needed for local authentication
|
|
2
|
-
const passport = require("passport");
|
|
3
|
-
const LocalStrategy = require("passport-local").Strategy;
|
|
4
|
-
const FacebookStrategy = require("passport-facebook").Strategy;
|
|
5
|
-
const secret = require("../config/secret");
|
|
6
|
-
const User = require("../models/user");
|
|
7
|
-
const async = require("async");
|
|
8
|
-
const Cart = require("../models/cart");
|
|
9
|
-
|
|
10
|
-
// serialize and deserialize
|
|
11
|
-
passport.serializeUser((user, done) => {
|
|
12
|
-
done(null, user);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
passport.deserializeUser((id, done) => {
|
|
16
|
-
User.findById(id, (err, user) => {
|
|
17
|
-
done(err, user);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
// custom function validate
|
|
22
|
-
exports.isAuthenticated = (req, res, next) => {
|
|
23
|
-
if (req.isAuthenticated()) {
|
|
24
|
-
return next();
|
|
25
|
-
}
|
|
26
|
-
res.redirect("/login");
|
|
27
|
-
};
|
|
28
|
-
// give the middleware a name, and create a new anonymous instance of LocalStrategy
|
|
29
|
-
passport.use(
|
|
30
|
-
"login",
|
|
31
|
-
new LocalStrategy(
|
|
32
|
-
{
|
|
33
|
-
usernameField: "email",
|
|
34
|
-
passwordField: "password",
|
|
35
|
-
passReqToCallback: true,
|
|
36
|
-
},
|
|
37
|
-
(req, email, password, done) => {
|
|
38
|
-
// find a specific email
|
|
39
|
-
User.findOne({ email: email }, (err, user) => {
|
|
40
|
-
// incase of an error return a callback
|
|
41
|
-
if (err) return done(err);
|
|
42
|
-
|
|
43
|
-
if (!user) {
|
|
44
|
-
return done(
|
|
45
|
-
null,
|
|
46
|
-
false,
|
|
47
|
-
req.flash("loginMessage", "No user with such credentials found")
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// compare user provided password and the database one
|
|
52
|
-
if (!user.comparePassword(password)) {
|
|
53
|
-
return done(
|
|
54
|
-
null,
|
|
55
|
-
false,
|
|
56
|
-
req.flash("loginMessage", "Oops! Wrong credentials")
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// return user object
|
|
61
|
-
return done(null, user);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
)
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
passport.use(
|
|
68
|
-
new FacebookStrategy(
|
|
69
|
-
secret.facebook,
|
|
70
|
-
(token, refreshToken, profile, done) => {
|
|
71
|
-
User.findOne({ facebook: profile.id }, (err, user) => {
|
|
72
|
-
if (err) return next(err);
|
|
73
|
-
|
|
74
|
-
if (user) {
|
|
75
|
-
return done(null, user);
|
|
76
|
-
} else {
|
|
77
|
-
async.waterfall([
|
|
78
|
-
(callback) => {
|
|
79
|
-
const newUser = new User();
|
|
80
|
-
newUser.email = profile._json.email;
|
|
81
|
-
newUser.facebook = profile.id;
|
|
82
|
-
newUser.tokens.push({ kind: "facebook", token: token });
|
|
83
|
-
newUser.profile.name = profile.displayName;
|
|
84
|
-
newUser.profile.picture =
|
|
85
|
-
"https://graph.facebook.com/" +
|
|
86
|
-
profile.id +
|
|
87
|
-
"/picture?type=large";
|
|
88
|
-
|
|
89
|
-
newUser.save((err) => {
|
|
90
|
-
if (err) return next(err);
|
|
91
|
-
callback(err, newUser._id);
|
|
92
|
-
});
|
|
93
|
-
},
|
|
94
|
-
(newUser) => {
|
|
95
|
-
const cart = new Cart();
|
|
96
|
-
|
|
97
|
-
cart.owner = newUser._id;
|
|
98
|
-
cart.save((err) => {
|
|
99
|
-
if (err) return done(err);
|
|
100
|
-
return done(err, newUser);
|
|
101
|
-
});
|
|
102
|
-
},
|
|
103
|
-
]);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
)
|
|
108
|
-
);
|
|
109
|
-
|
|
File without changes
|