|
@@ -107,80 +107,6 @@
|
|
|
return sharedOCCommunication;
|
|
|
}
|
|
|
|
|
|
-#pragma --------------------------------------------------------------------------------------------
|
|
|
-#pragma mark ===== Server =====
|
|
|
-#pragma --------------------------------------------------------------------------------------------
|
|
|
-
|
|
|
-- (void)checkServerUrl:(NSString *)serverUrl user:(NSString *)user userID:(NSString *)userID password:(NSString *)password completion:(void (^)(NSString *message, NSInteger errorCode))completion
|
|
|
-{
|
|
|
- OCCommunication *communication = [OCNetworking sharedManager].sharedOCCommunication;
|
|
|
-
|
|
|
- [communication setCredentialsWithUser:user andUserID:userID andPassword:password];
|
|
|
- [communication setUserAgent:[CCUtility getUserAgent]];
|
|
|
-
|
|
|
- [communication checkServer:serverUrl onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
|
|
|
-
|
|
|
- completion(nil, 0);
|
|
|
-
|
|
|
- } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
|
|
|
-
|
|
|
- NSString *message;
|
|
|
-
|
|
|
- NSInteger errorCode = response.statusCode;
|
|
|
- if (errorCode == 0 || (errorCode >= 200 && errorCode < 300))
|
|
|
- errorCode = error.code;
|
|
|
-
|
|
|
- // Error
|
|
|
- if (errorCode == 503)
|
|
|
- message = NSLocalizedString(@"_server_error_retry_", nil);
|
|
|
- else
|
|
|
- message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
|
|
|
-
|
|
|
- completion(message, errorCode);
|
|
|
- }];
|
|
|
-}
|
|
|
-
|
|
|
-- (void)getAppPassword:(NSString *)serverUrl username:(NSString *)username password:(NSString *)password completion:(void(^)(NSString *token, NSString *message, NSInteger errorCode))completion
|
|
|
-{
|
|
|
- NSData *authData = [[NSString stringWithFormat:@"%@:%@", username, password] dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
- NSString *authValue = [NSString stringWithFormat: @"Basic %@",[authData base64EncodedStringWithOptions:0]];
|
|
|
- NSString *URLString = [NSString stringWithFormat:@"%@/ocs/v2.php/core/getapppassword", serverUrl];
|
|
|
-
|
|
|
- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:URLString] cachePolicy:0 timeoutInterval:20.0];
|
|
|
- [request setValue:authValue forHTTPHeaderField:@"Authorization"];
|
|
|
- [request addValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];
|
|
|
- [request addValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
|
|
|
-
|
|
|
- NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
|
|
|
- NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
|
|
|
-
|
|
|
- NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) {
|
|
|
-
|
|
|
- NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
|
|
|
- NSInteger errorCode = 0;
|
|
|
- NSString *message = @"";
|
|
|
- NSString *token = nil;
|
|
|
-
|
|
|
- if (httpResponse.statusCode >= 200 && httpResponse.statusCode < 300) {
|
|
|
-
|
|
|
- NCXMLGetAppPasswordParser *parser = [NCXMLGetAppPasswordParser new];
|
|
|
- [parser initParserWithData:data];
|
|
|
- token = parser.token;
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- errorCode = httpResponse.statusCode;
|
|
|
- message = [NSHTTPURLResponse localizedStringForStatusCode:httpResponse.statusCode];
|
|
|
- }
|
|
|
-
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- completion(token, message, errorCode);
|
|
|
- });
|
|
|
- }];
|
|
|
-
|
|
|
- [task resume];
|
|
|
-}
|
|
|
-
|
|
|
#pragma --------------------------------------------------------------------------------------------
|
|
|
#pragma mark ===== Share =====
|
|
|
#pragma --------------------------------------------------------------------------------------------
|