mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-08 08:31:13 +00:00
add validation logic
This commit is contained in:
parent
039902da02
commit
2a3a8d62cb
@ -99,17 +99,61 @@ static NSString* const kBITAuthenticatorLastAuthenticatedVersionKey = @"BITAuthe
|
|||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
} else {
|
} else {
|
||||||
NSError *error = [NSError errorWithDomain:kBITAuthenticatorErrorDomain
|
NSString *validationEndpoint = @"validate";
|
||||||
code:BITAuthenticatorNetworkError
|
__weak typeof (self) weakSelf = self;
|
||||||
userInfo:nil];
|
[self getPath:validationEndpoint
|
||||||
if(completion) {
|
completion:^(BITHTTPOperation *operation, id response, NSError *error) {
|
||||||
completion(NO, error);
|
typeof (self) strongSelf = weakSelf;
|
||||||
} else {
|
if(nil == response) {
|
||||||
[self.delegate authenticator:self failedToValidateInstallationWithError:error];
|
NSDictionary *userInfo = nil;
|
||||||
}
|
if(error) {
|
||||||
|
userInfo = @{NSUnderlyingErrorKey : error};
|
||||||
|
}
|
||||||
|
NSError *error = [NSError errorWithDomain:kBITAuthenticatorErrorDomain
|
||||||
|
code:BITAuthenticatorNetworkError
|
||||||
|
userInfo:userInfo];
|
||||||
|
[strongSelf validationFailedWithError:error];
|
||||||
|
} else {
|
||||||
|
NSError *validationParseError = nil;
|
||||||
|
BOOL isValidated = [strongSelf.class isValidationResponseValid:response error:&validationParseError];
|
||||||
|
if(isValidated) {
|
||||||
|
[strongSelf validationSucceeded];
|
||||||
|
} else {
|
||||||
|
[strongSelf validationFailedWithError:validationParseError];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (BOOL) isValidationResponseValid:(id) response error:(NSError **) error {
|
||||||
|
NSParameterAssert(response);
|
||||||
|
|
||||||
|
NSError *jsonParseError = nil;
|
||||||
|
id jsonObject = [NSJSONSerialization JSONObjectWithData:response
|
||||||
|
options:0
|
||||||
|
error:&jsonParseError];
|
||||||
|
if(nil == jsonObject) {
|
||||||
|
if(error) {
|
||||||
|
*error = [NSError errorWithDomain:kBITAuthenticatorErrorDomain
|
||||||
|
code:BITAuthenticatorAPIServerReturnedInvalidRespone
|
||||||
|
userInfo:(jsonParseError ? @{NSUnderlyingErrorKey : jsonParseError} : nil)];
|
||||||
|
}
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
if(![jsonObject isKindOfClass:[NSDictionary class]]) {
|
||||||
|
if(error) {
|
||||||
|
*error = [NSError errorWithDomain:kBITAuthenticatorErrorDomain
|
||||||
|
code:BITAuthenticatorAPIServerReturnedInvalidRespone
|
||||||
|
userInfo:nil];
|
||||||
|
}
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: add proper validation
|
||||||
|
return [jsonObject[@"isValid"] boolValue];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)authenticateWithCompletion:(tAuthenticationCompletion)completion {
|
- (void)authenticateWithCompletion:(tAuthenticationCompletion)completion {
|
||||||
if(_authenticationController) {
|
if(_authenticationController) {
|
||||||
BITHockeyLog(@"Already authenticating. Ignoring request");
|
BITHockeyLog(@"Already authenticating. Ignoring request");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user