From 98a44809dc33e125f92e451a0b5b7cb8bb3fd806 Mon Sep 17 00:00:00 2001
From: Adam Soltys
Date: Tue, 4 Dec 2012 00:32:11 -0800
Subject: Update authentication and exchangers page
---
app.coffee | 71 +++++++++++++++++++++++++------------------------
public/img/adam.jpg | Bin 0 -> 18488 bytes
public/img/jackson.jpg | Bin 0 -> 8130 bytes
public/img/yuri.jpg | Bin 0 -> 4380 bytes
views/about.html | 8 +++---
views/exchangers.html | 35 ++++++++++++++++++++----
views/layout.html | 2 +-
views/user.html | 43 ++++++++++++++++++++++++++++++
8 files changed, 114 insertions(+), 45 deletions(-)
create mode 100644 public/img/adam.jpg
create mode 100644 public/img/jackson.jpg
create mode 100644 public/img/yuri.jpg
create mode 100644 views/user.html
diff --git a/app.coffee b/app.coffee
index e59829a6..615a09cf 100644
--- a/app.coffee
+++ b/app.coffee
@@ -5,14 +5,9 @@ engines = require('consolidate')
passport = require('passport')
bcrypt = require('bcrypt')
db = require("redis").createClient()
-app = express()
+ask = bid = 0
LocalStrategy = require('passport-local').Strategy
-passport.use(new LocalStrategy(
- (username, password, done) ->
- user = username: 'soltysa', password: 'adam'
- return done(null, user)
-))
passport.serializeUser((user, done) ->
done(null, user.username)
@@ -23,6 +18,29 @@ passport.deserializeUser((id, done) ->
done(null, user)
)
+passport.use(new LocalStrategy(
+ (username, password, done) ->
+ bcrypt.hash(password, 12, (err, hash) ->
+ db.hget(username, 'password', (err, result) ->
+ console.log(result)
+ if result
+ bcrypt.compare(password, result, (err, match) ->
+ console.log(match)
+ if match
+ db.hgetall(username, (err, user) ->
+ return done(null, user)
+ )
+ )
+ )
+ )
+ return done(null, false)
+))
+
+ensureAuthenticated = (req, res, next) ->
+ return next() if req.isAuthenticated()
+ res.redirect('/login')
+
+app = express()
app.enable('trust proxy')
app.engine('html', require('mmm').__express)
app.set('view engine', 'html')
@@ -45,11 +63,14 @@ routes =
"/merchants/signup": 'signup'
"/contact": 'contact'
-
for route, view of routes
((route, view) ->
app.get(route, (req, res) ->
- res.render(view, js: (-> global.js), css: (-> global.css), layout: 'layout')
+ res.render(view,
+ js: (-> global.js),
+ css: (-> global.css),
+ layout: 'layout'
+ )
)
)(route, view)
@@ -96,7 +117,7 @@ app.get('/ticker', (req, res) ->
host: 'bitcoincharts.com',
path: "/t/depthcalc.json?symbol=#{req.query.symbol}&type=#{req.query.type}&amount=#{req.query.amount}¤cy=true"
- require('http').get(options, (r) ->
+ http.get(options, (r) ->
r.setEncoding('utf-8')
r.on('data', (chunk) ->
try
@@ -136,28 +157,6 @@ app.post('/login', (req, res, next) ->
)
app.post('/users', (req, res) ->
- if req.body.login
- if req.body.password
- bcrypt.hash(req.body.password, 12, (err, hash) ->
- db.hget(req.body.login, 'password', (err, password) ->
- if password
- bcrypt.compare(req.body.password, password, (err, match) ->
- if match
- req.body.password = password
- db.hmset(req.body.login, req.body, ->
- res.redirect(req.body.login)
- )
- else
- res.redirect(req.body.login)
- )
- else
- req.body.password = hash
- db.hmset(req.body.login, req.body, ->
- res.redirect(req.body.login)
- )
- )
- )
- else
params = []
for k,v of req.body
params.push(encodeURIComponent(k), '=', encodeURIComponent(v), '&')
@@ -165,7 +164,7 @@ app.post('/users', (req, res) ->
res.redirect('calculator?' + params.join(''))
)
-app.post('/:user/transactions', (req, res) ->
+app.post('/:user/transactions', ensureAuthenticated, (req, res) ->
user = req.params.user
db.incr('transactions', (err, id) ->
db.hmset("#{user}:transactions:#{id}", req.body, ->
@@ -178,21 +177,23 @@ app.post('/:user/transactions', (req, res) ->
)
app.get('/calculator', (req, res) ->
+ console.log(req.user)
res.render('calculator',
js: (-> global.js),
css: (-> global.css),
)
)
-app.get('/:user/edit', (req, res) ->
- res.render('index',
+app.get('/:user/edit', ensureAuthenticated, (req, res) ->
+ res.render('user',
user: req.params.user,
js: (-> global.js),
css: (-> global.css)
)
)
-app.get('/:user', (req, res) ->
+app.get('/:user', ensureAuthenticated, (req, res) ->
+ console.log(req.user)
res.render('calculator',
user: req.params.user,
js: (-> global.js),
diff --git a/public/img/adam.jpg b/public/img/adam.jpg
new file mode 100644
index 00000000..de83b261
Binary files /dev/null and b/public/img/adam.jpg differ
diff --git a/public/img/jackson.jpg b/public/img/jackson.jpg
new file mode 100644
index 00000000..08afc7e8
Binary files /dev/null and b/public/img/jackson.jpg differ
diff --git a/public/img/yuri.jpg b/public/img/yuri.jpg
new file mode 100644
index 00000000..48a8d7d2
Binary files /dev/null and b/public/img/yuri.jpg differ
diff --git a/views/about.html b/views/about.html
index b021f8f2..6711c039 100644
--- a/views/about.html
+++ b/views/about.html
@@ -24,7 +24,7 @@
- The software has been designed so that over time, fewer and fewer
+ Over time, fewer and fewer
bitcoins will be created until there are a total of
21 million of them in circulation by the year 2040. Each bitcoin
is divisible up to 8 decimal places, making
@@ -128,15 +128,15 @@
their best interest to avoid the transaction fees
charged by the credit card companies. Transaction
fees end up getting built into the prices we pay for
- goods and services across the board so we're all
- indirectly subsidizing the big banks and credit card companies.
+ goods and services across the board so we're all
+ paying for them indirectly.
diff --git a/views/exchangers.html b/views/exchangers.html
index 35d01b2d..b3d86fa4 100644
--- a/views/exchangers.html
+++ b/views/exchangers.html
@@ -22,17 +22,42 @@
-
-
Adam Soltys
-

+
+
Adam
+
+
+
+
Jackson
+

+
+
+ | Neighbourhood: |
+ Fairview |
+
+
+ | Contact |
+
+
+
+
+
Yuri
+

+
+
+ | Neighbourhood: |
+ West End |
+
+
+ | Contact |
diff --git a/views/layout.html b/views/layout.html
index 072656d0..0e84c667 100644
--- a/views/layout.html
+++ b/views/layout.html
@@ -33,6 +33,6 @@
{{>content}}
-
+