-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp.coffee
116 lines (96 loc) · 2.93 KB
/
app.coffee
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
express = require('express')
path = require('path')
engines = require('consolidate')
RedisStore = require('connect-redis')(express)
sessionStore = new RedisStore(ttl: 172800)
app = express()
app.enable('trust proxy')
app.engine('html', require('mmm').__express)
app.set('view engine', 'html')
app.set('views', __dirname + '/views')
app.use(express.static(__dirname + '/public'))
app.use(require('connect-assets')(src: 'public'))
app.use(express.bodyParser())
app.use(express.cookieParser())
app.use(express.session(secret: 'weareallmadeofstars', store: sessionStore, key: 'otweb.sid'))
app.use(app.router)
app.get('/', (req, res) ->
res.render('index',
js: (-> global.js),
css: (-> global.css),
layout: "layout"
)
)
### Create New Nym and Register on Vanbtc.ca ###
app.get('/register', (req, res) ->
res.render('register',
js: (-> global.js),
css: (-> global.css),
layout:"layout"
)
)
app.get('/shownyms', (req, res) ->
exec = require('child_process').exec
exec("opentxs shownyms | sed '1,3d'", (err, out, stderr) ->
lines = out.split('\n')
lines.pop()
results = lines.map (line) ->
regex = /(.*) --- (.*)/
match = regex.exec(line)
if match
{"nym": match[1], "label": match[2]}
res.write(JSON.stringify(results))
res.end()
)
)
app.get('/showassets', (req, res) ->
exec = require('child_process').exec
exec("opentxs showassets | sed '1,3d'", (err, out, stderr) ->
lines = out.split('\n')
lines.pop()
results = lines.map (line) ->
regex = /(.*) --- (.*)/
match = regex.exec(line)
if match
{"asset": match[1], "name": match[2]}
res.write(JSON.stringify(results))
res.end()
)
)
app.post('/register', (req, res) ->
exec = require('child_process').exec
exec("echo #{req.body.password} | opentxs newnym --args \"name #{req.body.username}\" && opentxs register --mynym #{req.body.username} --server vancouver" , (err, out, stderr) ->
res.redirect('/newacct')
)
)
### Create Account ###
app.get('/newacct', (req, res) ->
res.render('newacct',
js: (-> global.js),
css: (-> global.css),
layout:"layout"
)
)
### app.post('/newacct', (req, res) ->
exec = require('child_process').exec
exec("opentxs newacct --mynym #{req.body.mynym} --mypurse #{req.body.mypurse} --server vancouver" , (err, out, stderr) ->
exec("opentxs newacct --mynym #{req.body.mynym} --mypurse #{req.body.mypurse} --server vancouver" , (err, out, stderr) ->
res.redirect('/transfer')
)
)
###
### Transfer Funds ###
app.get('/transfer', (req, res) ->
res.render('transfer',
js: (-> global.js),
css: (-> global.css),
layout:"layout"
)
)
app.post('/transfer', (req, res) ->
exec = require('child_process').exec
exec("echo btc | opentxs transfer --myacct #{req.body.myacct} --hisacct #{req.body.hisacct} --args \"amount #{req.body.amount}\"" , (err, out, stderr) ->
res.redirect('/register')
)
)
app.listen(3000)