Skip to content

Commit

Permalink
Merge pull request Aryamanz29#70 from abhinavdixit2306/master
Browse files Browse the repository at this point in the history
NewsLetter-Signup
  • Loading branch information
Aryamanz29 authored Oct 9, 2021
2 parents bb190ac + 3a93dee commit 89b2133
Show file tree
Hide file tree
Showing 10 changed files with 943 additions and 0 deletions.
1 change: 1 addition & 0 deletions Newsletter-signup/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions Newsletter-signup/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node app.js
86 changes: 86 additions & 0 deletions Newsletter-signup/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//jshint esversion:6

const express = require("express");

const https = require("https");

const bodyParser = require("body-parser");

const request = require("request");

const app = express();
app.use(express.static("public"));
app.use(bodyParser.urlencoded({extended:true}));
//To use static files in server make folder public
app.get("/", function(req,res){
res.sendFile(__dirname + "/signup.html");
});

app.post("/", function(req,res){
const fName = req.body.firstName;
const lName = req.body.lastName;
const email = req.body.email;

const data = {

members : [
{
email_address : email,
status : "subscribed",
merge_fields: {
FNAME : fName,
LNAME : lName
}



}
]
};

const jsonData = JSON.stringify(data);

const url = "https://us19.api.mailchimp.com/3.0/lists/dd914356a0";
const options = {
method: "POST",
auth: "abhinav:974eae1ad8cf0f603ee368e6565815a7-us19"
}

const request = https.request(url, options, function(response){

if(response.statusCode === 200){
res.sendFile(__dirname + "/success.html");
}else{
res.sendFile(__dirname + "/failure.html");
}



response.on("data", function(data){
console.log(JSON.parse(data));

})


});

request.write(jsonData);
request.end();

});

app.post("/failure", function(req,res){
res.redirect("/");
})

app.listen(process.env.PORT || 3000, function(){
console.log("Server is running on port 3000");
});



//api Key
//974eae1ad8cf0f603ee368e6565815a7-us19

//list id
//dd914356a0
22 changes: 22 additions & 0 deletions Newsletter-signup/failure.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Failure</title>

<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
</head>
<body style="background-color: #151719;">
<div class="jumbotron jumbotron-fluid">
<div class="container">
<h1 class="display-4">Uh oh!</h1>
<p class="lead">There is an error, please try again...</p>
<form action="/failure" method="post">
<button class="btn btn-lg btn-warning" type="submit">Try Again</button>
</form>

</div>
</div>
</body>
</html>
Loading

0 comments on commit 89b2133

Please sign in to comment.