Permalink
Browse files

Improve setCurrentUser

  • Loading branch information...
1 parent 4167aba commit 294e3d72c93e41e91a030e78ff1a4e68f11d9e2c @soffes soffes committed Aug 14, 2012
Showing with 8 additions and 9 deletions.
  1. +8 −9 CheddarKit/CDKUser.m
View
@@ -58,20 +58,19 @@ + (void)setCurrentUser:(CDKUser *)user {
if (__currentUser) {
[SSKeychain deletePasswordForService:kCDKKeychainServiceName account:__currentUser.remoteID.description];
}
-
+
+ NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
+
if (!user.remoteID || !user.accessToken) {
__currentUser = nil;
- return;
+ [userDefaults removeObjectForKey:kCDKUserIDKey];
+ } else {
+ [SSKeychain setPassword:user.accessToken forService:kCDKKeychainServiceName account:user.remoteID.description];
+ __currentUser = user;
+ [userDefaults setObject:user.remoteID forKey:kCDKUserIDKey];
}
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- [userDefaults setObject:user.remoteID forKey:kCDKUserIDKey];
[userDefaults synchronize];
-
- [SSKeychain setPassword:user.accessToken forService:kCDKKeychainServiceName account:user.remoteID.description];
-
- __currentUser = user;
-
[[NSNotificationCenter defaultCenter] postNotificationName:kCDKCurrentUserChangedNotificationName object:user];
}

0 comments on commit 294e3d7

Please sign in to comment.