Permalink
Browse files

Sync current login state correctly

  • Loading branch information...
1 parent 389bfc5 commit d68d5c50d3e70ff9237a43ffa47505a0d7de3acd @benlangfeld committed Oct 27, 2010
View
@@ -53,6 +53,9 @@
[theWindow orderFront:self];
// End of layout code
[[SCUserSessionManager defaultManager] setLoginProvider:[SCEmailLoginDialogController defaultController]];
+ // Sync current login state
+ CPLog.debug("Checking current login state");
+ [[SCUserSessionManager defaultManager] syncSession:self];
}
- (void)unauthorizedAction:(id)sender
@@ -110,6 +113,15 @@
[self successfulAlertWithMessage:@"You logged out successfully!"];
}
+- (void)sessionSyncDidSucceed:(SCUserSessionManager)sessionManager
+{
+ var userEmail = [[SCUserSessionManager defaultManager] userDisplayName];
+ if (userEmail)
+ CPLog.debug("Currently logged in user: " + userEmail);
+ else
+ CPLog.debug("No user currently logged in.");
+}
+
- (void)logout:(id)sender
{
[[SCUserSessionManager defaultManager] logout:self];
@@ -214,8 +214,8 @@ var SCDefaultSessionManager = nil;
if (aConnection === _sessionSyncConnection) {
var delegate = aConnection.delegate;
- if (responseBody.username)
- [self _setCurrentUser:responseBody.username];
+ if (responseBody.email)
+ [self _setCurrentUser:responseBody.email];
if (delegate && [delegate respondsToSelector:@selector(sessionSyncDidSucceed:)])
[delegate sessionSyncDidSucceed:self];
}
View
@@ -14,6 +14,8 @@
<string>/users.json</string>
<key>SCAuthUserCheckURL</key>
<string>/profiles/</string>
+ <key>SCAuthSyncURL</key>
+ <string>/user_sessions.json</string>
<key>SCAuthLogoutURL</key>
<string>/logout.json</string>
</dict>
@@ -10,4 +10,14 @@ def show
end
end
end
+
+ def find_current_user
+ if current_user
+ respond_with "{ \"email\" : \"#{current_user.email}\" }", :status => :ok
+ else
+ respond_to do |format|
+ format.any(:xml, :json) { head :not_found }
+ end
+ end
+ end
end
View
@@ -3,6 +3,7 @@
delete "/logout" => "devise/sessions#destroy"
end
match 'profiles/*email(.:format)' => 'profiles#show', :defaults => {:format => :json}
+ match "/user_sessions" => "profiles#find_current_user"
resources :projects, :tasks
root :to => "projects#index"
# The priority is based upon order of creation:

0 comments on commit d68d5c5

Please sign in to comment.