Skip to content

Commit

Permalink
v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
piatra committed Aug 8, 2013
1 parent 7bac569 commit a881865
Show file tree
Hide file tree
Showing 29 changed files with 831 additions and 203 deletions.
36 changes: 32 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,19 @@ app.configure('development', function(){
app.use(express.errorHandler());
});

function requireLogin(req, res, next) {
if (req.session.email) {
next(); // allow the next route to run
} else {
// require the user to log in
res.redirect("/login"); // or render a form, etc.
}
}

app.get('/', routes.index);

app.get('/login', routes.login);

app.post('/user/set/username', user.setUsername);

app.post('/auth/verify', auth.verify);
Expand All @@ -44,7 +55,11 @@ app.get('/auth/createKeyPair', auth.createKeyPair);
app.post('/payswarm/register', auth.registerKey);
app.post('/payswarm/complete', auth.complatePayswarmRegistration);

app.get('/newasset', routes.newasset);

/*
New asset
*/
app.get('/newasset', requireLogin, routes.newasset);
app.post('/newasset/process/', assets.createAssetAndListing);
app.post('/newasset/save', assets.saveAsset);

Expand All @@ -54,16 +69,29 @@ app.get('/assets/:count', assets.getLatestAssets);
app.get('/resign/listing/:id', assets.resignListing);

app.get('/assets/asset/:id', assets.getAsset);

app.get('/assets/asset/:id/purchase', assets.purchase);
app.post('/assets/asset/:id/purchased', assets.purchased);
app.post('/assets/asset/:id/preview', assets.preview);
app.get('/assets/asset/:id/preview', assets.preview);

app.get('/listings/listing/:id', assets.getListing);

app.get('/asset/content/:id', function (req, res){
app.get('/assets/asset/:id/content', function (req, res){
res.end('The content!');
});

app.get('/assets/:id/purchase', assets.purchase);

app.get('/decrypt/:type/:id', assets.decrypt);

app.get('/test', function (req, res){
res.render('test');
});

app.post('/upload', function (req, res) {
console.log(req.files);
res.json(req.files);
});

http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
4 changes: 2 additions & 2 deletions lib/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ module.exports = function (options) {
db.get.asset(query, function (err, doc) {
if (err) {
console.log('Error getting one asset' + err);
cb({});
cb(err, {});
} else {
cb(doc);
cb(null, doc);
}
});
}
Expand Down
1 change: 0 additions & 1 deletion lib/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module.exports = function(opts) {
console.log('Error reading keys: ', err);
} else {
keyPair = JSON.parse(data);
console.log('PRIVATE KEY PEM', keyPair);
payswarm.decrypt(encryptedMessage, {privateKey: keyPair.publicKey.privateKeyPem}, cb);
}
});
Expand Down
6 changes: 3 additions & 3 deletions lib/payswarm.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"publicKey": {
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApJTzBuohTPiqliU5Vu8o\nfVZcRIAR16BCVd1CdY65SGOfQuiN3xsK5T4ZGQQiyAogdpYhiGEqB/wgqNr3Wzjv\nC2jxBHLHsiNRGvWkRFqFA8axlqyTkXlSV9fXKbFX0hwrqSByy4JzaNxGA74wYBtH\n2b1nLEIGPE8biB+hywWADPNWSUO/QYm9LRGYuFbl/ieDB9kF8w+JMyzX3yYI45KS\nd979n2ucMgXZ7zMoY9cQKdnaqYINjtMhSW1oTJ03CY5N1v6y5Fx1G2m8fh+X1Qpl\n23LauzIa4T+wWCv7d34kE1DmQEOShtVc8rvpjp6Qz41HOz/bJSa8DAr3xUxPco9G\nGQIDAQAB\n-----END PUBLIC KEY-----\n",
"privateKeyPem": "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEApJTzBuohTPiqliU5Vu8ofVZcRIAR16BCVd1CdY65SGOfQuiN\n3xsK5T4ZGQQiyAogdpYhiGEqB/wgqNr3WzjvC2jxBHLHsiNRGvWkRFqFA8axlqyT\nkXlSV9fXKbFX0hwrqSByy4JzaNxGA74wYBtH2b1nLEIGPE8biB+hywWADPNWSUO/\nQYm9LRGYuFbl/ieDB9kF8w+JM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Y02eKj2XSrK2g+8yXR4XzgYz\nWmZ2G7pnFIMjSvrWGWwAPB8/zDo7eInWv/OQfspjdY0HQrBJMyBZx0lYOk+uYJMj\nY3Bz9dGp4gB90XDDw0Ey2POp73t+NPtZp/wQbRO0kT3B7BAzxkWy5GfWU0K2iRQz\nCSnhAoGBAMnJ5266sq9ETo0taO15B7pkBLE48+jmLkYMRmu4iHnGYlqJcQxh/evv\nDZ8XbysUGgmT3TcEXqg/lwL8WxXtvqDCOlA7SIncf4tRW1RjcntWfCduWOP8SAe1\n+yXmQQnoqiBCSGswXLFtv3udWCbSJ5rl8e/dKFSMDuDUUXhKLaKK\n-----END RSA PRIVATE KEY-----\n",
"id": "https://dev.payswarm.com/i/webpayments/keys/3"
"id": "https://dev.payswarm.com/i/webpay/keys/1"
},
"owner": "https://dev.payswarm.com/i/webpayments",
"source": "https://dev.payswarm.com/i/webpayments/accounts/primary"
"owner": "https://dev.payswarm.com/i/webpay",
"source": "https://dev.payswarm.com/i/webpay/accounts/primary"
}
9 changes: 8 additions & 1 deletion lib/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ var UserSchema = new Schema({
publicKeyUrl : String,
owner : String,
destination : String,
username: String
username: String,
preferences: {
hasBudget: Boolean
},
purchases: [String]
});

