Skip to content

Commit 2e8558d

Browse files
committed
Merge pull request parse-community#675 from ParsePlatform/nlutsenko.inject.userController
Inject user controller into UserAuthenticationController.
2 parents e61109e + 42df896 commit 2e8558d

File tree

4 files changed

+37
-39
lines changed

4 files changed

+37
-39
lines changed

Parse/Internal/BFTask+Private.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@
2222

2323
@interface BFTask (Private)
2424

25-
- (instancetype)continueAsyncWithBlock:(BFContinuationBlock)block;
26-
- (instancetype)continueAsyncWithSuccessBlock:(BFContinuationBlock)block;
25+
- (BFTask *)continueAsyncWithBlock:(BFContinuationBlock)block;
26+
- (BFTask *)continueAsyncWithSuccessBlock:(BFContinuationBlock)block;
2727

2828
- (BFTask *)continueImmediatelyWithBlock:(BFContinuationBlock)block;
2929
- (BFTask *)continueImmediatelyWithSuccessBlock:(BFContinuationBlock)block;
3030

31-
- (instancetype)continueWithResult:(id)result;
32-
- (instancetype)continueWithSuccessResult:(id)result;
31+
- (BFTask *)continueWithResult:(id)result;
32+
- (BFTask *)continueWithSuccessResult:(id)result;
3333

34-
- (instancetype)continueWithMainThreadResultBlock:(PFIdResultBlock)resultBlock
35-
executeIfCancelled:(BOOL)executeIfCancelled;
36-
- (instancetype)continueWithMainThreadBooleanResultBlock:(PFBooleanResultBlock)resultBlock
37-
executeIfCancelled:(BOOL)executeIfCancelled;
34+
- (BFTask *)continueWithMainThreadResultBlock:(PFIdResultBlock)resultBlock
35+
executeIfCancelled:(BOOL)executeIfCancelled;
36+
- (BFTask *)continueWithMainThreadBooleanResultBlock:(PFBooleanResultBlock)resultBlock
37+
executeIfCancelled:(BOOL)executeIfCancelled;
3838

