Manos Chorianopoulos

fix refresh token crash

......@@ -594,7 +594,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -969,7 +969,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
success(successResponse);
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -983,6 +983,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
- (void)refreshToken2ndTry:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
if ([_db tableExists:@"requestVariables"] == YES) {
FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"];
NSString *refreshToken = [NSString alloc];
while ([refreshTokenSet next]) {
......@@ -1014,12 +1015,12 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
NSString* errorCode = [dict objectForKey:@"NSLocalizedDescription"];
if ([errorCode isEqual:@"Request failed: unauthorized (401)"]) {
[self refreshToken3rdTry:^(NSDictionary *response) {
// [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [response objectForKey:@"access_token"], [response objectForKey:@"refresh_token"]];
// [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [response objectForKey:@"access_token"], [response objectForKey:@"refresh_token"]];
NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
success(successResponse);
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1028,10 +1029,12 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
NSLog(@"Error at token %@", error );
}
}];
}
}
- (void)refreshToken3rdTry:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
if ([_db tableExists:@"requestVariables"] == YES) {
FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"];
NSString *refreshToken = [NSString alloc];
while ([refreshTokenSet next]) {
......@@ -1062,13 +1065,15 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
dict = [error userInfo];
NSString* errorCode = [dict objectForKey:@"NSLocalizedDescription"];
if ([errorCode isEqual:@"Request failed: unauthorized (401)"]) {
// [self refreshToken:^(NSDictionary *response) {
// // [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [response objectForKey:@"access_token"], [response objectForKey:@"refresh_token"]];
// NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
// success(successResponse);
// } failureBlock:^(NSError *error) {
// [self refreshToken:^(NSDictionary *response) {
// // [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [response objectForKey:@"access_token"], [response objectForKey:@"refresh_token"]];
// NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
// success(successResponse);
// } failureBlock:^(NSError *error) {
if (failure) {
if ([_db tableExists:@"requestVariables"] == YES) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1077,6 +1082,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
NSLog(@"Error at token %@", error );
}
}];
}
}
- (void)changePasswordWithSuccessBlock:(NSString*)oldPassword andNewPassword:(NSString*)newPassword :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
......@@ -1105,7 +1111,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1148,7 +1154,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1209,7 +1215,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1315,7 +1321,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1356,7 +1362,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1397,7 +1403,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1475,7 +1481,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1512,7 +1518,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1549,7 +1555,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1586,7 +1592,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1623,7 +1629,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1738,7 +1744,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1775,7 +1781,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1812,7 +1818,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1853,7 +1859,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1890,7 +1896,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1927,7 +1933,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -2009,7 +2015,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -2046,7 +2052,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -2083,7 +2089,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -2295,7 +2301,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -2355,7 +2361,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -2396,7 +2402,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -2437,7 +2443,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -2478,7 +2484,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -2538,7 +2544,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -2575,7 +2581,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
......