diff --git a/PNObject.podspec b/PNObject.podspec index a56617b..e1eaa30 100644 --- a/PNObject.podspec +++ b/PNObject.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = "PNObject" -s.version = "0.3.1" +s.version = "0.3.2" s.summary = "PNObject is a simple replica of the more complex ParseObject" # This description is used to generate tags and improve search results. diff --git a/Pod/Classes/PNClasses/PNUser.h b/Pod/Classes/PNClasses/PNUser.h index 33ab34f..72fddd2 100644 --- a/Pod/Classes/PNClasses/PNUser.h +++ b/Pod/Classes/PNClasses/PNUser.h @@ -29,6 +29,8 @@ */ - (void) logout; +- (BOOL) isValidUser; + //- (void) setPassword:(NSString * _Nonnull)password inBackGroundWithBlock:(nullable void (^)(BOOL saveStatus, id responseObject, NSError * error)) responseBlock; ///-------------------------------------- diff --git a/Pod/Classes/PNClasses/PNUser.m b/Pod/Classes/PNClasses/PNUser.m index 139f2a9..f33fc0f 100644 --- a/Pod/Classes/PNClasses/PNUser.m +++ b/Pod/Classes/PNClasses/PNUser.m @@ -102,6 +102,14 @@ static bool isFirstAccess = YES; [self resetObject]; } +- (BOOL) isValidUser { + if(self.username && self.password && [self isValidPassword:[self password]]){ + return YES; + } + + return NO; +} + #pragma mark PNObjectSubclassing Protocol + (NSDictionary *)objcetMapping { diff --git a/Pod/Classes/PNObjectConfig.m b/Pod/Classes/PNObjectConfig.m index fa5d5d2..4222c18 100644 --- a/Pod/Classes/PNObjectConfig.m +++ b/Pod/Classes/PNObjectConfig.m @@ -1,10 +1,10 @@ - // - // PNObjectConfig.m - // Pods - // - // Created by Giuseppe Nucifora on 08/01/16. - // - // +// +// PNObjectConfig.m +// Pods +// +// Created by Giuseppe Nucifora on 08/01/16. +// +// #import "PNObjectConfig.h" #import "PNObjectConstants.h" @@ -224,7 +224,7 @@ static bool isFirstAccess = YES; } - (void) tryRefreshToken { - if ([PNUser currentUser]) { + if ([PNUser currentUser] && [[PNUser currentUser] isValidUser]) { [_manager authenticateUsingOAuthWithURLString:[_currentEndPointBaseUrl stringByAppendingString:@"oauth-token"] username:[[PNUser currentUser] username] password:[[PNUser currentUser] password] scope:nil success:^(AFOAuthCredential * _Nonnull credential) { _currentOauthCredential = credential; [_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; diff --git a/Pod/Classes/Vendors/AFOAuth2Manager/AFOAuth2Manager.h b/Pod/Classes/Vendors/AFOAuth2Manager/AFOAuth2Manager.h index 9b03e45..83e1ea9 100644 --- a/Pod/Classes/Vendors/AFOAuth2Manager/AFOAuth2Manager.h +++ b/Pod/Classes/Vendors/AFOAuth2Manager/AFOAuth2Manager.h @@ -1,38 +1,37 @@ -// AFOAuth2Manager.h -// -// Copyright (c) 2012-2014 AFNetworking (http://afnetworking.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE + // AFOAuth2Manager.h + // + // Copyright (c) 2012-2014 AFNetworking (http://afnetworking.com) + // + // Permission is hereby granted, free of charge, to any person obtaining a copy + // of this software and associated documentation files (the "Software"), to deal + // in the Software without restriction, including without limitation the rights + // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + // copies of the Software, and to permit persons to whom the Software is + // furnished to do so, subject to the following conditions: + // + // The above copyright notice and this permission notice shall be included in + // all copies or substantial portions of the Software. + // + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + // THE SOFTWARE #import +#import #import "AFOAuthCredential.h" #import "AFHTTPRequestSerializer+OAuth2.h" -@import AFNetworking; - NS_ASSUME_NONNULL_BEGIN @interface AFOAuth2Manager : AFHTTPSessionManager -///------------------------------------------ -/// @name Accessing OAuth 2 Client Properties -///------------------------------------------ + ///------------------------------------------ + /// @name Accessing OAuth 2 Client Properties + ///------------------------------------------ /** The service provider identifier used to store and retrieve OAuth credentials by `AFOAuthCredential`. Equivalent to the hostname of the client `baseURL`. @@ -49,17 +48,17 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, assign) BOOL useHTTPBasicAuthentication; -///------------------------------------------------ -/// @name Creating and Initializing OAuth 2 Managers -///------------------------------------------------ + ///------------------------------------------------ + /// @name Creating and Initializing OAuth 2 Managers + ///------------------------------------------------ /** Creates and initializes an `AFOAuth2Manager` object with the specified base URL, client identifier, and secret. - + @param url The base URL for the HTTP client. This argument must not be `nil`. @param clientID The client identifier issued by the authorization server, uniquely representing the registration information provided by the client. This argument must not be `nil`. @param secret The client secret. - + @return The newly-initialized OAuth 2 manager */ + (instancetype)managerWithBaseURL:(NSURL *)url @@ -73,11 +72,11 @@ NS_ASSUME_NONNULL_BEGIN /** Initializes an `AFOAuth2Manager` object with the specified base URL, client identifier, and secret. The communication to to the server will use HTTP basic auth by default (use `-(id)initWithBaseURL:clientID:secret:withBasicAuth:` to change this). - + @param url The base URL for the HTTP manager. This argument must not be `nil`. @param clientID The client identifier issued by the authorization server, uniquely representing the registration information provided by the client. This argument must not be `nil`. @param secret The client secret. - + @return The newly-initialized OAuth 2 client */ - (id)initWithBaseURL:(NSURL *)url @@ -89,13 +88,13 @@ NS_ASSUME_NONNULL_BEGIN clientID:(NSString *)clientID secret:(NSString *)secret; -///--------------------- -/// @name Authenticating -///--------------------- + ///--------------------- + /// @name Authenticating + ///--------------------- /** Creates and enqueues an `NSURLSessionTask` to authenticate against the server using a specified username and password, with a designated scope. - + @param URLString The URL string used to create the request URL. @param username The username used for authentication @param password The password used for authentication @@ -112,7 +111,7 @@ NS_ASSUME_NONNULL_BEGIN /** Creates and enqueues an `NSURLSessionTask` to authenticate against the server with a designated scope. - + @param URLString The URL string used to create the request URL. @param scope The authorization scope @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes a single argument: the OAuth credential returned by the server. @@ -151,7 +150,7 @@ NS_ASSUME_NONNULL_BEGIN /** Creates and enqueues an `NSURLSessionTask` to authenticate against the server with the specified parameters. - + @param URLString The URL string used to create the request URL. @param parameters The parameters to be encoded and set in the request HTTP body. @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes a single argument: the OAuth credential returned by the server. @@ -164,9 +163,9 @@ NS_ASSUME_NONNULL_BEGIN @end -///---------------- -/// @name Constants -///---------------- + ///---------------- + /// @name Constants + ///---------------- /** ## Error Domains