Skip to content

Commit

Permalink
login flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Marino Faggiana authored and Marino Faggiana committed Jan 8, 2018
1 parent 0cdb939 commit 64d7c7d
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 28 deletions.
2 changes: 1 addition & 1 deletion iOSClient/Brand/NCBrand.swift
Expand Up @@ -87,7 +87,7 @@ class NCBrandColor: NSObject {

// Options
@objc public let use_login_web: Bool = false
@objc public let use_login_web_flow: Bool = false
@objc public let use_login_web_flow: Bool = true
@objc public let use_firebase: Bool = false
@objc public let use_default_auto_upload: Bool = false
@objc public let use_themingColor: Bool = true
Expand Down
1 change: 1 addition & 0 deletions iOSClient/Database/NCDatabase.swift
Expand Up @@ -41,6 +41,7 @@ class tableAccount: Object {
@objc dynamic var displayName = ""
@objc dynamic var email = ""
@objc dynamic var enabled: Bool = false
@objc dynamic var loginFlow: Bool = false
@objc dynamic var optimization = NSDate()
@objc dynamic var password = ""
@objc dynamic var phone = ""
Expand Down
5 changes: 3 additions & 2 deletions iOSClient/Database/NCManageDatabase.swift
Expand Up @@ -57,13 +57,14 @@ class NCManageDatabase: NSObject {
let config = Realm.Configuration(

fileURL: dirGroup?.appendingPathComponent("\(appDatabaseNextcloud)/\(k_databaseDefault)"),
schemaVersion: 14,
schemaVersion: 15,

// 10 : Version 2.18.0
// 11 : Version 2.18.2
// 12 : Version 2.19.0.5
// 13 : Version 2.19.0.14
// 14 : ...
// 14 : Version 2.19.0.xx
// 15 : Version 2.19.2

migrationBlock: { migration, oldSchemaVersion in
// We haven’t migrated anything yet, so oldSchemaVersion == 0
Expand Down
98 changes: 73 additions & 25 deletions iOSClient/Login/CCLogin.m
Expand Up @@ -88,14 +88,19 @@ - (void)viewDidLoad

// Brand
if ([NCBrandOptions sharedInstance].disable_request_login_url) {

_baseUrl.text = [NCBrandOptions sharedInstance].loginBaseUrl;
_imageBaseUrl.hidden = YES;
_baseUrl.hidden = YES;
}

if (_loginType == loginAdd) {

// Login Flow ?
if ([NCBrandOptions sharedInstance].use_login_web_flow) {
_imageUser.hidden = YES;
_user.hidden = YES;
_imagePassword.hidden = YES;
_password.hidden = YES;
}
}

if (_loginType == loginAddForced) {
Expand Down Expand Up @@ -185,44 +190,82 @@ - (void)testUrl
if(![self.baseUrl.text hasPrefix:@"https"] && ![self.baseUrl.text hasPrefix:@"http"]) {
self.baseUrl.text = [NSString stringWithFormat:@"https://%@",self.baseUrl.text];
}
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.baseUrl.text] cachePolicy:0 timeoutInterval:20.0];
[request addValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
// Test Login Flow
if ([self.baseUrl.text length] > 0 && _user.hidden == YES && _password.hidden == YES) {

NSString *url = self.baseUrl.text;
if ([url hasSuffix:@"/"]) url = [url substringToIndex:[url length] - 1];
url = [url stringByAppendingString:flowEndpoint];

NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:0 timeoutInterval:20.0];

[request addValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];
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) {

dispatch_async(dispatch_get_main_queue(), ^{

self.login.enabled = YES;
self.loadingBaseUrl.hidden = YES;

if (error) {

NSLog(@"[LOG] Error: %ld - %@",(long)[error code] , [error localizedDescription]);

} else {


}

});
}];

[task resume];

} else {

NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.baseUrl.text] cachePolicy:0 timeoutInterval:20.0];
[request addValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];

NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) {
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) {

dispatch_async(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_main_queue(), ^{

self.login.enabled = YES;
self.loadingBaseUrl.hidden = YES;
self.login.enabled = YES;
self.loadingBaseUrl.hidden = YES;

if (error != nil) {
if (error != nil) {

NSLog(@"[LOG] Error: %ld - %@",(long)[error code] , [error localizedDescription]);
NSLog(@"[LOG] Error: %ld - %@",(long)[error code] , [error localizedDescription]);

// self signed certificate
if ([error code] == NSURLErrorServerCertificateUntrusted) {
// self signed certificate
if ([error code] == NSURLErrorServerCertificateUntrusted) {

NSLog(@"[LOG] Error NSURLErrorServerCertificateUntrusted");
NSLog(@"[LOG] Error NSURLErrorServerCertificateUntrusted");

[[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:[error localizedDescription] viewController:self delegate:self];
[[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:[error localizedDescription] viewController:self delegate:self];

} else {
} else {

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_connection_error_", nil) message:[error localizedDescription] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_connection_error_", nil) message:[error localizedDescription] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];

[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
}
}
}
});
});

}];
}];

[task resume];
[task resume];
}
}

- (void)trustedCerticateAccepted
Expand Down Expand Up @@ -409,6 +452,11 @@ - (IBAction)handlebaseUrlchange:(id)sender

- (IBAction)handleButtonLogin:(id)sender
{
if ([self.baseUrl.text length] > 0 && _user.hidden == YES && _password.hidden == YES) {
[self testUrl];
return;
}

if ([self.baseUrl.text length] > 0 && [self.user.text length] && [self.password.text length]) {

// remove last char if /
Expand Down

0 comments on commit 64d7c7d

Please sign in to comment.