- Fix user ma

This commit is contained in:
Giuseppe Nucifora 2016-02-15 16:35:59 +01:00
parent 527b02a082
commit bef8607419
14 changed files with 84 additions and 228 deletions

View File

@ -36,9 +36,9 @@
EnvironmentProduction : @"http://packman.ppreview.it/app_stage.php/api/v1/" EnvironmentProduction : @"http://packman.ppreview.it/app_stage.php/api/v1/"
} withOauth:YES]; } withOauth:YES];
[[PNObjectConfig sharedInstance] setHTTPHeaderValue:@"application/x-www-form-urlencoded" forKey:@"Content-Type"]; [[PNObjectConfig sharedInstance] setHTTPHeaderValue:@"application/x-www-form-urlencoded" forKey:@"Content-Type"];
[[PNObjectConfig sharedInstance] setClientID:@"1_pqjo2w5k7j4g8skco408oc048w8so0ws840gcg8k8gwsgk0g4" clientSecret:@"10w0vg2v6eggooc4wks4w4s0wkwok0wkck0w888so0o80g88w8" forEnv:Stage]; [[PNObjectConfig sharedInstance] setClientID:@"1_pqjo2w5k7j4g8skco408oc048w8so0ws840gcg8k8gwsgk0g4" clientSecret:@"10w0vg2v6eggooc4wks4w4s0wkwok0wkck0w888so0o80g88w8" forEnv:EnvironmentProduction];
#ifdef DEBUG #ifdef DEBUG
[[PNObjectConfig sharedInstance] setEnvironment:Stage]; [[PNObjectConfig sharedInstance] setEnvironment:EnvironmentStage];
#endif #endif

View File

@ -106,15 +106,15 @@
[password setPassword:@"asdasdasd"]; [password setPassword:@"asdasdasd"];
[password setConfirmPassword:@"asdasdasd"]; [password setConfirmPassword:@"asdasdasd"];
User *user = [User currentUser]; User *user = [User new];
[user setFirstName:@"Giuseppe"]; [user setFirstName:@"Giuseppe"];
[user setLastName:@"Nuficora"]; [user setLastName:@"Nuficora"];
[user setEmail:@"packman@giuseppenucifora.com"]; [user setEmail:@"packman5@giuseppenucifora.com"];
[user setPassword:password]; [user setPassword:password];
[user setHasAcceptedNewsletter:NO]; [user setHasAcceptedNewsletter:YES];
[user setHasAcceptedPrivacy:YES]; [user setHasAcceptedPrivacy:YES];
[user saveLocally]; //[user saveLocally];
NSLog(@"%@",[user JSONFormObject]); NSLog(@"%@",[user JSONFormObject]);
//NSLog(@"%@",[user JSONObjectMap]); //NSLog(@"%@",[user JSONObjectMap]);

View File

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

View File

