Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bernardus Prayoga #31

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: npm start
26 changes: 26 additions & 0 deletions apidoc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## List of Available Endpoints:
- POST /send-notif


### POST /register

#### Request
```json
{
userEmail: string,
}
```
#### Response
- 201
```json
{
message: "Email notif sent!"
}
```

- 500
```json
{
message: "ISE"
}
```
15 changes: 15 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const express = require('express')
const app = express()
const port = process.env.PORT || 3000
const cors = require('cors');
const Controller = require("./controllers/controller");

app.use(cors());
app.use(express.urlencoded({extended:false}));
app.use(express.json());

app.post('/send-notif', Controller.sendNotif);

app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
19 changes: 19 additions & 0 deletions config/firebaseconfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const firebase = require('firebase-admin');

// const firebaseConfig = {
// apiKey: "AIzaSyC-3oiyQY3k0FdKnbu2-WiNMy0_kR0IvJE",
// authDomain: "chat-app-yoga.firebaseapp.com",
// projectId: "chat-app-yoga",
// storageBucket: "chat-app-yoga.appspot.com",
// messagingSenderId: "553639271253",
// appId: "1:553639271253:web:1703ed73b6b9b17002eddc",
// measurementId: "G-ZBMPX8C1BD"
// };

let serviceAccount = require("../serviceAccountFirebase/chat-app-yoga-firebase-adminsdk-c6zfb-061214ae95.json");

firebase.initializeApp({
credential: firebase.credential.cert(serviceAccount)
});
const db = firebase.firestore();
module.exports = {db};
52 changes: 52 additions & 0 deletions controllers/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const {db} = require("../config/firebaseconfig");
const jwt = require("jsonwebtoken");
const bcrypt = require("bcryptjs");
const nodemailer = require("nodemailer")

class Controller {
static sendNotif(req, res) {
try {
const {userEmail} = req.body
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
type: 'OAuth2',
user: "bernarduuuus@gmail.com",
pass: "bernardus",
clientId: "300342072016-kgqpjgkc8n738uvf3evsje6feru3s0oo.apps.googleusercontent.com",
clientSecret: "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",
refreshToken: "1//040_qUCzHRYA3CgYIARAAGAQSNwF-L9IrXVyJ0eiuzH2EFn4YC6iyyaK-l3hpoAuzyy6nBa-EfD6IvGRerEP04imqA6-XfTTNoUE"
}
})

let mailOptions = {
from: "bernarduuuus@gmail.com",
to: userEmail,
subject: 'Register Notif',
text: `Terimakasih sudah daftar di aplikasi YourChat!`
};

transporter.sendMail(mailOptions, function(err, data) {
if (err) {
console.log("Error " + err);
} else {
console.log("Email sent successfully");
}
})

res.status(201).json({
message: "Email notif sent!"
});
} catch (error) {
console.log(error);
const code = 500;
const message = "ISE";

res.status(code).json({
message
})
}
}
}

module.exports = Controller;
Loading