-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from LizaHCarter/usersetup
Usersetup
- Loading branch information
Showing
23 changed files
with
411 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
var Item = require('../models/item'); | ||
|
||
exports.create = function(req, res){ | ||
req.body.ownerId = res.locals.user._id; | ||
Item.create(req.body, function(){ | ||
res.redirect('/profile'); | ||
}); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,22 @@ | ||
'use strict'; | ||
|
||
var bcrypt = require('bcrypt'), | ||
Mongo = require('mongodb'); | ||
var Mongo = require('mongodb'); | ||
|
||
function User(){ | ||
function Bid(){ | ||
} | ||
|
||
Object.defineProperty(User, 'collection', { | ||
get: function(){return global.mongodb.collection('users');} | ||
Object.defineProperty(Bid, 'collection', { | ||
get: function(){return global.mongodb.collection('bids');} | ||
}); | ||
|
||
User.findById = function(id, cb){ | ||
var _id = Mongo.ObjectID(id); | ||
User.collection.findOne({_id:_id}, cb); | ||
}; | ||
|
||
User.register = function(o, cb){ | ||
User.collection.findOne({email:o.email}, function(err, user){ | ||
if(user){return cb();} | ||
o.password = bcrypt.hashSync(o.password, 10); | ||
User.collection.save(o, cb); | ||
}); | ||
Bid.countItemBids = function(itemId, cb){ | ||
Bid.collection.count({itemUpForBidId:itemId, isOpen:true}, cb); | ||
}; | ||
|
||
User.authenticate = function(o, cb){ | ||
User.collection.findOne({email:o.email}, function(err, user){ | ||
if(!user){return cb();} | ||
var isOk = bcrypt.compareSync(o.password, user.password); | ||
if(!isOk){return cb();} | ||
cb(user); | ||
}); | ||
Bid.findById = function(id, cb){ | ||
var _id = Mongo.ObjectID(id); | ||
Bid.collection.findOne({_id:_id}, cb); | ||
}; | ||
|
||
module.exports = User; | ||
module.exports = Bid; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,49 @@ | ||
'use strict'; | ||
|
||
var bcrypt = require('bcrypt'), | ||
Mongo = require('mongodb'); | ||
|
||
function User(){ | ||
var Mongo = require('mongodb'), | ||
async = require('async'), | ||
Bid = require('./bid'); | ||
|
||
function Item(o){ | ||
this.name = o.name; | ||
this.location = o.location; | ||
this.lat = o.lat * 1; | ||
this.lng = o.lng * 1; | ||
this.description = o.description; | ||
this.tags = o.tags.split(',').map(function(s){return s.trim();}); | ||
this.photo = o.photo; | ||
this.ownerId = o.ownerId; | ||
this.isBiddable = false; | ||
this.onSale = false; | ||
this.datePosted = new Date(); | ||
} | ||
|
||
Object.defineProperty(User, 'collection', { | ||
get: function(){return global.mongodb.collection('users');} | ||
Object.defineProperty(Item, 'collection', { | ||
get: function(){return global.mongodb.collection('items');} | ||
}); | ||
|
||
User.findById = function(id, cb){ | ||
Item.findById = function(id, cb){ | ||
var _id = Mongo.ObjectID(id); | ||
User.collection.findOne({_id:_id}, cb); | ||
Item.collection.findOne({_id:_id}, cb); | ||
}; | ||
|
||
User.register = function(o, cb){ | ||
User.collection.findOne({email:o.email}, function(err, user){ | ||
if(user){return cb();} | ||
o.password = bcrypt.hashSync(o.password, 10); | ||
User.collection.save(o, cb); | ||
Item.findAllForUser = function(userId, cb){ | ||
Item.collection.find({ownerId:userId}).toArray(function(err, items){ | ||
async.map(items, getNumberOfBids, cb); | ||
}); | ||
}; | ||
|
||
User.authenticate = function(o, cb){ | ||
User.collection.findOne({email:o.email}, function(err, user){ | ||
if(!user){return cb();} | ||
var isOk = bcrypt.compareSync(o.password, user.password); | ||
if(!isOk){return cb();} | ||
cb(user); | ||
}); | ||
Item.create = function(data, cb){ | ||
var i = new Item(data); | ||
Item.collection.save(i, cb); | ||
}; | ||
|
||
module.exports = User; | ||
module.exports = Item; | ||
|
||
function getNumberOfBids(item, cb){ | ||
Bid.countItemBids(item._id, function(err, count){ | ||
item.numBids = count; | ||
cb(null, item); | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
@base: #f938ab; | ||
|
||
body{ | ||
background-color: saturate(@base, 5%); | ||
} | ||
|
||
.profile-photo { | ||
height: 200px; | ||
width: 150px; | ||
background-size: cover; | ||
} | ||
|
||
.item-photo { | ||
height: 100px; | ||
width: 100px; | ||
background-size: cover; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* jshint unused:false, camelcase:false */ | ||
/* global google */ | ||
|
||
(function(){ | ||
'use strict'; | ||
|
||
$(document).ready(function(){ | ||
$('button[type=submit]').click(geocodeAndSubmit); | ||
}); | ||
|
||
function geocodeAndSubmit(e){ | ||
var location = $('input[name=location]').val(); | ||
geocode(location, function(name, lat, lng){ | ||
$('input[name=location]').val(name); | ||
$('form').append('<input name="lat" value="'+lat+'" type="hidden">'); | ||
$('form').append('<input name="lng" value="'+lng+'" type="hidden">'); | ||
$('form').submit(); | ||
}); | ||
e.preventDefault(); | ||
} | ||
|
||
function geocode(address, cb){ | ||
var geocoder = new google.maps.Geocoder(); | ||
geocoder.geocode({address:address}, function(results, status){ | ||
//console.log('results', results); | ||
var name = results[0].formatted_address, | ||
lat = results[0].geometry.location.lat(), | ||
lng = results[0].geometry.location.lng(); | ||
cb(name, lat, lng); | ||
}); | ||
} | ||
|
||
})(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.