@ -19,7 +19,7 @@
@implementation PNInstallation @implementation PNInstallation
static PNInstallation *SINGLETON = nil; static PNInstallation *INSTALLATION = nil;
static bool isFirstAccess = YES; static bool isFirstAccess = YES;
@ -61,10 +61,10 @@ static bool isFirstAccess = YES;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
isFirstAccess = NO; isFirstAccess = NO;
SINGLETON = [[super allocWithZone:NULL] init]; INSTALLATION = [[super allocWithZone:NULL] init];
}); });
return SINGLETON; return INSTALLATION;
} }
- (void)setDeviceTokenFromData:(NSData *)deviceTokenData { - (void)setDeviceTokenFromData:(NSData *)deviceTokenData {
@ -85,8 +85,8 @@ static bool isFirstAccess = YES;
- (id) init - (id) init
{ {
if(SINGLETON){ if(INSTALLATION){
return SINGLETON; return INSTALLATION;
} }
if (isFirstAccess) { if (isFirstAccess) {
[self doesNotRecognizeSelector:_cmd]; [self doesNotRecognizeSelector:_cmd];

View File

@ -136,6 +136,10 @@
* <#Description#> * <#Description#>
*/ */
@property (nonatomic) BOOL hasVerifiedEmail; @property (nonatomic) BOOL hasVerifiedEmail;
/**
* <#Description#>
*/
@property (nonatomic) BOOL hasVerifiedPhone;
/** /**
* <#Description#> * <#Description#>
*/ */

View File

@ -28,7 +28,7 @@
@synthesize password = _password; @synthesize password = _password;
static PNUser *SINGLETON = nil; static id USER = nil;
static bool isFirstAccess = YES; static bool isFirstAccess = YES;
@ -39,15 +39,15 @@ static bool isFirstAccess = YES;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
isFirstAccess = NO; isFirstAccess = NO;
SINGLETON = [[super allocWithZone:NULL] initForCurrentUser]; USER = [[super allocWithZone:NULL] initForCurrentUser];
}); });
return SINGLETON; return USER;
} }
+ (instancetype)resetUser { + (instancetype)resetUser {
[SINGLETON autoRemoveLocally]; [USER autoRemoveLocally];
SINGLETON = nil; USER = nil;
return [self currentUser]; return [self currentUser];
} }
@ -65,8 +65,8 @@ static bool isFirstAccess = YES;
- (instancetype) initForCurrentUser - (instancetype) initForCurrentUser
{ {
if(SINGLETON){ if(USER){
return SINGLETON; return USER;
} }
if (isFirstAccess) { if (isFirstAccess) {
[self doesNotRecognizeSelector:_cmd]; [self doesNotRecognizeSelector:_cmd];
@ -75,19 +75,17 @@ static bool isFirstAccess = YES;
NSDictionary *savedUser = [[PNObjectModel sharedInstance] fetchObjectsWithClass:[self class]]; NSDictionary *savedUser = [[PNObjectModel sharedInstance] fetchObjectsWithClass:[self class]];
if (savedUser) { if (savedUser) {
SINGLETON = [super initWithJSON:savedUser]; USER = [super initWithJSON:savedUser];
}
else {
SINGLETON = [super init];
} }
if (SINGLETON) { if (USER) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self autoLogin]; [self autoLogin];
}); });
} }
return SINGLETON;
return USER;
} }
- (void) setEmail:(NSString *)email { - (void) setEmail:(NSString *)email {
@ -156,7 +154,7 @@ static bool isFirstAccess = YES;
[self POSTWithEndpointAction:@"registration/register" parameters:[self JSONFormObject] [self POSTWithEndpointAction:@"registration/register" parameters:[self JSONFormObject]
progress:nil progress:nil
success:^(NSURLSessionDataTask * _Nullable task, PNObject * _Nullable responseObject) { success:^(NSURLSessionDataTask * _Nullable task, NSDictionary * _Nullable responseObject) {
NSLog(@"response %@",responseObject); NSLog(@"response %@",responseObject);
if(success){ if(success){
success(self); success(self);
@ -294,8 +292,7 @@ static bool isFirstAccess = YES;
+ (NSDictionary *)objcetMapping { + (NSDictionary *)objcetMapping {
NSDictionary *mapping = @{ NSDictionary *mapping = @{
@"userId":@"id", @"userId":@"uuid",
@"userUUID":@"uuid",
@"firstName":@"firstName", @"firstName":@"firstName",
@"lastName":@"lastName", @"lastName":@"lastName",
@"profileImage":@"profileImage", @"profileImage":@"profileImage",
@ -306,6 +303,7 @@ static bool isFirstAccess = YES;
@"hasAcceptedPrivacy":@"hasAcceptedPrivacy", @"hasAcceptedPrivacy":@"hasAcceptedPrivacy",
@"hasAcceptedNewsletter":@"hasAcceptedNewsletter", @"hasAcceptedNewsletter":@"hasAcceptedNewsletter",
@"hasVerifiedEmail":@"hasVerifiedEmail", @"hasVerifiedEmail":@"hasVerifiedEmail",
@"hasVerifiedPhone":@"has_verified_phone",
@"emailVerifiedDate":@"emailVerifiedDate", @"emailVerifiedDate":@"emailVerifiedDate",
@"email":@"email", @"email":@"email",
@"username":@"username", @"username":@"username",

View File

@ -13,13 +13,15 @@
- (void) GETWithEndpointAction:(NSString * _Nonnull) endPoint - (void) GETWithEndpointAction:(NSString * _Nonnull) endPoint
progress:(nullable void (^)(NSProgress * _Nonnull downloadProgress)) downloadProgress progress:(nullable void (^)(NSProgress * _Nonnull downloadProgress)) downloadProgress
success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, id _Nullable responseObject))success success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSDictionary * _Nullable responseObject))success
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure; failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure;
- (void) POSTWithEndpointAction:(NSString * _Nonnull) endPoint - (void) POSTWithEndpointAction:(NSString * _Nonnull) endPoint
parameters:(NSDictionary * _Nonnull) parameters parameters:(NSDictionary * _Nonnull) parameters
progress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress progress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress
success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, id _Nullable responseObject))success success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSDictionary * _Nullable responseObject))success
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure; failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure;
+ (id _Nonnull) parseObjectFromResponse:(id _Nullable) response;
@end @end

View File

@ -18,7 +18,7 @@
- (void) GETWithEndpointAction:(NSString * _Nonnull) endPoint - (void) GETWithEndpointAction:(NSString * _Nonnull) endPoint
progress:(nullable void (^)(NSProgress * _Nonnull downloadProgress)) downloadProgress progress:(nullable void (^)(NSProgress * _Nonnull downloadProgress)) downloadProgress
success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, id _Nullable responseObject))success success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSDictionary * _Nullable responseObject))success
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure { failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure {
@ -27,7 +27,7 @@
[[[PNObjectConfig sharedInstance] manager] GET:[[[PNObjectConfig sharedInstance] baseUrl] stringByAppendingFormat:@"%@",endPoint] parameters:nil progress:downloadProgress success:^(NSURLSessionDataTask *task, id responseObject) { [[[PNObjectConfig sharedInstance] manager] GET:[[[PNObjectConfig sharedInstance] baseUrl] stringByAppendingFormat:@"%@",endPoint] parameters:nil progress:downloadProgress success:^(NSURLSessionDataTask *task, id responseObject) {
if (success) { if (success) {
success(task,[[self class] parseObjectFromResponse:responseObject]); success(task,responseObject);
} }
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
@ -51,7 +51,7 @@
- (void) POSTWithEndpointAction:(NSString * _Nonnull) endPoint - (void) POSTWithEndpointAction:(NSString * _Nonnull) endPoint
parameters:(NSDictionary * _Nonnull) parameters parameters:(NSDictionary * _Nonnull) parameters
progress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress progress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress
success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, id _Nullable responseObject))success success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSDictionary * _Nullable responseObject))success
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure { failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure {
if ([[PNObjectConfig sharedInstance] currentOauthCredential] && ![[[PNObjectConfig sharedInstance] currentOauthCredential] isExpired]) { if ([[PNObjectConfig sharedInstance] currentOauthCredential] && ![[[PNObjectConfig sharedInstance] currentOauthCredential] isExpired]) {
@ -59,7 +59,7 @@
[[[PNObjectConfig sharedInstance] manager] POST:[[[PNObjectConfig sharedInstance] baseUrl] stringByAppendingFormat:@"%@",endPoint] parameters:parameters progress:uploadProgress success:^(NSURLSessionDataTask *task, id responseObject) { [[[PNObjectConfig sharedInstance] manager] POST:[[[PNObjectConfig sharedInstance] baseUrl] stringByAppendingFormat:@"%@",endPoint] parameters:parameters progress:uploadProgress success:^(NSURLSessionDataTask *task, id responseObject) {
if (success) { if (success) {
success(task,[[self class] parseObjectFromResponse:responseObject]); success(task,responseObject);
} }
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

View File

@ -371,124 +371,6 @@ NSString * const PNObjectMappingSelector = @"PNObjectLocalNotificationRefreshTok
})(); })();
} }
} }
/*for (NSString* propertyName in self.JSONObjectMap) {
id mappingValue = [self.JSONObjectMap objectForKey:propertyName];
if([mappingValue isKindOfClass:NSDictionary.class]) {
mappedJSONKey = [mappingValue valueForKey:@"key"];
mappedJSONType = [mappingValue valueForKey:@"type"];
} else {
mappedJSONKey = mappingValue;
}
NSString *propertyType = [properties valueForKey:propertyName];
if (![[formMapping allKeys] containsObject:propertyName]) {
continue;
}
id value = [self valueForKey:propertyName];
//TODO: forse è da sostituire propertyName con il valore de
((void (^)())@{
@"c" : ^{
char val = [value charValue];
[JSON setValue:@(val) forKey:propertyName];
},
@"d" : ^{
double val = [value doubleValue];
[JSON setValue:@(val) forKey:propertyName];
},
@"f" : ^{
float val = [value floatValue];
[JSON setValue:@(val) forKey:propertyName];
},
@"i" : ^{
int val = [value intValue];
[JSON setValue:@(val) forKey:propertyName];
},
@"l" : ^{
long val = [value longValue];
[JSON setValue:@(val) forKey:propertyName];
},
@"s" : ^{
short val = [value shortValue];
[JSON setValue:@(val) forKey:propertyName];
},
@"B" : ^{
BOOL val = [value boolValue];
[JSON setValue:@(val) forKey:propertyName];
},
@"UIImage" : ^{
UIImage *image = [UIImage imageWithData:value];
[JSON setValue:image forKey:propertyName];
},
@"NSURL" : ^{
NSURL *url = value;
if (![self isObjNull:url]) {
[JSON setValue:[url absoluteString] forKey:propertyName];
}
},
@"NSString" : ^{
NSString *val = [NSString stringWithFormat:@"%@", value];
if (![self isObjNull:val]) {
[JSON setValue:val forKey:propertyName];
}
},
@"NSNumber" : ^{
NSInteger val = [value integerValue];
[JSON setValue:@(val) forKey:propertyName];
},
@"NSDate" : ^{
NSDate *val = [value toLocalTime];
if (![self isObjNull:val]) {
[JSON setValue:val forKey:propertyName];
}
},
@"NSArray" : ^{
NSMutableArray *arr = [NSMutableArray array];
for(id object in value) {
BOOL isPNObjectSubclass = [[object class] isSubclassOfClass:[PNObject class]];
if(isPNObjectSubclass) {
NSDictionary *objectDict = [(PNObject*) object reverseMapping];
[arr addObject:objectDict];
}
}
[JSON setValue:arr forKey:propertyName];
},
@"NSMutableArray" : ^{
NSMutableArray *arr = [NSMutableArray array];
for(id object in value) {
BOOL isPNObjectSubclass = [[object class] isSubclassOfClass:[PNObject class]];
if(isPNObjectSubclass) {
NSDictionary *objectDict = [(PNObject*) object reverseMapping];
[arr addObject:objectDict];
}
}
[JSON setValue:arr forKey:propertyName];
}
}[propertyType] ?: ^{
BOOL isPNObjectSubclass = [NSClassFromString(propertyType) isSubclassOfClass:[PNObject class]];
if(isPNObjectSubclass) {
NSDictionary *objectDict = [(PNObject*)value reverseMapping];
[JSON setValue:objectDict forKey:propertyName];
}
else {
// do nothing
}
})();
}*/
} }
return JSON; return JSON;
} }

