Initial setup done
This commit is contained in:
commit
37ce50bc88
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
playground/
|
||||
server.js
|
||||
52
index.js
Normal file
52
index.js
Normal file
@ -0,0 +1,52 @@
|
||||
const path = require('path');
|
||||
const express = require('express');
|
||||
const bodyParser = require('body-parser');
|
||||
|
||||
const Client = require('bitcoin-core');
|
||||
const client = require('./server')
|
||||
|
||||
const crypto = require('crypto');
|
||||
const routes = require('./routes');
|
||||
|
||||
const cookieParser = require('cookie-parser');
|
||||
const session = require('express-session');
|
||||
const flash = require('connect-flash');
|
||||
const validator = require('express-validator');
|
||||
|
||||
const port = process.env.PORT || 3001;
|
||||
|
||||
const app = express();
|
||||
|
||||
app.set('view engine', 'ejs');
|
||||
|
||||
const middleware = [
|
||||
express.static(path.join(__dirname, 'public')),
|
||||
bodyParser.urlencoded({extended:true}),
|
||||
cookieParser(),
|
||||
session({
|
||||
secret: 'super-secret-key',
|
||||
key: 'super-secret-cookie',
|
||||
resave: false,
|
||||
saveUninitialized: false,
|
||||
cookie: { maxAge: 60000 }
|
||||
}),
|
||||
validator(),
|
||||
flash()
|
||||
]
|
||||
|
||||
app.use(middleware);
|
||||
|
||||
app.use('/', routes);
|
||||
|
||||
app.use((req, res,next)=>{
|
||||
res.status(404).send("Page Not Found");
|
||||
});
|
||||
|
||||
app.use((err, req, res, next)=>{
|
||||
console.log(err);
|
||||
res.status(500).send("Page Broke!");
|
||||
});
|
||||
|
||||
app.listen(port, ()=>{
|
||||
console.log("Greetings app running on port "+port);
|
||||
});
|
||||
3239
package-lock.json
generated
Normal file
3239
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
31
package.json
Normal file
31
package.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "flocards",
|
||||
"version": "1.0.0",
|
||||
"description": "A greeting card generating app based on FLO Blockchain",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"browserify": "browserify public/js/main.js -o public/js/bundle.js",
|
||||
"watch": "watchify public/js/main.js -o public/js/bundle.js"
|
||||
},
|
||||
"author": "Abhishek Sinha",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^0.18.0",
|
||||
"bitcoin-core": "^2.0.0",
|
||||
"body-parser": "^1.18.3",
|
||||
"browserify": "^16.2.2",
|
||||
"connect-flash": "^0.1.1",
|
||||
"cookie-parser": "^1.4.3",
|
||||
"ejs": "^2.6.1",
|
||||
"express": "^4.16.3",
|
||||
"express-layout": "^0.1.0",
|
||||
"express-session": "^1.15.6",
|
||||
"express-validator": "^5.3.0",
|
||||
"helmet": "^3.13.0",
|
||||
"html-pdf": "^2.2.0",
|
||||
"lodash": "^4.17.10",
|
||||
"node-fetch": "^2.2.0",
|
||||
"watchify": "^3.11.0"
|
||||
}
|
||||
}
|
||||
0
public/css/main.css
Normal file
0
public/css/main.css
Normal file
BIN
public/images/Diwali2018.jpg
Normal file
BIN
public/images/Diwali2018.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
BIN
public/images/hbd.jpg
Normal file
BIN
public/images/hbd.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
14
public/js/bundle.js
Normal file
14
public/js/bundle.js
Normal file
@ -0,0 +1,14 @@
|
||||
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
|
||||
$(document).on('click', '#bc-btn', function() {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: '/write',
|
||||
success: function(data) {
|
||||
console.log(data);
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
console.log(textStatus, errorThrown);
|
||||
}
|
||||
});
|
||||
});
|
||||
},{}]},{},[1]);
|
||||
12
public/js/main.js
Normal file
12
public/js/main.js
Normal file
@ -0,0 +1,12 @@
|
||||
$(document).on('click', '#bc-btn', function() {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: '/write',
|
||||
success: function(data) {
|
||||
console.log(data);
|
||||
},
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
console.log(textStatus, errorThrown);
|
||||
}
|
||||
});
|
||||
});
|
||||
66
routes.js
Normal file
66
routes.js
Normal file
@ -0,0 +1,66 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const { check, validationResult } = require('express-validator/check')
|
||||
const { matchedData } = require('express-validator/filter')
|
||||
const _ = require('lodash');
|
||||
const fetch = require('node-fetch');
|
||||
const client = require('./server.js');
|
||||
|
||||
var path = require('path')
|
||||
var fs = require('fs');
|
||||
var pdf = require('html-pdf');
|
||||
|
||||
router.get('/', (req, res)=>{
|
||||
res.render('index.ejs', {
|
||||
data: {},
|
||||
errors: {},
|
||||
title: 'Welcome! Select a card of your choice.'
|
||||
})
|
||||
})
|
||||
|
||||
router.get('/write/:card_id', (req, res)=>{
|
||||
res.render('write.ejs', {
|
||||
data: {card_id: req.params.card_id},
|
||||
errors: {},
|
||||
title: 'Write your message'
|
||||
})
|
||||
})
|
||||
|
||||
router.post('/write', [check('_bdata').isLength({min:1}).withMessage('Please write some remarks!').trim(),
|
||||
check('_cardid').isLength({min:1}).withMessage('Could not find the card id!').trim()],
|
||||
(req,res)=>{
|
||||
const errors = validationResult(req)
|
||||
if(!errors.isEmpty()) {
|
||||
return res.render('write', {
|
||||
data: req.body,
|
||||
errors: errors.mapped(),
|
||||
title: 'Please Write your message'
|
||||
})
|
||||
}
|
||||
|
||||
const data = matchedData(req)
|
||||
|
||||
let remarks = data._bdata;
|
||||
let card_id = data._cardid;
|
||||
|
||||
var toaddress = "oXCsMUyX3mLJEdnn8SXoH6gyPW9Jd6kjYu";
|
||||
var amount = 1;
|
||||
|
||||
res.json({"txnid":"zdfjhdzjfhzhfjhzekjhfjhf", "card_id":card_id})
|
||||
// try {
|
||||
// client.sendToAddress(toaddress, amount, "Greetings App", "REBC", false, false, 1, 'UNSET', remarks)
|
||||
// .then((txnid) => {
|
||||
// console.log(txnid)
|
||||
// res.json({"txnid":txnid, "card_id":card_id})
|
||||
// });
|
||||
// }catch(err){
|
||||
// console.log("Unable to send FLO." + err.message);
|
||||
// }
|
||||
|
||||
// req.flash('success', 'Your remarks was successfully entered.')
|
||||
// res.redirect('/')
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
module.exports = router
|
||||
5
server.example.js
Normal file
5
server.example.js
Normal file
@ -0,0 +1,5 @@
|
||||
const Client = require('bitcoin-core');
|
||||
const client = new Client({host: 'localhost', network: 'testnet', username: 'yourusername', password: 'yourpassword', port: 17313
|
||||
});
|
||||
|
||||
module.exports = client;
|
||||
15
templates/test.html
Normal file
15
templates/test.html
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Happy Diwali</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>
|
||||
Happy Diwali to me
|
||||
</h1>
|
||||
<img class="logo" src="{{image}}">
|
||||
</body>
|
||||
</html>
|
||||
23
views/index.ejs
Normal file
23
views/index.ejs
Normal file
@ -0,0 +1,23 @@
|
||||
<% include partials/header.ejs %>
|
||||
|
||||
<div class="container">
|
||||
<div class="card mb-3">
|
||||
<a href="/write/Diwali2018"><img class="card-img-top" src="images/Diwali2018.jpg" alt="Card image cap"></a>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Card title</h5>
|
||||
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
|
||||
<p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<a href="/write/hbd"><<img class="card-img-bottom" src="images/hbd.jpg" alt="Card image cap"></a>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Card title</h5>
|
||||
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
|
||||
<p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<% include partials/footer.ejs %>
|
||||
4
views/partials/footer.ejs
Normal file
4
views/partials/footer.ejs
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
<script src="js/bundle.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
22
views/partials/header.ejs
Normal file
22
views/partials/header.ejs
Normal file
@ -0,0 +1,22 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
<!-- Bootstrap CSS -->
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
||||
|
||||
<title><%=title%></title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-sm bg-primary navbar-dark">
|
||||
<a class="navbar-brand" href="#">Book of Records</a>
|
||||
</nav>
|
||||
|
||||
<ul>
|
||||
<li><a href="/">Home</a></li>
|
||||
<li><a href="/write">Write a remarks</a></li>
|
||||
</ul>
|
||||
32
views/write.ejs
Normal file
32
views/write.ejs
Normal file
@ -0,0 +1,32 @@
|
||||
<% include partials/header.ejs %>
|
||||
|
||||
<div class="container">
|
||||
<div class="form-header">
|
||||
<% if (Object.keys(errors).length === 0) { %>
|
||||
<h2>Please write a review about your experience here:</h2>
|
||||
<% } else { %>
|
||||
<h2 class="errors-heading">Oops, please correct the following:</h2>
|
||||
<ul class="errors-list">
|
||||
<% Object.values(errors).forEach(error => { %>
|
||||
<li><%= error.msg %></li>
|
||||
<% }) %>
|
||||
</ul>
|
||||
<% } %>
|
||||
</div>
|
||||
|
||||
<% if(data.card_id) { %>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="_bdata">Your message:</label>
|
||||
<textarea class="form-control" id="_bdata" name="_bdata"></textarea>
|
||||
|
||||
<input type="hidden" id="_cardid" name="_cardid" value="<%=data.card_id%>" >
|
||||
<br>
|
||||
<button type="submit" class="btn btn-primary" id="bc-btn">Submit</button>
|
||||
</div>
|
||||
|
||||
<%}%>
|
||||
|
||||
</div> <!-- container-->
|
||||
|
||||
<% include partials/footer.ejs %>
|
||||
Loading…
Reference in New Issue
Block a user