Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Fix duplicate accounts #976

Merged
merged 3 commits into from
Dec 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions Owncloud iOs Client/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -2791,6 +2791,7 @@ -(void)badCertificateNotAcceptedByUser {

- (void) switchActiveUserTo:(UserDto *)user isNewAccount:(BOOL)isNewAccount {


self.userSessionCurrentToken = nil;
// should be here or right after checking the user really changed? for the moment, here

Expand All @@ -2802,28 +2803,30 @@ - (void) switchActiveUserTo:(UserDto *)user isNewAccount:(BOOL)isNewAccount {

// Cancel downloads of the previous user
[self portedCancelAllDownloads];

[UtilsCookies saveActiveUserCookiesAndRestoreCookiesOfUser:user];

// update active state of users in DB
[ManageUsersDB setAllUsersNoActive];
[ManageUsersDB setActiveAccountByUserId:user.userId];
user.activeaccount = YES;

[UtilsCookies saveActiveUserCookiesAndRestoreCookiesOfUser:user];


//Change the active user in appDelegate global variable
self.activeUser = user;


//We check the connection here because we need to accept the certificate on the self signed server before go to the files tab
[[CheckAccessToServer sharedManager] isConnectionToTheServerByUrl:[UtilsUrls getFullRemoteServerPath:user]];

[CheckFeaturesSupported updateServerFeaturesAndCapabilitiesOfActiveUser];

[UtilsCookies eraseURLCache];

//we create the user folder to haver multiuser

//we create the user folder to have multiuser
[UtilsFileSystem createFolderForUser:user];

self.isNewUser = YES;

ManageAccounts *manageAccounts = [ManageAccounts new];
[manageAccounts updateDisplayNameOfUserWithUser:user];

}
}

Expand Down
2 changes: 1 addition & 1 deletion Owncloud iOs Client/DataBase/Queries/ManageFilesDB.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ + (NSMutableArray *) getFilesByFileIdForActiveUser:(NSInteger) fileId {
#endif
__block NSMutableArray *output = [NSMutableArray new];

DLog(@"getFilesByFileId: %ld for active user",(long)fileId);
DLog(@"getFilesByFileId: %ld for active user %ld, %@",(long)fileId, mUser.userId, mUser.username);

FMDatabaseQueue *queue = Managers.sharedDatabase;

Expand Down
2 changes: 1 addition & 1 deletion Owncloud iOs Client/Login/Keychain/OCKeychain.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ +(NSDictionary *)getKeychainDictionaryOfUserId:(NSString *)userId {

OSStatus stsExist = SecItemCopyMatching((__bridge CFDictionaryRef)keychainItem, (CFTypeRef *)&result);

DLog(@"(getCredentials)Error Code %d (0 = success)", (int)stsExist);
DLog(@"(getCredentials of userId %@)Error Code %d (0 = success)", userId, (int)stsExist);

if (stsExist != errSecSuccess) {
NSLog(@"Unable to get the item with userId=%@ ",userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ public enum TextfieldType: String {
return;
}

UtilsCookies.updateOfActiveUserInDB()
self.detectUserDataAndValidate(credentials: userCredDto, serverPath: serverPath!)

}
Expand Down
1 change: 1 addition & 0 deletions Owncloud iOs Client/Network/UserData/DetectUserData.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ + (void) getUserDisplayNameOfServer:(NSString*)path credentials:(OCCredentialsDt
withCompletion:(void(^)(NSString *serverUserID, NSString *displayName, NSError *error))completion {

[[AppDelegate sharedOCCommunication] setCredentials:credentials];
DLog(@"credDto: %@",credentials.userName);

[[AppDelegate sharedOCCommunication] setValueOfUserAgent:[UtilsUrls getUserAgent]];

Expand Down
2 changes: 1 addition & 1 deletion Owncloud iOs Client/Tabs/FileTab/FilesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1855,7 +1855,7 @@ - (void) updateCurrentFileToShowIfNeeded {
FileDto *rootFileDtoOfActiveUser = [ManageFilesDB getRootFileDtoByUser:app.activeUser];
if (self.fileIdToShowFiles.userId != rootFileDtoOfActiveUser.userId) {
_fileIdToShowFiles = rootFileDtoOfActiveUser;
DLog(@"Changing between accounts, update _fileIdToShowFiles with root file of active user");
DLog(@"Changing between accounts, update _fileIdToShowFiles with root file of active user %ld, %@", (long)app.activeUser.userId, app.activeUser.username);
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions Owncloud iOs Client/Tabs/SettingTab/SettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1100,9 +1100,6 @@ - (void) didPressOnAccountIndexPath:(NSIndexPath*)indexPath {
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
UserDto *selectedUser = (UserDto *)[self.listUsers objectAtIndex:indexPath.row];

//We check the connection here because we need to accept the certificate on the self signed server before go to the files tab
[[CheckAccessToServer sharedManager] isConnectionToTheServerByUrl:[UtilsUrls getFullRemoteServerPath:selectedUser]];

//Method to change the account
[[OCLoadingSpinner sharedOCLoadingSpinner] initLoadingForViewController: self];
[app switchActiveUserTo:selectedUser isNewAccount:NO];
Expand Down
2 changes: 2 additions & 0 deletions Owncloud iOs Client/Utils/UtilsCookies.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

+ (void) eraseURLCache;

+ (void) updateCookiesOfActiveUserInDB;

+ (void) saveCurrentOfActiveUserAndClean;

+ (void) restoreCookiesOfUser:(UserDto *)user;
Expand Down
27 changes: 17 additions & 10 deletions Owncloud iOs Client/Utils/UtilsCookies.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,29 @@ + (void) eraseURLCache
[[NSURLCache sharedURLCache] setDiskCapacity:0];
}

+ (void) updateCookiesOfActiveUserInDB {
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate];

if (app.activeUser != nil) {
DLog(@"_updateCookiesOfActiveUserInDB_");

//1- Try to Delete the cookies of the active user
[ManageCookiesStorageDB deleteCookiesByUser:app.activeUser];

//2- Store the current cookies on the Database
[UtilsCookies setOnDBStorageCookiesByUser:app.activeUser];
}
}


+ (void) saveCurrentOfActiveUserAndClean {
DLog(@"_saveAndCleanCookies_");

AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate];

//Clear the cookies before to try to do login

//1- Try to Delete the cookies of the active user
[ManageCookiesStorageDB deleteCookiesByUser:app.activeUser];

//2- Store the current cookies on the Database
if (app.activeUser != nil) {
[UtilsCookies setOnDBStorageCookiesByUser:app.activeUser];
}
//3- Clean the cookies storage
[self updateCookiesOfActiveUserInDB];

//Clean the cookies storage
[UtilsFramework deleteAllCookies];
}

Expand Down