View File

@ -412,7 +412,7 @@
} }
} }
self.JSON = nil; _JSON = nil;
_JSONObjectMap = nil; _JSONObjectMap = nil;
_objID = nil; _objID = nil;
_createdAt = nil; _createdAt = nil;

View File

@ -14,13 +14,6 @@
#import "AFHTTPRequestSerializer+OAuth2.h" #import "AFHTTPRequestSerializer+OAuth2.h"
#import "AFOAuthCredential.h" #import "AFOAuthCredential.h"
typedef NS_ENUM(NSInteger, Environment) {
Development = 0,
Stage = 1,
Production = 2
};
#pragma mark LocalNotification Keys #pragma mark LocalNotification Keys
extern NSString* _Nonnull const PNObjectLocalNotificationRefreshTokenClientCredentialSuccess; extern NSString* _Nonnull const PNObjectLocalNotificationRefreshTokenClientCredentialSuccess;
@ -79,7 +72,7 @@ extern NSString* _Nonnull const Client_Secret;
* *
* @param env <#env description#> * @param env <#env description#>
*/ */
- (void) setEnvironment:(Environment) env; - (void) setEnvironment:(NSString * _Nonnull) environment;
/** /**
* <#Description#> * <#Description#>
@ -92,12 +85,12 @@ extern NSString* _Nonnull const Client_Secret;
/** /**
* <#Description#> * <#Description#>
* *
* @param value <#value description#> * @param value EnvironmentProduction, EnvironmentStage, EnvironmentDevelopment
* @param key <#key description#> * @param key <#key description#>
*/ */
- (void) removeHTTPHeaderValueForKey:(NSString * _Nonnull) key; - (void) removeHTTPHeaderValueForKey:(NSString * _Nonnull) key;
- (void) setClientID:(NSString * _Nonnull) clientID clientSecret:(NSString* _Nonnull) clientSecret forEnv:(Environment) environment; - (void) setClientID:(NSString * _Nonnull) clientID clientSecret:(NSString* _Nonnull) clientSecret forEnv:(NSString * _Nonnull) environment;
/** /**
* <#Description#> * <#Description#>
@ -178,6 +171,6 @@ extern NSString* _Nonnull const Client_Secret;
/** /**
* <#Description#> * <#Description#>
*/ */
@property (nonatomic, strong, readonly) NSString *encrypKey; @property (nonatomic, strong, nonnull , readonly) NSString *encrypKey;
@end @end

