Permalink
Browse files

added start to for profile command

  • Loading branch information...
1 parent 9677f79 commit 676ad426e69b7fd8fca59fc5a4f3033218738fa3 @matthewfl matthewfl committed Dec 2, 2010
Showing with 748 additions and 60 deletions.
  1. +36 −2 Bespin/control.js
  2. +84 −55 front-end.js
  3. +3 −2 static/profile.html
  4. +624 −0 static/profile_style.css
  5. +1 −1 static/profile_style.less
View
@@ -1,7 +1,7 @@
"define metadata";
({
"objects": ["commandLine", "editor"],
- "description": "the interface for working with Node-host",
+ "description": "the interface for Node-host",
"provides": [
{
"ep": "command",
@@ -111,6 +111,13 @@
"description": "Toggle the showing of the sidebar",
"pointer": "#sidebarCommand",
"params": []
+ },
+ {
+ "ep": "command",
+ "name": "profile",
+ "description": "Change user, profile and sharing settings",
+ "pointer": "#profileCommand",
+ "params": []
}
]
});
@@ -309,7 +316,7 @@ exports.loginCommand = function (args,request) {
if(userName !== null) return exports.logoutCommand();
request.done();
$.facebox('<div id="login" class="bespin"><form action="/newUser" method="post" type="input">User:<input id="userName" name="userName" type="input" style="color:#000; width:90%;"/><br>Password:<input id="password" name="password" type="password" style="color:#000; width: 90%; "/><div id="moreUser" style="display:none;">Password Again:<input id="password2" name="password2" type="password" style="color: #000; width:90%" /><br>Email:<input id="userEmail" name="userEmail" type="input" style="color: #000; width:90%" /></div><br><input value="login" type="button" id="loginButton" style="width:40%; display: inline;" /><input value="new user" type="submit" id="newUserButton" style="width:40%; display:inline;"/></form></div>');
- $("#userName").focus();
+ setTimeout('$("#userName").focus();', 30);
$("#userName,#password").keypress(function (e) {
if(e.keyCode == '13') {
e.preventDefault();
@@ -378,6 +385,7 @@ exports.loginCommand = function (args,request) {
}
$(document).bind('afterClose.facebox', r);
$(document).trigger('close.facebox');
+ env.editor.focus = true;
track("login");
},
complete: function (a,b) {
@@ -389,6 +397,30 @@ exports.loginCommand = function (args,request) {
});
};
+exports.profileCommand = function (args, request) {
+ if(!userToken) { alert("you need to login for this command"); return request.done("Not logedin"); }
+ $.facebox('<div id="profile" class="bespin">Loading...</div>');
+ Ajax.Call("profile-data", function (data) {
+ $("#profile").html('Name: <input id="Pname" type="input" style="width: 90%; color:#000;"><hr>Email:<input id="Pemail" type="input" style="width: 90%; color: #000;"><hr>Profile: (<a href="http://jsapp.us/p/'+userName+'" target="_blank">view profile</a>)<br><textarea id="Pprofile" rows="12" style="color: #000; width: 98%;"></textarea><div style="width: 30%;"> </div><input type="button" value="save" id="profileSave" style="width: 95%; display: inline;">');
+
+ $("#Pname").val(data.name || userName);
+ $("#Pemail").val(data.email);
+ $("#Pprofile").val(data.markdown);
+ $("#profileSave").click(function () {
+ Ajax.Call({
+ "action": "profile-save",
+ "name": $("#Pname").val(),
+ "email": $("#Pemail").val(),
+ "markdown": $("#Pprofile").val()
+ }, function () {
+ alert("profile saved");
+ });
+ Ajax.send();
+ });
+ });
+ Ajax.send();
+};
+
exports.newUserCommand = function (args, request) {
exports.loginCommand(args, request);
$("#newUserButton").click();
@@ -434,6 +466,8 @@ exports.sidebarCommand = function () {
window.sideBar(null);
};
+
+
var Ajax = {
docTitle: document.title,
buffer: [],
View
@@ -90,7 +90,7 @@ var ajaxActions = {
db.setCat("lsOwn_"+user, data.name+"*");
}else
return back(false);
-
+
});
},
deploy: function (data, user, back) {
@@ -136,6 +136,25 @@ var ajaxActions = {
back({ok: true, num: val});
});
});
+ },
+ "profile-data": function (data, user, back) {
+ if(!user) return back(false);
+ async([
+ [
+ function () { db.get("setting_name_"+user, this); },
+ function () { db.get("email_"+user, this); },
+ function () { db.get("profile_"+user, this); }
+ ],
+ function () {
+ back({name: this[0], email: this[1], markdown: this[2] || "This is the content for your profile in markdown"});
+ }
+ ]);
+ },
+ "profile-save": function (data, user, back) {
+ if(!user) back(false);
+ db.set("setting_name_"+user, data.name);
+ db.set("email_"+user, data.email);
+ db.set("profile_"+user, data.markdown);
}
};
@@ -171,9 +190,9 @@ server.post('/ajax', function (req, res, match) {
}
});
})(ajaxActions[d.actions[i].action], d.actions[i], userName, ret.length-1);
-
+
//ret.push(ajaxActions[d.actions[i].action](d.actions[i], userName) || {});
-
+
}else
ret.push({"error":"not found", "name":d.actions[i].action})
}
@@ -191,25 +210,25 @@ server.post('/ajax', function (req, res, match) {
server.post('/newUser', function (req, res) {
try {
- var raw="";
- req.on('data', function (d) {
- raw+=d.toString('ascii', 0);
- });
- req.on('end', function () {
- (function (data) {
- if(!data.userName || data.userName=="null" || data.userName.length < 2)
- res.notFound("User name not valid");
- db.has("login_"+data.userName, function (has) {
- if(has)
- return router.staticHandler('./static/newUserName.html')(req,res);
- var pass = crypto.createHash('sha1').update(data.password).digest('hex');
- db.set("login_"+data.userName, pass);
- db.set("email_"+data.userName, data.userEmail);
- console.log("new user "+data.userName);
- res.redirect( "/#u" + (userLogin[data.userName] = Math.random().toString().substring(2)) + "," + data.userName );
+ var raw="";
+ req.on('data', function (d) {
+ raw+=d.toString('ascii', 0);
+ });
+ req.on('end', function () {
+ (function (data) {
+ if(!data.userName || data.userName=="null" || data.userName.length < 2)
+ res.notFound("User name not valid");
+ db.has("login_"+data.userName, function (has) {
+ if(has)
+ return router.staticHandler('./static/newUserName.html')(req,res);
+ var pass = crypto.createHash('sha1').update(data.password).digest('hex');
+ db.set("login_"+data.userName, pass);
+ db.set("email_"+data.userName, data.userEmail);
+ console.log("new user "+data.userName);
+ res.redirect( "/#u" + (userLogin[data.userName] = Math.random().toString().substring(2)) + "," + data.userName );
+ });
+ })(querystring.parse(raw));
});
- })(querystring.parse(raw));
- });
} catch (e) {
console.error(e);
res.notFound("there was an error");
@@ -252,42 +271,52 @@ server.get(/\/s\/(.*)$/, function (req, res, match) {
server.get(/\/p\/(.*)$/, function (req, res, match) {
if(match.length < 2) return "User was not found";
var user = match;
- async([
- [
- function () { db.get("lsOwn_"+user, this); },
- function () { db.get("email_"+user, this); },
- function () { db.get("setting_name_"+user, this); },
- function () { db.get("profile_"+user, this); }
- ],
- [
- function () {
- var i,ret="",l = this[0].split("*");
- for(i=0;i<l.length-1;++i) {
- ret += '<div class="site"><a href="http://'+l[i]+'.jsapp.us" target="_blank">'+l[i]+'</a></div>';
+ db.get("email_"+user, function (userEmail) {
+ // This is to check that there is a user before a lot of database hits
+ if(userEmail !== null) {
+ async([
+ [
+ function () { db.get("lsOwn_"+user, this); },
+ function () { db.get("setting_name_"+user, this); },
+ function () { db.get("profile_"+user, this); }
+ ],
+ [
+ function () {
+ if(!this[0]) return this("");
+ var i,ret="",l = this[0].split("*");
+ for(i=0;i<l.length-1;++i) {
+ ret += '<div class="site"><a href="http://'+l[i]+'.jsapp.us" target="_blank">'+l[i]+'</a></div>';
+ }
+ this(ret);
+ },
+ function () {
+ this(crypto.createHash('md5').update((userEmail || "").toLowerCase()).digest('hex'));
+ },
+ function () {
+ if(this[1])
+ this(this[1].replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"));
+ else
+ this(user.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"));
+ },
+ function () {
+ if(this[2])
+ 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 () {
+ 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.end();
}
- this(ret);
- },
- function () {
- this(crypto.createHash('md5').update(this[1] || "").digest('hex'));
- },
- function () {
- if(this[2])
- this(this[2].replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"));
- else
- this(user.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"));
- },
- function () {
- if(this[3])
- this(Markdown(this[3].replace(/</g, "&lt;").replace(/>/g, "&gt;")));
- else
- this("You can create your profile using the profile command from the editor");
- }
- ],
- function () {
- res.writeHead(200, {"Content-type": "text/html"});
- res.write(indexFiles.profile.replace(/\{SUBDOMAIN\}/g, this[0]).replace(/\{EHASH\}/g, this[1])
+ ]);
+ }else{
+ res.writeHead(404, {"Content-type": "text/html"});
+ res.write("The user was not found");
+ res.end();
}
- ]);
+ });
});
View
@@ -2,8 +2,9 @@
<head>
<title>{USER}'s profile on JSApp.US</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
- <link rel="stylesheet/less" href="profile_style.less" type="text/css">
- <script src="/less.js"></script>
+ <!--link rel="stylesheet/less" href="/profile_style.less" type="text/css">
+ <script src="/less.js"></script-->
+ <link rel="stylesheet" href="/profile_style.css" type="text/css">
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-504603-3']);
Oops, something went wrong.

0 comments on commit 676ad42

Please sign in to comment.