Marino Faggiana 7 years ago
parent
commit
a618b4f32c
2 changed files with 18 additions and 8 deletions
  1. 5 2
      iOSClient/Database/NCManageDatabase.swift
  2. 13 6
      iOSClient/Login/CCLogin.m

+ 5 - 2
iOSClient/Database/NCManageDatabase.swift

@@ -170,7 +170,7 @@ class NCManageDatabase: NSObject {
         }
     }
     
-    func setAccountPassword(_ account: String, password: String) {
+    func setAccountPassword(_ account: String, password: String) -> tableAccount? {
         
         let realm = try! Realm()
         
@@ -178,7 +178,7 @@ class NCManageDatabase: NSObject {
 
         guard let result = realm.objects(tableAccount.self).filter("account = %@", account).first else {
             realm.cancelWrite()
-            return
+            return nil
         }
         
         result.password = password
@@ -187,7 +187,10 @@ class NCManageDatabase: NSObject {
             try realm.commitWrite()
         } catch let error {
             print("[LOG] Could not write to database: ", error)
+            return nil
         }
+        
+        return result
     }
     
     func deleteAccount(_ account: String) {

+ 13 - 6
iOSClient/Login/CCLogin.m

@@ -283,8 +283,12 @@
         
         if (_loginType == loginModifyPasswordUser) {
             
-            [[NCManageDatabase sharedInstance] setAccountPassword:account password:self.password.text];
+            // Change Password
+            tableAccount *tbAccount = [[NCManageDatabase sharedInstance] setAccountPassword:account password:self.password.text];
             
+            // Setting App active account
+            [app settingActiveAccount:tbAccount.account activeUrl:tbAccount.url activeUser:tbAccount.user activePassword:tbAccount.password];
+
             // Dismiss
             [self.delegate loginSuccess:_loginType];
             [self dismissViewControllerAnimated:YES completion:nil];
@@ -297,7 +301,7 @@
             // Read User Profile
             CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:account];
             metadataNet.action = actionGetUserProfile;
-            [app.netQueue addOperation:[[OCnetworking alloc] initWithDelegate:self metadataNet:metadataNet withUser:self.user.text withPassword:self.password.text withUrl:[self.baseUrl.text stringByAppendingString:webDAV] isCryptoCloudMode:NO]];
+            [app.netQueue addOperation:[[OCnetworking alloc] initWithDelegate:self metadataNet:metadataNet withUser:self.user.text withPassword:self.password.text withUrl:self.baseUrl.text isCryptoCloudMode:NO]];
         }
         
     } else {
@@ -330,12 +334,15 @@
 
 - (void)getUserProfileSuccess:(CCMetadataNet *)metadataNet userProfile:(OCUserProfile *)userProfile
 {
-    // Update User
-    [[NCManageDatabase sharedInstance] setAccountsUserProfile:userProfile];
-    
     // Set this account as default
-    (void)[[NCManageDatabase sharedInstance] setAccountActive:metadataNet.account];
+    tableAccount *tbAccount = [[NCManageDatabase sharedInstance] setAccountActive:metadataNet.account];
     
+    // Setting App active account
+    [app settingActiveAccount:tbAccount.account activeUrl:tbAccount.url activeUser:tbAccount.user activePassword:tbAccount.password];
+    
+    // Update User
+    [[NCManageDatabase sharedInstance] setAccountsUserProfile:userProfile];
+
     // Dismiss
     [self.delegate loginSuccess:_loginType];
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{