Permalink
Browse files

added public code to profile view

  • Loading branch information...
1 parent 8d71b51 commit a34fd9631dc3f7a3d86df1866ff6647c1e6234a9 @matthewfl matthewfl committed Dec 13, 2010
Showing with 53 additions and 5 deletions.
  1. +4 −0 Bespin/control.js
  2. +30 −3 front-end.js
  3. +19 −1 static/profile.html
  4. +0 −1 test.js
View
@@ -408,6 +408,10 @@ exports.loginCommand = function (args,request) {
alert("Username is to short");
return false;
}
+ if(/\\|\//.exec($("#userName").val())) {
+ alert("Username can not contain \/ or \\");
+ return false;
+ }
if(!$("#password").val()) {
alert("There is no password entered");
return false;
View
@@ -258,7 +258,7 @@ server.post('/newUser', function (req, res) {
});
req.on('end', function () {
(function (data) {
- if(!data.userName || data.userName=="null" || data.userName.length < 2)
+ if(!data.userName || data.userName=="null" || data.userName.length < 2 || /\\|\//.exec(data.userName))
res.notFound("User name not valid");
db.has("login_"+data.userName, function (has) {
if(has)
@@ -320,7 +320,8 @@ server.get(/\/p\/(.*)$/, function (req, res, match) {
[
function () { db.get("lsOwn_"+user, this); },
function () { db.get("setting_name_"+user, this); },
- function () { db.get("profile_"+user, this); }
+ function () { db.get("profile_"+user, this); },
+ function () { db.get("lsPublic_"+user, this); }
],
[
function () {
@@ -345,11 +346,18 @@ server.get(/\/p\/(.*)$/, function (req, res, match) {
this(Markdown(this[2].replace(/</g, "&lt;").replace(/>/g, "&gt;")));
else
this("You can create your profile using the profile command from the editor");
+ },
+ function () {
+ if(!this[3]) return this("");
+ var i,ret="",l=this[3].split("*");
+ for(i=0;i<l.length;i++)
+ ret+= '<div class="publicF"><a class="publicL" href="/code/'+user+'/'+l[i]+'" target="_blank">'+l[i]+'</a></div>';
+ this(ret);
}
],
function () {
res.writeHead(200, {"Content-type": "text/html"});
- res.write(indexFiles.profile.replace(/\{SUBDOMAIN\}/g, this[0]).replace(/\{EHASH\}/g, this[1]).replace(/\{USER\}/g, user.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")).replace(/\{NAME\}/g, this[2]).replace(/\{MARKDOWN\}/g, this[3]));
+ res.write(indexFiles.profile.replace(/\{SUBDOMAIN\}/g, this[0]).replace(/\{EHASH\}/g, this[1]).replace(/\{USER\}/g, user.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")).replace(/\{NAME\}/g, this[2]).replace(/\{MARKDOWN\}/g, this[3]).replace(/\{PUBLIC\}/g, this[4]));
res.end();
}
]);
@@ -361,6 +369,25 @@ server.get(/\/p\/(.*)$/, function (req, res, match) {
});
});
+server.get(/\/code\/(.*)$/, function (req, res, match) {
+ //res.writeHead(200, {"Content-Type": "text/html"});
+ var user = match.substring(0,match.indexOf('/'));
+ var file = match.substring(match.indexOf('/')+1);
+ db.get("lsPublic_"+user, function (data) {
+ if(!data || data.split("*").indexOf(file) == -1) {
+ res.writeHead(401, {"Content-Type": "text/html"});
+ res.end("<p>The file was not found, or not public</p>");
+ }
+ res.writeHead(200, {"Content-type": "text/html"});
+ db.get("fs_"+user+"_"+file, function (code) {
+ res.write("<p>This code can be loaded in to anyones project using: <code>require(\""+user+"/"+file+"\");</code></p><p><code>");
+ res.write(code.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<br>").replace(/\t/g, "&nbsp;&nbsp;&nbsp;&nbsp;").replace(/\s/g, "&nbsp;"));
+ res.write("</code></p>");
+ res.end();
+ });
+ });
+});
+
server.get(/\/error/, function (req, res) {
res.writeHead(503, {"Content-Type": "text/html"});
View
@@ -10,6 +10,17 @@
_gaq.push(['_setAccount', 'UA-504603-3']);
_gaq.push(['_setDomainName', 'jsapp.us']);
_gaq.push(['_trackPageview']);
+ var loadedHR=false;
+ $(function () {
+ $("a.publicL").click(function () {
+ if(!loadedHR){
+ $("#mark").append("<hr>");
+ loadedHR=true;
+ }
+ $("#codeView").load($(this).attr('href'));
+ return false;
+ });
+ });
</script>
</head>
<body>
@@ -27,6 +38,11 @@
{SUBDOMAIN}
<div class="break"> </div>
</div>
+ <h4><center>Public files</center></h4>
+ <div id="public" class="push_1">
+ {PUBLIC}
+ <div class="break"> </div>
+ </div>
</div>
<div class="grid_9">
<div class="alpha"> </div>
@@ -35,9 +51,11 @@
</div>
<div class="clear"> </div>
<hr>
- <div class="grid_9">
+ <div class="grid_9" id="mark">
{MARKDOWN}
</div>
+ <div class="clear"> </div>
+ <div class="grid_9" id="codeView"></div>
<div class="omega"> </div>
</div>
<div class="clear"> </div>
View
@@ -24,7 +24,6 @@ var server = http.createServer(function (req, res) {
return;
}
sandbox.build(data, urlInfo.query.user, function (d) {
- console.log(d)
var name;
do {
name = config.testBase.replace(/\#\#/g, Math.random().toString().substring(2,12));

0 comments on commit a34fd96

Please sign in to comment.