- Add isAuthenticated method

- Fix vari
This commit is contained in:
Giuseppe Nucifora 2016-02-12 10:39:47 +01:00
parent 963a3b6e2f
commit fab098e9ab
5 changed files with 38 additions and 26 deletions

View File

@ -62,6 +62,8 @@
[self.view addSubview:_cancelToken];
User * user = [User currentUser];
[self.view setNeedsUpdateConstraints];
}
@ -121,12 +123,17 @@
}];*/
[[PNUser currentUser] loginCurrentUserWithEmail:@"packman@giuseppenucifora.com" password:@"asdasdasd" withBlockSuccess:^(PNUser * _Nullable responseObject) {
User * user = [User currentUser];
if ([user isAuthenticated]) {
[user loginCurrentUserWithEmail:@"packman@giuseppenucifora.com" password:@"asdasdasd" withBlockSuccess:^(PNUser * _Nullable responseObject) {
NSLog(@"response : %@",responseObject);
} failure:^(NSError * _Nonnull error) {
NSLog(@"response : %@",error);
}];
}
}
- (void)didReceiveMemoryWarning

View File

@ -8,7 +8,7 @@
Pod::Spec.new do |s|
s.name = "PNObject"
s.version = "0.3.6"
s.version = "0.3.7"
s.summary = "PNObject is a simple replica of the more complex ParseObject"
# This description is used to generate tags and improve search results.

View File

@ -96,7 +96,7 @@
*
* @return <#return value description#>
*/
- (BOOL) autenticated;
- (BOOL) isAuthenticated;
//- (void) setPassword:(NSString * _Nonnull)password inBackGroundWithBlock:(nullable void (^)(BOOL saveStatus, id responseObject, NSError * error)) responseBlock;

View File

@ -19,6 +19,8 @@
@interface PNUser() <PNObjectSubclassing>
@property (nonatomic) BOOL authenticated;
@end
@implementation PNUser
@ -79,6 +81,10 @@ static bool isFirstAccess = YES;
}
if (SINGLETON) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self autoLogin];
});
}
return SINGLETON;
}
@ -293,10 +299,15 @@ static bool isFirstAccess = YES;
failure:(nullable void (^)(NSError * _Nonnull error))failure {
[[PNObjectConfig sharedInstance] refreshTokenForUserWithEmail:email password:password withBlockSuccess:^(BOOL refreshSuccess) {
if (refreshSuccess) {
[self setAuthenticated:YES];
[self setEmail:email];
[self setPassword:password];
[self setConfirmPassword:password];
[self saveLocally];
if (success) {
success([PNUser currentUser]);
success(self);
}
}
} failure:failure];
@ -330,6 +341,7 @@ static bool isFirstAccess = YES;
@"facebookAccessToken":@"facebookAccessToken",
@"isFacebookUser":@"isFacebookUser",
@"registeredAt":@"registeredAt",
@"authenticated":@"authenticated"
};
return mapping;
}

View File

@ -293,13 +293,6 @@ static bool isFirstAccess = YES;
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceCredentialIdentifier];
[_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
PNUser *user = [PNUser currentUser];
[user setEmail:email];
[user setPassword:password];
[user setConfirmPassword:password];
[user saveLocally];
if (success) {
success(YES);