-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
154 lines (121 loc) · 3.53 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
const express = require("express")
const bodyParser = require("body-parser")
const https = require("https")
const cors = require('cors')
const app = express()
//const OpenAIapi = require("openai")
//const Configuration = require("openai")
/*import OpenAIapi from "openai";
import {config} from "dotenv";
config()
import express from "express";
import bodyParser from "body-parser";
import https from 'https';
import cors from "cors";*/
app.use(bodyParser.urlencoded({extended:true}))
app.use(express.static("public"))
app.use(cors())
app.use(bodyParser.json())
app.get('/sendEmail', (req,res)=>{
//res.sendFile(__dirname + "/index.html") //display on the browse web page
const email = {
email:''
}
res.send(email)
})
app.post('/sendEmail' , (req,res)=>{
const email = req.body.email
var api_key = 'c2f78883d5a33c5a2c84020e370ce197-c30053db-51a6393a';
var domain = 'sandbox2b04097476d841a38b2f8648b5e93afe.mailgun.org';
var mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});
var data = {
from: 'SIT313 <[email protected]>',
to: email,
subject: 'SIT313 project',
text: 'Welcome!'
};
console.log(data)
mailgun.messages().send(data, function (error, body) {
if(error){
console.log(error);
}
console.log(body);
});
})
app.get('/login', (req,res)=>{
const user = {
username:"Deakin",
password:"123"
}
res.send(user)
})
app.post('/login' , (req,res)=>{
const password = req.body.password
const username = req.body.username
const data = {
email_address : username,
password : password
}
console.log(data)
})
/*const configuration = new Configuration({
organization: "org-CMdBrDyhS7AYNLBllVzJGK9m",
apiKey: "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"
});*/
/*const openai = new OpenAIapi({
apiKey: process.env.OPENAI_API_KEY
});
app.get('/chatgpt', (req,res)=>{
const resume = {
resume:''
}
res.send(resume)
})
app.post("/chatgpt", async(req,res) => {
const resume = req.body.resume;
const result = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [
{
role: "system",
content: "You are a EbereGPT. You can help with graphic design tasks",
},
resume,
],
});
res.json({
output: result.data.choices[0].message,
})
});*/
const generateCode = () => Math.random().toString(36).substring(2, 12);
let code = generateCode();
app.post("/sendCode", (req, res) => {
const email = req.body.email
var api_key = 'c2f78883d5a33c5a2c84020e370ce197-c30053db-51a6393a';
var domain = 'sandbox2b04097476d841a38b2f8648b5e93afe.mailgun.org';
var mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});
var data = {
from: 'SIT313 <[email protected]>',
to: email,
subject: 'SIT313 project',
text: 'verify code: ' + code,
};
console.log(data)
mailgun.messages().send(data, function (error, body) {
if(error){
console.log(error);
}
console.log(body);
});
})
app.post("/verification", (req, res) => {
if (code === req.body.code) {
return res.json({ message: "You're verified successfully" });
}
res.json({
error_message: "Incorrect credentials",
});
});
app.listen(process.env.PORT || 3007, function (request, response){
console.log("Server is running on port 3007")
} )