var PayeeSchema = {
Expand Down Expand Up @@ -38,6 +42,8 @@ var AssetSchema = {
},
title: String,
assetContent: String,
assetFiles: [String],
assetPreview: [String],
assetProvider: String,
signature : Object,
assetDescription: String,
Expand All @@ -61,6 +67,7 @@ var ListingSchema = {
payeeRule: Array,
asset: String,
assetHash: String,
_listingHash: String,
license: String,
licenseHash: String,
validFrom: String,
Expand Down
13 changes: 13 additions & 0 deletions lib/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,22 @@ module.exports = function (opts) {
db.get.user(fields, user, cb);
}

function addPurchase (assetId, user, cb) {
get({purchases:1}, user, function (err, user) {
if (err) {
console.log('error retrieving user');
cb(err);
} else {
user.purchases.push(assetId);
user.save(cb);
}
});
}

userUtils.checkUser = checkUser;
userUtils.updateFields = updateFields;
userUtils.get = get;
userUtils.addPurchase = addPurchase;
return userUtils;

};
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@
"mongoose": "~3.6.11",
"q": "~0.9.6",
"underscore": "~1.4.4",
"highlight.js": "~7.3.0"
"highlight.js": "~7.3.0",
"formidable": "~1.0.14"
},
"subdomain": "webpayments",
"engines": {
"node": "0.8.x"
},
"repository" : {
"type" : "git",
"url" : "https://github.com/piatra/webpayments-marketplace"
"repository": {
"type": "git",
"url": "https://github.com/piatra/webpayments-marketplace"
},
"devDependencies": {
"requirejs": "~2.1.6"
}
}
}
Binary file added public/images/bg-gradient-sand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/bg-sand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/payswarm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 7 additions & 3 deletions public/javascripts/event-handlers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
define([
'message',
'event-login',
'event-assets'
], function (message, loginEv, assetsEv) {
'event-assets',
'modal',
'upload'
], function (message, loginEv, assetsEv, modal, upload) {

var verify = {
assertion : function (assertion) {
Expand Down Expand Up @@ -40,7 +42,7 @@ define([
navigator.id.request();
});

$('.js-handler--create-asset').on('submit', assetsEv.create(assetsEv.assetCreated));
// $('.js-handler--create-asset').on('submit', assetsEv.create(assetsEv.assetCreated));

$('.js-handler--change-username').on('submit', assetsEv.create(assetsEv.usernameChanged));

Expand All @@ -51,6 +53,8 @@ define([
}).success(loginEv.displayPayswarmMsg);
}

//$('input[type=file]').on('change', upload.sendFile);

assetsEv.loadLatest($('.container--newest'));

}
Expand Down
72 changes: 72 additions & 0 deletions public/javascripts/upload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
define([], function () {

function readFile (file) {
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {
// FIXME (emit events?)
// Render thumbnail.
var span = document.createElement('span');
span.innerHTML = ['<p><img class="thumb" src="', e.target.result,
'" title="', escape(theFile.name), '"/>',
'<input type="checkbox" id="', escape(theFile.name) ,'">Is this a preview ?</p>'].join('');
$('#preview').html(span);
};
})(file);

// Read in the image file as a data URL.
reader.readAsDataURL(file);
}

function sendFile () {
var formData = new FormData();
var file = this.files[0];
var progress = document.createElement('progress');
progress.value = 0;
progress.max = 100;
progress.innerHTML = '0%'
$(this).replaceWith(progress);

if (file.type.match('image.*')) {
$('button[type=submit]').attr('disabled', true);
readFile(file);
}

var attached = $('.js-handler--filesAttached')[0].innerHTML.split(', ');
attached.push(escape(file.name));
$('.js-handler--filesAttached')[0].innerHTML = attached.join(', ');

formData.append('myFile', file);

var xhr = new XMLHttpRequest();

xhr.open('post', '/upload', true);

xhr.upload.onprogress = function(e) {
if (e.lengthComputable) {
var percentage = (e.loaded / e.total) * 100;
$('progress').attr('value', percentage).text(percentage + '%');
}
};

xhr.onerror = function(e) {
console.log('An error occurred while submitting the form. Maybe your file is too big');
};

xhr.onload = function() {
if (this.status == 200) {
var $fileInput = $('<input type="file" class="topcoat-text-input">');
$('progress').replaceWith($fileInput);
$fileInput.on('change', sendFile);
$('button[type=submit]').attr('disabled', false);
}
};

xhr.send(formData);
}

return {
sendFile: sendFile
}
})
6 changes: 6 additions & 0 deletions public/stylesheets/mixins.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
metrics-reset()
margin 0
padding 0

warningBg = #FFFFBF
var-item__title-color = #0096dd
Loading

0 comments on commit a881865

Please sign in to comment.