Skip to content
Browse files

delete current user with class method

  • Loading branch information...
1 parent 2ea72ce commit deb8e1f1aa0b661dcf1f2cea0dff59bf7178da01 Erik Aigner committed Apr 30, 2012
Showing with 28 additions and 9 deletions.
  1. +2 −0 DataKit-Private/DKUser-Private.h
  2. +5 −6 DataKit/DKUser.h
  3. +15 −1 DataKit/DKUser.m
  4. +6 −2 DataKitTests/DKUserTests.m
View
2 DataKit-Private/DKUser-Private.h
@@ -13,4 +13,6 @@
+ (BOOL)userNameAndPasswordValid:(NSError **)error;
+- (BOOL)deleteCurrentUser:(NSError **)error;
+
@end
View
11 DataKit/DKUser.h
@@ -24,16 +24,15 @@
+ (instancetype)signInUserWithName:(NSString *)name password:(NSString *)password error:(NSError **)error;
+ (instancetype)currentUser;
+ (BOOL)signOut:(NSError **)error;
++ (BOOL)deleteCurrentUser:(NSError **)error;
+ (BOOL)requestPasswordResetForUsername:(NSString *)name orEmail:(NSString *)email error:(NSError **)error UNIMPLEMENTED_ATTRIBUTE;
/** @name Deleting Users */
-// TODO: Make clear in the docs that the delete methods do not delete the instance but the current user.
-
-- (BOOL)delete;
-- (BOOL)delete:(NSError **)error;
-- (void)deleteInBackground;
-- (void)deleteInBackgroundWithBlock:(void (^)(DKEntity *, NSError *))block;
+- (BOOL)delete UNAVAILABLE_ATTRIBUTE;
+- (BOOL)delete:(NSError **)error UNAVAILABLE_ATTRIBUTE;
+- (void)deleteInBackground UNAVAILABLE_ATTRIBUTE;
+- (void)deleteInBackgroundWithBlock:(void (^)(DKEntity *, NSError *))block UNAVAILABLE_ATTRIBUTE;
@end
View
16 DataKit/DKUser.m
@@ -166,6 +166,20 @@ + (BOOL)signOut:(NSError **)error {
return [DKKeychain removePasswordForService:kDKUserKeychainServiceName account:nil error:error];
}
++ (BOOL)deleteCurrentUser:(NSError **)error {
+ DKUser *currentUser = [self currentUser];
+ if (currentUser == nil) {
+ if (error != NULL) {
+ NSDictionary *infoDict = [NSDictionary dictionaryWithObject:NSLocalizedString(@"No current user", nil)
+ forKey:NSLocalizedDescriptionKey];
+ *error = [NSError errorWithDomain:NSCocoaErrorDomain code:0x100 userInfo:infoDict];
+ }
+
+ return NO;
+ }
+ return [currentUser deleteCurrentUser:error];
+}
+
- (BOOL)isSignedIn {
return (self.sessionToken.length > 0);
}
@@ -202,7 +216,7 @@ - (void)setSessionToken:(NSString *)sessionToken {
[self setObject:[sessionToken copy] forKey:kDKUserSessionField];
}
-- (BOOL)delete:(NSError **)error {
+- (BOOL)deleteCurrentUser:(NSError **)error {
BOOL success = [super delete:error];
if (success) {
[isa signOut:NULL];
View
8 DataKitTests/DKUserTests.m
@@ -228,8 +228,12 @@ - (void)testDelete {
STAssertTrue(success, nil);
STAssertNil(error, error.localizedDescription);
+ curUser = [DKUser currentUser];
+
+ STAssertNil(curUser, nil);
+
error = nil;
- success = [curUser delete:&error];
+ success = [DKUser deleteCurrentUser:&error];
STAssertFalse(success, nil);
STAssertNotNil(error, nil);
@@ -242,7 +246,7 @@ - (void)testDelete {
STAssertNil(error, error.localizedDescription);
error = nil;
- success = [curUser delete:&error];
+ success = [DKUser deleteCurrentUser:&error];
STAssertTrue(success, nil);
STAssertNil(error, error.localizedDescription);

1 comment on commit deb8e1f

@eaigner
Owner

Don't like the current state of DKUser at all! Needs rework.

Please sign in to comment.
Something went wrong with that request. Please try again.