diff --git a/server.js b/server.js
index 37f226e..5d6b373 100644
--- a/server.js
+++ b/server.js
@@ -168,7 +168,7 @@ router.get('/raw/:id', ensureAuthenticatedWeb, function(request, response, next)
router.post('/documents', ensureAuthenticatedAPI, function(request, response, next) {
return documentHandler.handlePost(request, response);
});
-// get documents
+
router.get('/documents/:id', ensureAuthenticatedAPI, function(request, response, next) {
if(!request.isAuthenticated()){
response.sendStatus(401);
@@ -181,6 +181,9 @@ router.get('/documents/:id', ensureAuthenticatedAPI, function(request, response,
skipExpire
);
});
+router.get('/users/me', ensureAuthenticatedAPI, function(req, res, next) {
+ return res.json(req.user);
+});
function ensureAuthenticatedWeb(req, res, next) {
if (req.isAuthenticated()) { return next(); }
diff --git a/static/application.css b/static/application.css
index ab90a24..b977168 100644
--- a/static/application.css
+++ b/static/application.css
@@ -120,6 +120,10 @@ textarea {
padding: 10px 15px;
}
+#box4{
+ text-align: center;
+}
+
#box3 .label, #messages li {
color: #fff;
font-weight: bold;
diff --git a/static/application.js b/static/application.js
index f2a8023..883f570 100644
--- a/static/application.js
+++ b/static/application.js
@@ -108,6 +108,10 @@ haste.prototype.setTitle = function(ext) {
document.title = title;
};
+haste.prototype.init = function(){
+ document.body.addEventListener('document.user-loaded', this.userLoaded.bind(this))
+ this.user.get(null)
+}
// Show a message box
haste.prototype.showMessage = function(msg, cls) {
var msgBox = $('
'+msg+'');
@@ -343,6 +347,29 @@ haste.prototype.configureButton = function(options) {
$('#pointer').hide();
});
};
+haste.prototype.user = {
+ get: function(id){
+ if(!id){
+ id = 'me'
+ }
+ $.ajax('/users/' + id , {
+ success:
+ function(res){
+ document.body.dispatchEvent(new CustomEvent('document.user-loaded', {'detail': {user: res}}))
+ }
+ })
+ }
+}
+
+haste.prototype.userLoaded = function(e){
+ console.log(e.detail.user);
+ if(! (e.detail.user && e.detail.user.photos.length > 0)){
+ throw "error reading user photo"
+ }
+ var user = e.detail.user;
+ var image = user.photos[0].value;
+ $('#box4').append('
')
+}
// Configure keyboard shortcuts for the textarea
haste.prototype.configureShortcuts = function() {
diff --git a/static/application.min.js b/static/application.min.js
index 0fd07b2..9d89d48 100644
--- a/static/application.min.js
+++ b/static/application.min.js
@@ -1 +1 @@
-var haste_document=function(){this.locked=!1};haste_document.prototype.htmlEscape=function(e){return e.replace(/&/g,"&").replace(/>/g,">").replace(/'+e+"");$("#messages").prepend(n),setTimeout(function(){n.slideUp("fast",function(){$(this).remove()})},3e3)},haste.prototype.lightKey=function(){this.configureKey(["new","save"])},haste.prototype.fullKey=function(){this.configureKey(["new","duplicate","twitter","raw"])},haste.prototype.configureKey=function(e){var t,n=0;$("#box2 .function").each(function(){t=$(this);for(n=0;n";$("#linenos").html(t)},haste.prototype.removeLineNumbers=function(){$("#linenos").html(">")},haste.prototype.loadDocument=function(e){var t=e.split(".",2),n=this;n.doc=new haste_document,n.doc.load(t[0],function(e){e?(n.$code.html(e.value),n.setTitle(e.key),n.fullKey(),n.$textarea.val("").hide(),n.$box.show().focus(),n.addLineNumbers(e.lineCount)):n.newDocument()},this.lookupTypeByExtension(t[1]))},haste.prototype.duplicateDocument=function(){if(this.doc.locked){var e=this.doc.data;this.newDocument(),this.$textarea.val(e)}},haste.prototype.lockDocument=function(){var e=this;this.doc.save(this.$textarea.val(),function(t,n){if(t)e.showMessage(t.message,"error");else if(n){e.$code.html(n.value),e.setTitle(n.key);var r="/"+n.key;n.language&&(r+="."+e.lookupExtensionByType(n.language)),window.history.pushState(null,e.appName+"-"+n.key,r),e.fullKey(),e.$textarea.val("").hide(),e.$box.show().focus(),e.addLineNumbers(n.lineCount)}})},haste.prototype.configureButtons=function(){var e=this;this.buttons=[{$where:$("#box2 .save"),label:"Save",shortcutDescription:"control + s",shortcut:function(e){return e.ctrlKey&&e.keyCode===83},action:function(){e.$textarea.val().replace(/^\s+|\s+$/g,"")!==""&&e.lockDocument()}},{$where:$("#box2 .new"),label:"New",shortcut:function(e){return e.ctrlKey&&e.keyCode===78},shortcutDescription:"control + n",action:function(){e.newDocument(!e.doc.key)}},{$where:$("#box2 .duplicate"),label:"Duplicate & Edit",shortcut:function(t){return e.doc.locked&&t.ctrlKey&&t.keyCode===68},shortcutDescription:"control + d",action:function(){e.duplicateDocument()}},{$where:$("#box2 .raw"),label:"Just Text",shortcut:function(e){return e.ctrlKey&&e.shiftKey&&e.keyCode===82},shortcutDescription:"control + shift + r",action:function(){window.location.href="/raw/"+e.doc.key}},{$where:$("#box2 .twitter"),label:"Twitter",shortcut:function(t){return e.options.twitter&&e.doc.locked&&t.shiftKey&&t.ctrlKey&&t.keyCode==84},shortcutDescription:"control + shift + t",action:function(){window.open("https://twitter.com/share?url="+encodeURI(window.location.href))}}];for(var t=0;t/g,">").replace(/'+e+"");$("#messages").prepend(n),setTimeout(function(){n.slideUp("fast",function(){$(this).remove()})},3e3)},haste.prototype.lightKey=function(){this.configureKey(["new","save"])},haste.prototype.fullKey=function(){this.configureKey(["new","duplicate","twitter","raw"])},haste.prototype.configureKey=function(e){var t,n=0;$("#box2 .function").each(function(){t=$(this);for(n=0;n";$("#linenos").html(t)},haste.prototype.removeLineNumbers=function(){$("#linenos").html(">")},haste.prototype.loadDocument=function(e){var t=e.split(".",2),n=this;n.doc=new haste_document,n.doc.load(t[0],function(e){e?(n.$code.html(e.value),n.setTitle(e.key),n.fullKey(),n.$textarea.val("").hide(),n.$box.show().focus(),n.addLineNumbers(e.lineCount)):n.newDocument()},this.lookupTypeByExtension(t[1]))},haste.prototype.duplicateDocument=function(){if(this.doc.locked){var e=this.doc.data;this.newDocument(),this.$textarea.val(e)}},haste.prototype.lockDocument=function(){var e=this;this.doc.save(this.$textarea.val(),function(t,n){if(t)e.showMessage(t.message,"error");else if(n){e.$code.html(n.value),e.setTitle(n.key);var r="/"+n.key;n.language&&(r+="."+e.lookupExtensionByType(n.language)),window.history.pushState(null,e.appName+"-"+n.key,r),e.fullKey(),e.$textarea.val("").hide(),e.$box.show().focus(),e.addLineNumbers(n.lineCount)}})},haste.prototype.configureButtons=function(){var e=this;this.buttons=[{$where:$("#box2 .save"),label:"Save",shortcutDescription:"control + s",shortcut:function(e){return e.ctrlKey&&e.keyCode===83},action:function(){e.$textarea.val().replace(/^\s+|\s+$/g,"")!==""&&e.lockDocument()}},{$where:$("#box2 .new"),label:"New",shortcut:function(e){return e.ctrlKey&&e.keyCode===78},shortcutDescription:"control + n",action:function(){e.newDocument(!e.doc.key)}},{$where:$("#box2 .duplicate"),label:"Duplicate & Edit",shortcut:function(t){return e.doc.locked&&t.ctrlKey&&t.keyCode===68},shortcutDescription:"control + d",action:function(){e.duplicateDocument()}},{$where:$("#box2 .raw"),label:"Just Text",shortcut:function(e){return e.ctrlKey&&e.shiftKey&&e.keyCode===82},shortcutDescription:"control + shift + r",action:function(){window.location.href="/raw/"+e.doc.key}},{$where:$("#box2 .twitter"),label:"Twitter",shortcut:function(t){return e.options.twitter&&e.doc.locked&&t.shiftKey&&t.ctrlKey&&t.keyCode==84},shortcutDescription:"control + shift + t",action:function(){window.open("https://twitter.com/share?url="+encodeURI(window.location.href))}}];for(var t=0;t0))throw"error reading user photo";var t=e.detail.user,n=t.photos[0].value;$("#box4").append('
')},haste.prototype.configureShortcuts=function(){var e=this;$(document.body).keydown(function(t){var n;for(var r=0;r
@@ -57,6 +60,7 @@
+