Permalink
Browse files

store profile on the user doc not in the application db

  • Loading branch information...
1 parent 420adb7 commit 41d7cff811d010ce6b174f6812f3bb6d49f8665e @jchris jchris committed Feb 18, 2010
Showing with 33 additions and 31 deletions.
  1. +16 −15 vendor/evently/profile/loggedIn.js
  2. +17 −16 vendor/evently/profile/noProfile/selectors/form/submit.js
@@ -1,18 +1,19 @@
function(e, r) {
var userCtx = r.userCtx;
- // todo we need a place to put library functions // application constants
- // maybe we need to make common.js require available in here
- var proid = "couch.app.profile:"+userCtx.name,
- widget = $(this);
-
- $$(widget).app.db.openDoc(proid, {
- success : function(doc) {
- // todo decide if this is better than passing around
- $$(widget).profile = doc;
- widget.trigger("profileReady", [doc]);
- },
- error : function() {
- widget.trigger("noProfile", [userCtx]);
- }
+ var widget = $(this);
+ // load the profile from the user doc
+ $.couch.userDb(function(db) {
+ var userDocId = "org.couchdb.user:"+userCtx.name;
+ db.openDoc(userDocId, {
+ success : function(userDoc) {
+ var profile = userDoc["couch.app.profile"];
+ if (profile) {
+ $$(widget).profile = profile;
+ widget.trigger("profileReady", [profile]);
+ } else {
+ widget.trigger("noProfile", [userCtx]);
+ }
+ }
+ });
});
-}
+}
@@ -1,18 +1,13 @@
function() {
// TODO this can be cleaned up with docForm
- // todo get the app from somewhere
+
var name = $("input[name=userCtxName]",this).val();
- var proid = "couch.app.profile:"+name,
- newProfile = {
- _id : proid,
- type : "couch.app.profile",
- rand : Math.random().toString(),
- name : name,
+ var newProfile = {
+ rand : Math.random().toString(),
nickname : $("input[name=nickname]",this).val(),
email : $("input[name=email]",this).val(),
url : $("input[name=url]",this).val()
}, widget = $(this);
- var app = $$(widget).app;
// setup gravatar_url
if (typeof hex_md5 == "undefined") {
@@ -22,14 +17,20 @@ function() {
newProfile.gravatar_url = 'http://www.gravatar.com/avatar/'+hex_md5(newProfile.email || newProfile.rand)+'.jpg?s=40&d=identicon';
- app.db.saveDoc(newProfile, {
- success : function() {
- app.db.openDoc(proid, {
- success : function(doc) {
- widget.trigger("profileReady", [doc]);
- }
- });
- }
+ // store the user profile on the user account document
+ $.couch.userDb(function(db) {
+ var userDocId = "org.couchdb.user:"+name;
+ db.openDoc(userDocId, {
+ success : function(userDoc) {
+ userDoc["couch.app.profile"] = newProfile;
+ db.saveDoc(userDoc, {
+ success : function() {
+ $$(widget).profile = profile;
+ widget.trigger("profileReady", [newProfile]);
+ }
+ });
+ }
+ });
});
return false;
}

0 comments on commit 41d7cff

Please sign in to comment.