View File

@ -42,11 +42,11 @@ NSString* const Client_Secret = @"client_secret";
@property (nonatomic, strong) NSMutableDictionary *configuration; @property (nonatomic, strong) NSMutableDictionary *configuration;
@property (nonatomic, strong) NSMutableDictionary *headerFields; @property (nonatomic, strong) NSMutableDictionary *headerFields;
@property (nonatomic) Environment currentEnv; @property (nonatomic, strong) NSString *currentEnv;
@property (nonatomic, strong) NSString *currentEndPointBaseUrl; @property (nonatomic, strong) NSString *currentEndPointBaseUrl;
@property (nonatomic, strong) NSString *currentOAuthClientID; @property (nonatomic, strong) NSString *currentOAuthClientID;
@property (nonatomic, strong) NSString *currentOAuthClientSecret; @property (nonatomic, strong) NSString *currentOAuthClientSecret;
@property (nonatomic, strong) NSMutableArray *environments; //@property (nonatomic, strong) NSMutableDictionary *environments;
@end @end
@ -84,16 +84,14 @@ static bool isFirstAccess = YES;
SINGLETON.oauthEnabled = oauthEnabled; SINGLETON.oauthEnabled = oauthEnabled;
for (NSString *key in [endpointUrlsForEnvironments allKeys]) { for (NSString *key in [endpointUrlsForEnvironments allKeys]) {
if ([SINGLETON.environments containsObject:key]) { NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]];
if (endpointUrl) {
NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]]; [SINGLETON.configuration setValue:[NSDictionary dictionaryWithObjectsAndKeys:[endpointUrl absoluteString],BaseUrl, nil] forKey:key];
if (endpointUrl) {
[SINGLETON.configuration setValue:[NSDictionary dictionaryWithObjectsAndKeys:[endpointUrl absoluteString],BaseUrl, nil] forKey:key];
}
} }
} }
NSAssert([SINGLETON.configuration objectForKey:EnvironmentProduction], @"EnvironmentProduction must be valid endpoint url"); NSAssert([SINGLETON.configuration objectForKey:EnvironmentProduction], @"EnvironmentProduction must be valid endpoint url");
[SINGLETON setEnvironment:Production]; [SINGLETON setEnvironment:EnvironmentProduction];
@ -138,11 +136,9 @@ static bool isFirstAccess = YES;
if (self) { if (self) {
if (_oauthEnabled) { if (_oauthEnabled) {
_currentOauthCredential = [AFOAuthCredential retrieveCredentialWithIdentifier:PNObjectServiceCredentialIdentifier]; [AFOAuthCredential deleteCredentialWithIdentifier:PNObjectServiceCredentialIdentifier];
} }
_environments = [[NSMutableArray alloc] initWithArray:@[EnvironmentDevelopment,EnvironmentStage,EnvironmentProduction]];
_configuration = [[NSMutableDictionary alloc] init]; _configuration = [[NSMutableDictionary alloc] init];
_minPasswordLenght = minPassLenght; _minPasswordLenght = minPassLenght;
@ -162,30 +158,20 @@ static bool isFirstAccess = YES;
return self; return self;
} }
- (void) setEnvironment:(Environment) env { - (void) setEnvironment:(NSString * _Nonnull) environment {
_currentEnv = env; _currentEnv = environment;
_currentEndPointBaseUrl = nil; _currentEndPointBaseUrl = nil;
_currentOAuthClientID = nil; _currentOAuthClientID = nil;
_currentOAuthClientSecret = nil; _currentOAuthClientSecret = nil;
if (env < [_environments count]) { if ([_configuration objectForKey:environment]) {
if ([_configuration objectForKey:[_environments objectAtIndex:env]]) { _currentEndPointBaseUrl = [[_configuration objectForKey:_currentEnv] objectForKey:BaseUrl];
_currentEndPointBaseUrl = [[_configuration objectForKey:[_environments objectAtIndex:env]] objectForKey:BaseUrl]; _currentOAuthClientID = [[_configuration objectForKey:_currentEnv] objectForKey:Client_ID];
_currentOAuthClientID = [[_configuration objectForKey:[_environments objectAtIndex:env]] objectForKey:Client_ID]; _currentOAuthClientSecret = [[_configuration objectForKey:_currentEnv] objectForKey:Client_Secret];
_currentOAuthClientSecret = [[_configuration objectForKey:[_environments objectAtIndex:env]] objectForKey:Client_Secret];
} }
}
else { NSLog(@"%@",[[_configuration objectForKey:_currentEnv] objectForKey:BaseUrl]);
_currentEndPointBaseUrl = [[_configuration objectForKey:EnvironmentProduction] objectForKey:BaseUrl];
if ([[_configuration objectForKey:EnvironmentProduction] objectForKey:Client_ID]) {
_currentOAuthClientID = [[_configuration objectForKey:EnvironmentProduction] objectForKey:Client_ID];
}
if ([[_configuration objectForKey:EnvironmentProduction] objectForKey:Client_Secret]) {
_currentOAuthClientSecret = [[_configuration objectForKey:EnvironmentProduction] objectForKey:Client_Secret];
}
}
NSLog(@"%@",[[_configuration objectForKey:[_environments objectAtIndex:env]] objectForKey:BaseUrl]);
NSAssert(_currentEndPointBaseUrl,@"Selected environment generate error. Please check configuration"); NSAssert(_currentEndPointBaseUrl,@"Selected environment generate error. Please check configuration");
@ -205,7 +191,7 @@ static bool isFirstAccess = YES;
_manager = [AFOAuth2Manager manager]; _manager = [AFOAuth2Manager manager];
} }
_currentOauthCredential = [AFOAuthCredential retrieveCredentialWithIdentifier:PNObjectServiceCredentialIdentifier]; //_currentOauthCredential = [AFOAuthCredential retrieveCredentialWithIdentifier:PNObjectServiceCredentialIdentifier];
if (_oauthEnabled && _currentOAuthClientID && _currentOAuthClientSecret) { if (_oauthEnabled && _currentOAuthClientID && _currentOAuthClientSecret) {
@ -246,7 +232,7 @@ static bool isFirstAccess = YES;
} }
- (void) refreshToken { - (void) refreshToken {
if([PNUser currentUser] && [[PNUser currentUser] hasValidEmailAndPasswordData]) { if([PNUser currentUser] && [[PNUser currentUser] hasValidEmailAndPasswordData]) {
[self refreshTokenForUser]; [self refreshTokenForUser];
} }
else { else {
@ -296,7 +282,7 @@ static bool isFirstAccess = YES;
if (![email isValidEmail]) { if (![email isValidEmail]) {
if (failure) { if (failure) {
NSError *error = [NSError errorWithDomain:NSLocalizedString(@"Email is not valid", @"") code:kHTTPStatusCodeBadRequest userInfo:nil]; NSError *error = [NSError errorWithDomain:NSLocalizedString(@"Email is not valid", @"") code:kHTTPStatusCodeBadRequest userInfo:nil];
failure(error); failure(error);
return; return;
} }
@ -308,22 +294,22 @@ static bool isFirstAccess = YES;
return; return;
} }
} }
[_manager authenticateUsingOAuthWithURLString:[_currentEndPointBaseUrl stringByAppendingString:@"oauth-token"] username:email password:password scope:nil success:^(AFOAuthCredential * _Nonnull credential) { [_manager authenticateUsingOAuthWithURLString:[_currentEndPointBaseUrl stringByAppendingString:@"oauth-token"] username:email password:password scope:nil success:^(AFOAuthCredential * _Nonnull credential) {
_currentOauthCredential = credential; _currentOauthCredential = credential;
[AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceCredentialIdentifier]; [AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceCredentialIdentifier];
[_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; [_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential];
if (success) { if (success) {
success(YES); success(YES);
} }
} failure:^(NSError * _Nonnull error) { } failure:^(NSError * _Nonnull error) {
[[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenUserFail object:error]; [[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenUserFail object:error];
if (failure) { if (failure) {
failure(error); failure(error);
} }
}]; }];
} }
- (void) refreshTokenForClientCredential { - (void) refreshTokenForClientCredential {
@ -368,15 +354,15 @@ static bool isFirstAccess = YES;
} }
} }
- (void) setClientID:(NSString * _Nonnull) clientID clientSecret:(NSString* _Nonnull) clientSecret forEnv:(Environment) environment { - (void) setClientID:(NSString * _Nonnull) clientID clientSecret:(NSString* _Nonnull) clientSecret forEnv:(NSString *) environment {
if ([_configuration objectForKey:[_environments objectAtIndex:environment]]) { if ([_configuration objectForKey:environment]) {
NSMutableDictionary *currentConfigurationDict = [[NSMutableDictionary alloc] initWithDictionary:[_configuration objectForKey:[_environments objectAtIndex:environment]]]; NSMutableDictionary *currentConfigurationDict = [[NSMutableDictionary alloc] initWithDictionary:[_configuration objectForKey:environment]];
[currentConfigurationDict setObject:clientID forKey:Client_ID]; [currentConfigurationDict setObject:clientID forKey:Client_ID];
[currentConfigurationDict setObject:clientSecret forKey:Client_Secret]; [currentConfigurationDict setObject:clientSecret forKey:Client_Secret];
[_configuration setObject:currentConfigurationDict forKey:[_environments objectAtIndex:environment]]; [_configuration setObject:currentConfigurationDict forKey:environment];
if (_currentEnv == environment) { if (_currentEnv == environment) {
[self setEnvironment:environment]; [self setEnvironment:environment];

View File

@ -41,15 +41,6 @@
*/ */
- (id _Nonnull) saveLocally:(id _Nonnull) object; - (id _Nonnull) saveLocally:(id _Nonnull) object;
/**
* <#Description#>
*
* @param object <#object description#>
*
* @return <#return value description#>
*/
- (id _Nonnull) saveNSUSerDefautls:(id _Nonnull) object;
/** /**
* <#Description#> * <#Description#>
* *

View File

@ -238,9 +238,9 @@ static bool isFirstAccess = YES;
} }
} }
- (id _Nonnull) saveNSUSerDefautls:(id _Nonnull) object { /*- (id _Nonnull) saveNSUSerDefautls:(id _Nonnull) object {
} }*/
- (BOOL) removeObjectLocally:(id _Nonnull) object { - (BOOL) removeObjectLocally:(id _Nonnull) object {
BOOL isPNObjectSubclass = [[object class] isSubclassOfClass:[PNObject class]]; BOOL isPNObjectSubclass = [[object class] isSubclassOfClass:[PNObject class]];