Browse Source

Add verify if _account_already_exists_

Marino Faggiana 7 years ago
parent
commit
6b8facf772
2 changed files with 20 additions and 3 deletions
  1. 19 3
      iOSClient/Login/CCLogin.m
  2. 1 0
      iOSClient/Supporting Files/en.lproj/Localizable.strings

+ 19 - 3
iOSClient/Login/CCLogin.m

@@ -338,9 +338,25 @@
 
 - (void)getUserProfileSuccess:(CCMetadataNet *)metadataNet userProfile:(OCUserProfile *)userProfile
 {
-    tableAccount *account = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account = %@", metadataNet.account]];
+    // Verify if the account already exists
+    if (userProfile.id.length > 0 && self.baseUrl.text.length > 0) {
+    
+        tableAccount *accountAlreadyExists = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"url = %@ AND user = %@", self.baseUrl.text, userProfile.id]];
+        
+        if (accountAlreadyExists) {
+            
+            [[NCManageDatabase sharedInstance] deleteAccount:metadataNet.account];
+            
+            NSString *message = [NSString stringWithFormat:NSLocalizedString(@"_account_already_exists_", nil), userProfile.id];
+            alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
+            [alertView show];
+            
+            return;
+        }
+    }
     
-    // Verify account
+    // Verify if account is a valid account
+    tableAccount *account = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account = %@", metadataNet.account]];
     if (account) {
     
         // Set this account as default
@@ -352,7 +368,7 @@
         // Update User
         [[NCManageDatabase sharedInstance] setAccountsUserProfile:userProfile];
 
-        // Dismiss
+        // Ok ! Dismiss
         [self.delegate loginSuccess:_loginType];
         
         dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{

+ 1 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -223,6 +223,7 @@
 "_title_form_security_init_"    = "Security options";
 "_login_bottom_label_"          = "Don't have a server yet?\nChoose one of the providers.";
 "_error_multidomain_"           = "Address not allowed, only the following domains are valid:";
+"_account_already_exists_"      = "The account %@ already exists";
 
 // Favorite