Permalink
Browse files

working toward auto-adding users

  • Loading branch information...
1 parent fb80960 commit dac77af76bcd86f1f76b3d7b6fa064cbc0e3373e @jchris committed Sep 15, 2010
@@ -11,7 +11,7 @@ function() {
function setupComplete() {
app.db.openDoc(docid, {
success : function(doc) {
- doc.state = "setup-complete";
+ doc.twebz.state = "setup-complete";
app.db.saveDoc(doc, {
success : function() {
widget.trigger("_init");
@@ -1,4 +1,4 @@
-function() {
+function(e, redo) {
var widget = $(this)
, app = $$(widget).app
, userCtx = $$("#account").userCtx
@@ -8,10 +8,11 @@ function() {
function requestUserSetup(userSetupDoc) {
userSetupDoc = userSetupDoc || {
_id : userDocid,
- username : userCtx.name,
- type : "user-setup"
+ username : userCtx.name
};
- userSetupDoc.state = "setup-requested";
+ userSetupDoc.twebz = userSetupDoc.twebz || {};
+ userSetupDoc.twebz.type = "user-setup";
+ userSetupDoc.twebz.state = "setup-requested";
app.db.saveDoc(userSetupDoc, {
success : function() {
if (userCtx.roles.indexOf("_admin") != -1) {
@@ -24,7 +25,7 @@ function() {
}
app.db.openDoc(userDocid, {
success : function(doc) {
- if (doc.state == "setup-complete") {
+ if (!redo && doc.twebz && doc.twebz.state == "setup-complete") {
widget.trigger("tweet");
} else {
requestUserSetup(doc);
@@ -6,6 +6,9 @@ function(cb) {
, udb = $.couch.db(twebz.user_db(userCtx.name))
;
udb.view("twebz-private/twitter-accts", {
- success : cb
+ success : cb,
+ error : function() {
+ $(widget).trigger("setup_user", [true]);
+ }
});
};
@@ -1,3 +1,4 @@
<p>An admin will need to finish setting up your account. If you have an admin
account on this CouchDB, log out and back in as the admin to complete setup.
- Otherwise, contact an admin, or, just wait.</p>
+ Otherwise, contact an admin, or, just wait a few moments and refresh. <strong>Some
+ admins are robots, and they tend to be really fast!</strong></p>
View
@@ -2,5 +2,7 @@
"xpasscode" : "4879332c65153ca9326e495961d30dc7",
"xdb" : "http://jchris.couchone.com:80/twebz",
"passcode" : "twebz",
- "db" : "http://localhost:5984/twebz"
+ "db" : "http://localhost:5984/twebz",
+ "admin_user" : "jchris",
+ "admin_pass" : "jchris"
}
View
@@ -21,12 +21,18 @@ var config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json')))
, dburl = url.parse(config.db)
, dbname = dburl.pathname.split('/')[1]
, twebz = require('../lib/twebz').init(dbname)
+ , admin_client
, client = couchdb.createClient(dburl.port, dburl.hostname,
twebz.app_user, config.passcode)
, db = client.db(dbname)
, config_db = client.db(twebz.config_db)
;
+if (config.admin_pass && config.admin_user) {
+ admin_client = couchdb.createClient(dburl.port, dburl.hostname,
+ config.admin_user, config.admin_pass);
+}
+
config_db.getDoc(twebz.twitter_keys_docid, function(er, doc) {
var twitter_oauth;
if (er) {
@@ -313,6 +319,20 @@ config_db.getDoc(twebz.twitter_keys_docid, function(er, doc) {
});
}
+ function setupUser(doc) {
+ if (admin_client) {
+ // check to see if the user exists
+ // create the database for the user
+ // set the access so only the user can access it
+ // create the secret doc
+ // set the doc to setup complete
+ log("you have an admin client")
+ } else {
+ log("add admin_user and admin_pass to the config and twebz will setup users for you");
+ }
+ }
+
+
function getProfileInfo(doc) {
if (doc.twebz.couch_user && doc.twebz.twitter_user &&
doc.twebz.twitter_user.user_id) {
@@ -435,6 +455,9 @@ config_db.getDoc(twebz.twitter_keys_docid, function(er, doc) {
retweet : {
unsent : sendRetweet
},
+ "user-setup" : {
+ "setup-requested" : setupUser
+ },
"user-recent" : {
request : requestRecentTweets
},
@@ -2,7 +2,7 @@ function(tweet) {
if (tweet.id && tweet.text) {
var date = new Date(tweet.created_at);
var wordCounts = {};
- var words = tweet.text.toLowerCase().split(/\s/);
+ var words = tweet.text.toLowerCase().split(/[^\w\-_'\:\/\.\@]/);
words.forEach(function(word) {
if (word.match(/\/|\:/)||word.match(/^@/)) return;
word = word.replace(/[^\w\-_'\.\@]/g,"").replace(/\W*$/,"").replace(/^\W*/,"").replace(/'\w{1,2}$/,"");
@@ -1,5 +1,5 @@
function(doc) {
- if (doc.type =="user-setup") {
- emit(doc.state, doc.username);
+ if (doc.twebz && doc.twebz.type =="user-setup") {
+ emit(doc.twebz.state, doc.username);
}
};
@@ -2,7 +2,7 @@ function(tweet) {
if (tweet.id && tweet.text && tweet.user && tweet.user.screen_name) {
var wordCounts = {};
var date = new Date(tweet.created_at);
- var words = tweet.text.toLowerCase().split(/\s/);
+ var words = tweet.text.toLowerCase().split(/[^\w\-_'\:\/\.\@]/);
var name = tweet.user.screen_name.toLowerCase();
words.forEach(function(word) {
if (word.match(/\/|\:/)||word.match(/^@/)) return;

0 comments on commit dac77af

Please sign in to comment.