-
Notifications
You must be signed in to change notification settings - Fork 42
/
app.coffee
100 lines (82 loc) · 2.64 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
express = require('express')
path = require('path')
engines = require('consolidate')
passport = require('./passport')
calculator = require("./routes/calculator")
sessions = require("./routes/sessions")(passport)
transactions = require("./routes/transactions")
users = require("./routes/users")(sessions)
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: 'vanbtc.sid'))
app.use(passport.initialize())
app.use(passport.session())
app.use(app.router)
routes =
"/": 'main/index'
"/about": 'main/about'
"/digibtc": 'main/digibtc'
"/exchangers": 'main/exchangers'
"/exchangers/join": 'main/join'
"/merchants": 'main/merchants'
"/merchants/signup": 'main/signup'
"/contact": 'main/contact'
for route, view of routes
((route, view) ->
app.get(route, (req, res) ->
res.render(view,
js: (-> global.js),
css: (-> global.css),
layout: 'layout'
)
)
)(route, view)
authorize = (req, res, next) ->
if req.params.user is req.user?.username or
req.user?.username is 'admin'
return next()
res.redirect('/login')
app.get('/deposit', (req, res) ->
res.render('main/deposit',
js: (-> global.js),
css: (-> global.css)
)
)
app.get('/issue/:amount', (req, res) ->
exec = require('child_process').exec
exec("opentxs writecheque --myacct issuer --args \"memo \\\"Here's some OT-Bitcoins.\\\" amount #{req.params.amount} validfor 2592000\"", (err, out, stderr) ->
res.write(out)
res.end()
)
)
app.get('/setup', calculator.new)
app.get('/calculator', calculator.show)
app.get('/ticker', calculator.ticker)
app.get('/login', sessions.new)
app.post('/login', sessions.create)
app.get('/logout', sessions.destroy)
app.get('/:user/exists', users.exists)
app.get('/:user.json', users.json)
app.get('/:user', users.show)
app.get('/users/new', users.new)
app.post('/users', users.create)
app.get('/:user/edit', authorize, users.edit)
app.post('/:user/update', authorize, users.update)
app.get('/:user/transactions.json', authorize, transactions.json)
app.post('/:user/transactions', authorize, transactions.create)
app.get('/:user/report', authorize, transactions.index)
app.use((err, req, res, next) ->
res.status(500)
console.log(err)
res.end()
)
app.listen(3000)