Permalink
Browse files

working toward a twebz user and config db

  • Loading branch information...
1 parent 0b202be commit a83b079f4ca4890a6878fa3f84eacd4ebe5e9cd1 @jchris committed Aug 28, 2010
View
@@ -1,4 +1,4 @@
{
- "name": "Name of your CouchApp",
- "description": "CouchApp"
+ "name": "Twebz",
+ "description": "Decentralized Twitter Client"
}
@@ -1,15 +1,37 @@
function() {
- var widget = $(this), app = $$(widget).app;
- app.db.openDoc("twebz-config", {
- success : function(doc) {
- if (doc.twitter_keypair) {
- widget.trigger("keyring");
- } else {
- widget.trigger("twitter_keypair");
- }
- },
- error : function() {
- widget.trigger("twitter_keypair");
+ var widget = $(this)
+ , app = $$(widget).app
+ , twebz = app.require("lib/twebz").init(app.db.name)
+ ;
+ // ensure the twebz user exists and has a private database for config
+ $.couch.session({
+ success : function(session) {
+ $.couch.db(session.authentication_db).openDoc("org.couchdb.user:"+twebz.app_user, {
+ success : function() {
+ // if the user exists, we assume it's been setup proper
+ // check to see if the config database exists
+ },
+ error : function() {
+ if (session.userCtx.roles.indexOf("_admin") != -1) {
+ widget.trigger("create_app_user");
+ } else {
+ widget.trigger("admin_required");
+ }
+ }
+ });
}
- });
+ })
+ //
+ // app.db.openDoc("twebz-config", {
+ // success : function(doc) {
+ // if (doc.twebz) {
+ // widget.trigger("keyring");
+ // } else {
+ // widget.trigger("twitter_keypair");
+ // }
+ // },
+ // error : function() {
+ // widget.trigger("twitter_keypair");
+ // }
+ // });
};
@@ -0,0 +1,2 @@
+<h3>Admin Required</h3>
+<p>Please login as an admin user and reload this page in order to complete the setup process.</p>
@@ -0,0 +1,10 @@
+function() {
+ var widget = $(this)
+ , app = $$(widget).app
+ , twebz = app.require("lib/twebz").init(app.db.name)
+ ;
+ twebz.password = $.couch.newUUID().split("").sort(function() {
+ return Math.random() - Math.random();
+ }).join("");
+ return twebz;
+};
@@ -0,0 +1,16 @@
+<h3>Create App User</h3>
+<p>Twebz requires a dedicate user for the application, which will have access
+ to the twebz configuration database.</p>
+<p>To proceed with setup, copy the Twebz configuration code below, then click
+ "setup". Setup will create a user called {{app_user}} and grant it access to
+ a configuration database called {{config_db}}.
+</p>
+<p>You will be prompted to save the {{app_user}} user's password to a
+ configuration file. This permits the Node.js compontent of Twebz to access
+ configuration data allowing it to communicate with Twitter.</p>
+<p>Once this step is complete you will be prompted to acquire Twitter authentication keys,
+ which takes just a moment on Twitter's API page.</p>
+<form><p>Copy this passcode and paste it into the file <tt>node/config.json</tt>:
+ <strong class="password">{{password}}</strong></p>
+ <p>Once the passcode is in place, click this button to continue:
+ <input type="submit" value="Setup Twebz User"></p></form>
@@ -0,0 +1,12 @@
+function() {
+ var widget = $(this)
+ , app = $$(widget).app
+ , twebz = app.require("lib/twebz").init(app.db.name)
+ , password = $(".password", widget).text()
+ ;
+ $.couch.signup({name:twebz.app_user}, password, {
+ success : function() {
+
+ }
+ })
+};
View
@@ -0,0 +1,9 @@
+exports.init = function(dbname) {
+ return {
+ app_user : dbname,
+ config_db : dbname + "-config",
+ user_db : function(username) {
+ return dbname + "-private-" + username;
+ }
+ }
+};
View
@@ -6,7 +6,8 @@ var tweetstream = require('tweetstream'),
request = require('request'),
sys = require('sys'),
couchdb = require("couchdb"),
- cc = require("couch-client")
+ cc = require("couch-client"),
+ oauth = require("oauth")
;
function log(e) {
View
@@ -23,7 +23,13 @@ twebz :
install:
/* create twebz database*/
setup screen
- prompt for user to setup twitter app keypair in node/config.json
+ site setup:
+ create twebz user
+ put twebz user password in config.json
+ create twebz-config database only twebz user can read
+ prompt for user to setup twitter app keypair
+
+ user setup:
prompt to create twebz-private-username database
ensure user is admin
grant access to private-db to node script
@@ -35,6 +41,8 @@ install:
link twitter account(s) to couchdb account
store twitter creds in private db
+ oauth_token
+ oauth_token_secret
store shared secret in private db
option to send each tweet as any linked account

0 comments on commit a83b079

Please sign in to comment.