Soft logout: Support soft logout

#2540
This commit is contained in:
manuroe 2019-07-19 14:25:45 +02:00
parent 3abd4bbd00
commit 07505b08dc
6 changed files with 96 additions and 2 deletions

View file

@ -1,3 +1,10 @@
Changes in 0.9.2 (2019-07-)
===============================================
Improvements:
* Upgrade MatrixKit version ([v0.10.2](https://github.com/matrix-org/matrix-ios-kit/releases/tag/v0.10.2)).
* Soft logout: Support soft logout (#2540).
Changes in 0.9.1 (2019-07-17)
===============================================

View file

@ -2781,6 +2781,16 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN
[self logoutWithConfirmation:NO completion:nil];
}
}];
// Add observer to handle soft logout
[[NSNotificationCenter defaultCenter] addObserverForName:kMXKAccountManagerDidSoftlogoutAccountNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
MXKAccount *account = notif.object;
[self removeMatrixSession:account.mxSession];
// Return to authentication screen
[self.masterTabBarController showAuthenticationScreenAfterSoftLogout:account.mxCredentials];
}];
[[NSNotificationCenter defaultCenter] addObserverForName:kMXSessionIgnoredUsersDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull notif) {

View file

@ -395,6 +395,16 @@
}
}
- (void)setSoftLogoutCredentials:(MXCredentials *)softLogoutCredentials
{
[super setSoftLogoutCredentials:softLogoutCredentials];
// Customise the screen for soft logout
// TODO
self.customServersTickButton.hidden = YES;
}
- (void)handleAuthenticationSession:(MXAuthenticationSession *)authSession
{
[super handleAuthenticationSession:authSession];

View file

@ -54,6 +54,7 @@
@end
@implementation AuthInputsView
@synthesize softLogoutCredentials;
+ (UINib *)nib
{
@ -487,6 +488,15 @@
}
}
}
// For soft logout, pass the device_id currently used
if (parameters && self.softLogoutCredentials)
{
NSMutableDictionary *parametersWithDeviceId = [parameters mutableCopy];
parametersWithDeviceId[@"device_id"] = self.softLogoutCredentials.deviceId;
parameters = parametersWithDeviceId;
}
}
else if (type == MXKAuthenticationTypeRegister)
{
@ -725,7 +735,12 @@
{
// Note: this use case was not tested yet.
parameters = @{
@"auth": @{@"session":currentSession.session, @"username": self.userLoginTextField.text, @"password": self.passWordTextField.text, @"type": kMXLoginFlowTypePassword}
@"auth": @{
@"session":currentSession.session,
@"username": self.userLoginTextField.text,
@"password": self.passWordTextField.text,
@"type": kMXLoginFlowTypePassword
}
};
}
else if ([self isFlowSupported:kMXLoginFlowTypeTerms] && ![self isFlowCompleted:kMXLoginFlowTypeTerms])
@ -936,6 +951,12 @@
return YES;
}
- (void)setSoftLogoutCredentials:(MXCredentials *)credentials
{
softLogoutCredentials = credentials;
self.userLoginTextField.text = softLogoutCredentials.userId;
}
- (BOOL)areAllRequiredFieldsSet
{
// Keep enable the submit button.

View file

@ -63,6 +63,13 @@
*/
- (void)showAuthenticationScreenWithRegistrationParameters:(NSDictionary*)parameters;
/**
Display the authentication screen in order to login back a soft logout session.
@param softLogoutCredentials the credentials of the soft logout session.
*/
- (void)showAuthenticationScreenAfterSoftLogout:(MXCredentials*)softLogoutCredentials;
/**
Open the room with the provided identifier in a specific matrix session.

View file

@ -42,6 +42,7 @@
// The parameters to pass to the Authentification view controller.
NSDictionary *authViewControllerRegistrationParameters;
MXCredentials *softLogoutCredentials;
// The recents data source shared between all the view controllers of the tab bar.
RecentsDataSource *recentsDataSource;
@ -142,11 +143,25 @@
[super viewDidAppear:animated];
// Check whether we're not logged in
BOOL authIsShown = NO;
if (![MXKAccountManager sharedManager].accounts.count)
{
[self showAuthenticationScreen];
authIsShown = YES;
}
else
else if (![MXKAccountManager sharedManager].activeAccounts.count)
{
// Display a login screen if the account is soft logout
// Note: We support only one account
MXKAccount *account = [MXKAccountManager sharedManager].accounts.firstObject;
if (account.isSoftLogout)
{
[self showAuthenticationScreenAfterSoftLogout:account.mxCredentials];
authIsShown = YES;
}
}
if (!authIsShown)
{
// Check whether the user has been already prompted to send crash reports.
// (Check whether 'enableCrashReport' flag has been set once)
@ -401,6 +416,25 @@
}
}
- (void)showAuthenticationScreenAfterSoftLogout:(MXCredentials*)credentials;
{
NSLog(@"[MasterTabBarController] showAuthenticationScreenAfterSoftLogout");
softLogoutCredentials = credentials;
// Check whether an authentication screen is not already shown or preparing
if (!self.authViewController && !isAuthViewControllerPreparing)
{
isAuthViewControllerPreparing = YES;
[[AppDelegate theDelegate] restoreInitialDisplay:^{
[self performSegueWithIdentifier:@"showAuth" sender:self];
}];
}
}
- (void)selectRoomWithId:(NSString*)roomId andEventId:(NSString*)eventId inMatrixSession:(MXSession*)matrixSession
{
[self selectRoomWithId:roomId andEventId:eventId inMatrixSession:matrixSession completion:nil];
@ -637,6 +671,11 @@
_authViewController.externalRegistrationParameters = authViewControllerRegistrationParameters;
authViewControllerRegistrationParameters = nil;
}
if (softLogoutCredentials)
{
_authViewController.softLogoutCredentials = softLogoutCredentials;
softLogoutCredentials = nil;
}
}
else if ([[segue identifier] isEqualToString:@"showUnifiedSearch"])
{