3939
/**
4040
Adds a continuation to the task that will run the given block on the main

Parse/Internal/BFTask+Private.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ + (instancetype)defaultPriorityBackgroundExecutor {
2929

3030
@implementation BFTask (Private)
3131

32-
- (instancetype)continueAsyncWithBlock:(BFContinuationBlock)block {
32+
- (BFTask *)continueAsyncWithBlock:(BFContinuationBlock)block {
3333
return [self continueWithExecutor:[BFExecutor defaultPriorityBackgroundExecutor] withBlock:block];
3434
}
3535

36-
- (instancetype)continueAsyncWithSuccessBlock:(BFContinuationBlock)block {
36+
- (BFTask *)continueAsyncWithSuccessBlock:(BFContinuationBlock)block {
3737
return [self continueWithExecutor:[BFExecutor defaultPriorityBackgroundExecutor] withSuccessBlock:block];
3838
}
3939

@@ -45,20 +45,20 @@ - (BFTask *)continueImmediatelyWithSuccessBlock:(BFContinuationBlock)block {
4545
return [self continueWithExecutor:[BFExecutor immediateExecutor] withSuccessBlock:block];
4646
}
4747

48-
- (instancetype)continueWithResult:(id)result {
48+
- (BFTask *)continueWithResult:(id)result {
4949
return [self continueWithBlock:^id(BFTask *task) {
5050
return result;
5151
}];
5252
}
5353

54-
- (instancetype)continueWithSuccessResult:(id)result {
54+
- (BFTask *)continueWithSuccessResult:(id)result {
5555
return [self continueWithSuccessBlock:^id(BFTask *task) {
5656
return result;
5757
}];
5858
}
5959

60-
- (instancetype)continueWithMainThreadResultBlock:(PFIdResultBlock)resultBlock
61-
executeIfCancelled:(BOOL)executeIfCancelled {
60+
- (BFTask *)continueWithMainThreadResultBlock:(PFIdResultBlock)resultBlock
61+
executeIfCancelled:(BOOL)executeIfCancelled {
6262
if (!resultBlock) {
6363
return self;
6464
}
@@ -84,8 +84,8 @@ - (instancetype)continueWithMainThreadResultBlock:(PFIdResultBlock)resultBlock
8484
}];
8585
}
8686

87-
- (instancetype)continueWithMainThreadBooleanResultBlock:(PFBooleanResultBlock)resultBlock
88-
executeIfCancelled:(BOOL)executeIfCancelled {
87+
- (BFTask *)continueWithMainThreadBooleanResultBlock:(PFBooleanResultBlock)resultBlock
88+
executeIfCancelled:(BOOL)executeIfCancelled {
8989
return [self continueWithMainThreadResultBlock:^(id object, NSError *error) {
9090
resultBlock([object boolValue], error);
9191
} executeIfCancelled:executeIfCancelled];

Parse/Internal/User/AuthenticationProviders/Controller/PFUserAuthenticationController.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
2121

2222
@interface PFUserAuthenticationController : NSObject
2323

24-
@property (nonatomic, weak, readonly) id<PFCurrentUserControllerProvider> dataSource;
24+
@property (nonatomic, weak, readonly) id<PFCurrentUserControllerProvider, PFUserControllerProvider> dataSource;
2525

2626
///--------------------------------------
2727
/// @name Init
@@ -30,8 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
3030
- (instancetype)init NS_UNAVAILABLE;
3131
+ (instancetype)new NS_UNAVAILABLE;
3232

33-
- (instancetype)initWithDataSource:(id<PFCurrentUserControllerProvider>)dataSource;
34-
+ (instancetype)controllerWithDataSource:(id<PFCurrentUserControllerProvider>)dataSource;
33+
+ (instancetype)controllerWithDataSource:(id<PFCurrentUserControllerProvider, PFUserControllerProvider>)dataSource;
3534

3635
///--------------------------------------
3736
/// @name Authentication Providers
@@ -46,15 +45,16 @@ NS_ASSUME_NONNULL_BEGIN
4645
/// @name Authentication
4746
///--------------------------------------
4847

49-
- (BFTask PF_GENERIC(NSNumber *) *)restoreAuthenticationAsyncWithAuthData:(nullable NSDictionary *)authData
50-
forAuthType:(NSString *)authType;
51-
- (BFTask PF_GENERIC(NSNumber *) *)deauthenticateAsyncWithAuthType:(NSString *)authType;
48+
- (BFTask PF_GENERIC(NSNumber *)*)restoreAuthenticationAsyncWithAuthData:(nullable NSDictionary PF_GENERIC(NSString *, NSString *)*)authData
49+
forAuthType:(NSString *)authType;
50+
- (BFTask PF_GENERIC(NSNumber *)*)deauthenticateAsyncWithAuthType:(NSString *)authType;
5251

5352
///--------------------------------------
5453
/// @name Log In
5554
///--------------------------------------
5655

57-
- (BFTask *)logInUserAsyncWithAuthType:(NSString *)authType authData:(NSDictionary *)authData;
56+
- (BFTask PF_GENERIC(PFUser *)*)logInUserAsyncWithAuthType:(NSString *)authType
57+
authData:(NSDictionary PF_GENERIC(NSString *, NSString *)*)authData;
5858

5959
@end
6060

Parse/Internal/User/AuthenticationProviders/Controller/PFUserAuthenticationController.m

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ @implementation PFUserAuthenticationController
3232
#pragma mark - Init
3333
///--------------------------------------
3434

35-
- (instancetype)initWithDataSource:(id<PFCurrentUserControllerProvider>)dataSource {
35+
- (instancetype)initWithDataSource:(id<PFCurrentUserControllerProvider, PFUserControllerProvider>)dataSource {
3636
self = [super init];
3737
if (!self) return nil;
3838

@@ -43,7 +43,7 @@ - (instancetype)initWithDataSource:(id<PFCurrentUserControllerProvider>)dataSour
4343
return self;
4444
}
4545

46-
+ (instancetype)controllerWithDataSource:(id<PFCurrentUserControllerProvider>)dataSource {
46+
+ (instancetype)controllerWithDataSource:(id<PFCurrentUserControllerProvider, PFUserControllerProvider>)dataSource {
4747
return [[self alloc] initWithDataSource:dataSource];
4848
}
4949

@@ -94,7 +94,7 @@ - (void)unregisterAuthenticationDelegateForAuthType:(NSString *)authType {
9494
#pragma mark - Authentication
9595
///--------------------------------------
9696

97-
- (BFTask PF_GENERIC(NSNumber *)*)restoreAuthenticationAsyncWithAuthData:(nullable NSDictionary *)authData
97+
- (BFTask PF_GENERIC(NSNumber *)*)restoreAuthenticationAsyncWithAuthData:(nullable NSDictionary PF_GENERIC(NSString *, NSString *)*)authData
9898
forAuthType:(NSString *)authType {
9999
id<PFUserAuthenticationDelegate> provider = [self authenticationDelegateForAuthType:authType];
100100
if (!provider) {
@@ -113,12 +113,12 @@ - (void)unregisterAuthenticationDelegateForAuthType:(NSString *)authType {
113113
#pragma mark - Log In
114114
///--------------------------------------
115115

116-
- (BFTask *)logInUserAsyncWithAuthType:(NSString *)authType authData:(NSDictionary *)authData {
116+
- (BFTask PF_GENERIC(PFUser *)*)logInUserAsyncWithAuthType:(NSString *)authType
117+
authData:(NSDictionary PF_GENERIC(NSString *, NSString *)*)authData {
117118
//TODO: (nlutsenko) Make it fully async.
118-
//TODO: (nlutsenko) Inject `PFUserController` here.
119119
PFUser *currentUser = [PFUser currentUser];
120120
if (currentUser && [PFAnonymousUtils isLinkedWithUser:currentUser]) {
121-
if ([currentUser isLazy]) {
121+
if (currentUser.isLazy) {
122122
PFUser *user = currentUser;
123123
BFTask *resolveLaziness = nil;
124124
NSDictionary *oldAnonymousData = nil;
@@ -135,7 +135,7 @@ - (BFTask *)logInUserAsyncWithAuthType:(NSString *)authType authData:(NSDictiona
135135
}
136136

137137
return [resolveLaziness continueAsyncWithBlock:^id(BFTask *task) {
138-
if (task.isCancelled || task.exception || task.error) {
138+
if (task.cancelled || task.faulted) {
139139
[user.authData removeObjectForKey:authType];
140140
[user.linkedServiceNames removeObject:authType];
141141
[user restoreAnonymity:oldAnonymousData];
@@ -144,28 +144,26 @@ - (BFTask *)logInUserAsyncWithAuthType:(NSString *)authType authData:(NSDictiona
144144
return task.result;
145145
}];
146146
} else {
147-
return [[currentUser linkWithAuthTypeInBackground:authType
148-
authData:authData] continueAsyncWithBlock:^id(BFTask *task) {
147+
return [[currentUser linkWithAuthTypeInBackground:authType authData:authData] continueAsyncWithBlock:^id(BFTask *task) {
149148
NSError *error = task.error;
150149
if (error) {
151150
if (error.code == kPFErrorAccountAlreadyLinked) {
152151
// An account that's linked to the given authData already exists,
153152
// so log in instead of trying to claim.
154-
return [[PFUser userController] logInCurrentUserAsyncWithAuthType:authType
155-
authData:authData
156-
revocableSession:[PFUser _isRevocableSessionEnabled]];
153+
return [self.dataSource.userController logInCurrentUserAsyncWithAuthType:authType
154+
authData:authData
155+
revocableSession:[PFUser _isRevocableSessionEnabled]];
157156
} else {
158157
return task;
159158
}
160159
}
161-
162160
return currentUser;
163161
}];
164162
}
165163
}
166-
return [[PFUser userController] logInCurrentUserAsyncWithAuthType:authType
167-
authData:authData
168-
revocableSession:[PFUser _isRevocableSessionEnabled]];
164+
return [self.dataSource.userController logInCurrentUserAsyncWithAuthType:authType
165+
authData:authData
166+
revocableSession:[PFUser _isRevocableSessionEnabled]];
169167
}
170168

171169
@end

0 commit comments

Comments
 (0)