Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

switching to username instead of email address

  • Loading branch information...
commit cf21b89179708b9cd591feab451f08c88a0fe706 1 parent 72947c9
@troygoode troygoode authored
View
7 app.js
@@ -1,5 +1,6 @@
var express = require('express')
, easyoauth = require('easy-oauth')
+ , oauthKeys = require('./oauth/keys_file')
, config = {
port: (process.env.PORT || 3001),
secret: (process.env.SECRET || 'i can haz sekrets?'),
@@ -29,7 +30,7 @@ app.configure(function(){
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.session({ secret: config.secret }));
- app.use(easyoauth(require('./oauth/keys_file')))
+ app.use(easyoauth(oauthKeys))
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
@@ -49,11 +50,11 @@ app.helpers({
});
app.dynamicHelpers({
isLoggedIn: function(req){
- return (req.session.auth.user);
+ return req.session.auth.user;
},
hasAdminAccess: function(req){
- return (req.session.auth.user && req.session.auth.user.username === 'SethCarney');
+ return req.session.auth.user && req.session.auth.user.username === 'SethCarney';
}
});
View
0  public/express-lane-client.css → public/css/express-lane-client.css
File renamed without changes
View
4 public/js/app.js
@@ -2,7 +2,7 @@ var authcallback = function(data) {
window.location = window.location;
};
-$('#login').click(function(event){
+$('.login-button').click(function(event){
event.preventDefault();
openEasyOAuthBox('twitter', authcallback);
-});
+});
View
12 repositories/orders.js
@@ -3,8 +3,8 @@ var request = require('request');
module.exports = function(config) {
return {
- find: function(emailAddress, cb){
- var url = config.serverUrl + '/orders';
+ find: function(username, cb){
+ var url = config.serverUrl + '/orders/' + username;
var options = { json: true, method: 'get', url: url };
request(options, function(err, res, body) {
if (err !== null) cb(err);
@@ -12,9 +12,9 @@ module.exports = function(config) {
});
},
- add: function(emailAddress, productsInCart, cb){
- if(!emailAddress || !emailAddress.length){
- cb('no email address');
+ add: function(username, productsInCart, cb){
+ if(!username || !username.length){
+ cb('no username');
return;
}
if(!productsInCart || !productsInCart.length){
@@ -23,7 +23,7 @@ module.exports = function(config) {
}
var order = {
- email: emailAddress,
+ username: username,
products: productsInCart.map(function(productInCart){
return {
_id: productInCart.product._id,
View
4 routes/admin.js
@@ -1,7 +1,8 @@
module.exports = function(app, ordersRepo){
app.get('/admin', function(req, res){
- ordersRepo.find(null, function(err, orders){
+ ordersRepo.find(function(err, orders){
+ if(err) throw err;
res.render('admin', { orders: orders });
});
});
@@ -9,6 +10,7 @@ module.exports = function(app, ordersRepo){
app.post('/admin', function(req, res){
var order_id = req.body.order_id;
ordersRepo.mark_complete(order_id, function(err, order) {
+ if(err) throw err;
res.redirect('/admin');
});
});
View
5 routes/cart.js
@@ -2,6 +2,7 @@ module.exports = function(app, cartRepo, productsRepo){
app.get('/cart', function(req, res){
cartRepo.find(req.session, function(err, productsInCart){
+ if(err) throw err;
res.render('cart', {
cart: productsInCart,
total: productsInCart.reduce(function(previous, current){
@@ -13,7 +14,9 @@ module.exports = function(app, cartRepo, productsRepo){
app.post('/cart/:product_id', function(req, res){
productsRepo.get(req.params.product_id, function(err, product){
+ if(err) throw err;
cartRepo.increment(req.session, product, function(err){
+ if(err) throw err;
res.redirect('/cart');
});
});
@@ -21,7 +24,9 @@ module.exports = function(app, cartRepo, productsRepo){
app.del('/cart/:product_id', function(req, res){
productsRepo.get(req.params.product_id, function(err, product){
+ if(err) throw err;
cartRepo.remove(req.session, product, function(err){
+ if(err) throw err;
res.redirect('/cart');
});
});
View
8 routes/checkout.js
@@ -2,8 +2,11 @@ module.exports = function(app, cartRepo, ordersRepo){
app.post('/orders', function(req, res){
cartRepo.find(req.session, function(err, productsInCart){
- ordersRepo.add(req.session.emailAddress, productsInCart, function(err, order){
+ if(err) throw err;
+ ordersRepo.add(req.session.auth.user.username, productsInCart, function(err, order){
+ if(err) throw err;
cartRepo.empty(req.session, function(err){
+ if(err) throw err;
res.redirect('/orders');
});
});
@@ -11,7 +14,8 @@ module.exports = function(app, cartRepo, ordersRepo){
});
app.get('/orders', function(req, res){
- ordersRepo.find(req.session.emailAddress, function(err, orders){
+ ordersRepo.find(req.session.auth.user.username, function(err, orders){
+ if(err) throw err;
res.render('orders', {orders: orders});
});
});
View
11 routes/product.js
@@ -1,14 +1,15 @@
module.exports = function(app, productsRepo){
app.get('/', function(req, res){
- productsRepo.find(function(err, products){
- if (err !== null) products = [];
- res.render('products', {products: products});
- });
+ productsRepo.find(function(err, products){
+ if(err) throw err;
+ res.render('products', {products: products});
+ });
});
- app.get('/products/:product_id', function(req, res){
+ app.get('/products/:product_id', function(req, res, next){
productsRepo.get(req.params.product_id, function(err, product){
+ if(err) throw err;
res.render('product', {product: product});
});
});
View
6 views/cart.jade
@@ -31,11 +31,15 @@ block content
else
p: em Your shopping cart is empty.
- if cart.length
+ if cart.length && isLoggedIn
form(action='/orders', method='POST')
div.buttons
a.btn(href='/') Continue Shopping
input.btn.btn-success(type='submit', value='Checkout')
+ else if cart.length
+ a.btn(href='/') Continue Shopping
+ span.btn.login-button Login
+ span You must login in order to checkout.
else
div.buttons
a.btn(href='/') Continue Shopping
View
4 views/layout.jade
@@ -11,7 +11,7 @@ html(lang='en')
style
body{ padding-top: 60px; } /* 60px to make the container go all the way to the bottom of the topbar */
link(rel='stylesheet', href='/bootstrap/css/bootstrap-responsive.min.css')
- link(rel='stylesheet', href='/express-lane-client.css')
+ link(rel='stylesheet', href='/css/express-lane-client.css')
body
.navbar.navbar-fixed-top
@@ -31,7 +31,7 @@ html(lang='en')
li: a(href='/admin') Admin
li: a(href='/logout') Logout
else
- li: a(href='/auth/twitter', id='login') Login
+ li: a.login-button(href='/auth/twitter') Login
block content
Please sign in to comment.
Something went wrong with that request. Please try again.